Skip to content

Commit

Permalink
Add API key authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
tfranzese-woolpert committed Jan 16, 2025
1 parent 3f1fb5c commit 3cd5b25
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ The latest version of this provider can be installed with the Koop CLI. See the
To suppress KoopJS warnings from the console output, run with an environment variable of KOOP_WARNINGS="suppress". In powershell, this will look like: $env:KOOP_WARNINGS="suppress" ; node main.js

## Elastic Search Connect Environment Variable
Setting an environment variable of `KOOP_ENV_KEYS` allows saving of usernames and passwords to connect to elastic search
Setting an environment variable of `KOOP_ENV_KEYS` allows saving of secrets to connect to elastic search
without having to store them in the configuration file. The format for this variable is
`esId,user,password||esId2,user2,password2`. The _esId_ is the id given to the connection in the configuration file as
shown below in the *Basic Config File Structure* section.
`esId,user,password,apiKey||esId2,user2,password2||esId3,,,apiKey3`. The _esId_ is the id given to the connection in the configuration file as
shown below in the *Basic Config File Structure* section. The _apiKey_ should be base64 encoded.

## Command Line
`npm start`
Expand Down
12 changes: 9 additions & 3 deletions src/utils/elasticConnectUtil.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ function initializeESClients() {
if(envConfig[esId]){
connectInfo.userName = envConfig[esId].user;
connectInfo.password = envConfig[esId].password;
connectInfo.apiKey = envConfig[esId].apiKey;
}

let esClient = new Client({
node: hosts,
auth: {
username: connectInfo.userName,
password: connectInfo.password
password: connectInfo.password,
apiKey: connectInfo.apiKey
},
requestTimeout: 900000,
keepAlive: false,
Expand All @@ -61,10 +63,14 @@ function checkForEnvironmentVariables(){
if(koopEnvKeys){
koopEnvKeys.forEach(envConf => {
let envInfo = envConf.split(',');
koopEnvConfig[envInfo[0]] = {user: envInfo[1], password: envInfo[2]};
koopEnvConfig[envInfo[0]] = {
user: envInfo[1],
password: envInfo[2],
apiKey: envInfo[3]
};
});
}
// console.dir(koopEnvConfig);// esId,user,password||esId,user,password
// console.dir(koopEnvConfig);// esId,user,password,apiKey||esId,user,password,apiKey
return koopEnvConfig;
} catch (e) {
console.error(e);
Expand Down

0 comments on commit 3cd5b25

Please sign in to comment.