From a338983d78a9345415daa4c3d6cb604c18744a2f Mon Sep 17 00:00:00 2001 From: Jason Stoltzfus Date: Wed, 29 Jan 2025 14:39:15 -0500 Subject: [PATCH] Error out if environment variables are not set --- packages/eui-usage-analytics/README.md | 4 ++-- packages/eui-usage-analytics/index.js | 19 +++++++++++++++---- 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/eui-usage-analytics/README.md b/packages/eui-usage-analytics/README.md index e0d985fd442..48c5fd4c55f 100644 --- a/packages/eui-usage-analytics/README.md +++ b/packages/eui-usage-analytics/README.md @@ -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 diff --git a/packages/eui-usage-analytics/index.js b/packages/eui-usage-analytics/index.js index b8250cf5318..2c332be25a4 100644 --- a/packages/eui-usage-analytics/index.js +++ b/packages/eui-usage-analytics/index.js @@ -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); };