Skip to content

Commit

Permalink
Merge pull request #1 from mmz-srf/PLATFORM-3053-use-SM-for-secrets
Browse files Browse the repository at this point in the history
Platform 3053 use sm for secrets
  • Loading branch information
michizubi-SRF authored Sep 22, 2023
2 parents 0e32912 + 92f0915 commit 643d87e
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions lib/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,24 @@ if (process.env.AWS_SAM_LOCAL !== undefined) {
console.log(process.env);
}

function getScaniiAPISecrets() {
const headers = {"X-Aws-Parameters-Secrets-Token": process.env.AWS_SESSION_TOKEN}
const scaniiAPISecrets = process.env.SCANII_API_SECRETS_NAME;
return fetch(`http://localhost:2773/secretsmanager/get?secretId=${scaniiAPISecrets}`, {
method: 'GET',
headers: headers,
})
.then(function (response) {
if (!response.ok) {
throw new Error('API request failed with status: ' + response.status);
}
return response.json();
})
.then(function (data) {
return data.SecretString;
})
}

function defaults() {
CONFIG.KEY = null;
CONFIG.SECRET = null;
Expand All @@ -16,13 +34,6 @@ function defaults() {
CONFIG.MAX_ATTEMPT_DELAY_MSEC = 30_000;

// 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_ENDPOINT) {
CONFIG.API_ENDPOINT = process.env.API_ENDPOINT;
}
Expand Down Expand Up @@ -50,5 +61,13 @@ function defaults() {
}

defaults();

var secrets = getScaniiAPISecrets()
.then(function (secretString) {
secrets = JSON.parse(secretString)
CONFIG.KEY = secrets['API_KEY'];
CONFIG.SECRET = secrets['API_SECRET'];
});

exports.defaults = defaults;
exports.CONFIG = CONFIG;

0 comments on commit 643d87e

Please sign in to comment.