Skip to content

Commit

Permalink
PLATFORM-3053 Get scanii secrets from AWS SM
Browse files Browse the repository at this point in the history
  • Loading branch information
michizubi-SRF committed Sep 21, 2023
1 parent 0e32912 commit e0581ce
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,19 @@ if (process.env.AWS_SAM_LOCAL !== undefined) {
console.log(process.env);
}

const headers = {"X-Aws-Parameters-Secrets-Token": process.env.AWS_SESSION_TOKEN}
const scaniiAPISecrets = process.env.SCANII_API_SECRETS_NAME;

async function getScaniiAPISecrets () {
let response = await fetch(`http://localhost:2773/secretsmanager/get?secretId=${scaniiAPISecrets}`, {
method: 'GET',
headers: headers
});
let data = await response.json();

return data.SecretString;
}

function defaults() {
CONFIG.KEY = null;
CONFIG.SECRET = null;
Expand All @@ -15,13 +28,17 @@ function defaults() {
CONFIG.MAX_ATTEMPTS = 10;
CONFIG.MAX_ATTEMPT_DELAY_MSEC = 30_000;

const SCANII_API_SECRETS = getScaniiAPISecrets();
CONFIG.KEY = SCANII_API_SECRETS['API_KEY'];
CONFIG.SECRET = SCANII_API_SECRETS['API_SECRET'];

// extracting config overwrites from the environment:
if (process.env.API_KEY) {
CONFIG.KEY = process.env.API_KEY;
}
if (process.env.API_SECRET) {
CONFIG.SECRET = process.env.API_SECRET;
}
// if (process.env.API_KEY) {
// CONFIG.KEY = process.env.API_KEY;
// }
// if (process.env.API_SECRET) {
// CONFIG.SECRET = process.env.API_SECRET;
// }

if (process.env.API_ENDPOINT) {
CONFIG.API_ENDPOINT = process.env.API_ENDPOINT;
Expand Down

0 comments on commit e0581ce

Please sign in to comment.