Skip to content

Commit

Permalink
Error out if environment variables are not set
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonStoltz committed Jan 29, 2025
1 parent b2e52ac commit a338983
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/eui-usage-analytics/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ There is not a lot of magic to this script, it does 2 key things:
This script requires the following to run:

1. The [kibana](https://github.com/elastic/kibana) directory must be cloned to the same directory as the eui repository.
2. `CLOUD_ID` and `AUTH_APIKEY` of the Elatic Cloud instance for which you would like to ship the data.
2. `CLOUD_ID_SECRET` and `AUTH_APIKEY_SECRET` of the Elatic Cloud instance for which you would like to ship the data.

## Usage
****
This script must be run from this directory.

```
CLOUD_ID=****** AUTH_APIKEY=****** node index.js
CLOUD_ID_SECRET=****** AUTH_APIKEY_SECRET=****** node index.js
```

## Schema
Expand Down
19 changes: 15 additions & 4 deletions packages/eui-usage-analytics/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,29 @@
const { scan } = require('./scan');

const { Client } = require('@elastic/elasticsearch');

if (!process.env.CLOUD_ID_SECRET || process.env.AUTH_APIKEY_SECRET) {
console.error(
'CLOUD_ID_SECRET and AUTH_APIKEY_SECRET environment variables must be set before running this script.'
);
process.exit(1);
}

const client = new Client({
cloud: {
id: process.env.CLOUD_ID
id: process.env.CLOUD_ID_SECRET,
},
auth: {
apiKey: process.env.AUTH_APIKEY
}
apiKey: process.env.AUTH_APIKEY_SECRET,
},
});

const run = async () => {
const result = await scan();
const operations = result.flatMap(doc => [{ index: { _index: 'eui_components' } }, doc]);
const operations = result.flatMap((doc) => [
{ index: { _index: 'eui_components' } },
doc,
]);
const response = await client.bulk({ refresh: true, operations });
console.log(response);
};
Expand Down

0 comments on commit a338983

Please sign in to comment.