-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
45 lines (38 loc) · 1.1 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
"use strict";
const awsParamStore = require("aws-param-store");
const AWS = require("aws-sdk");
const AWSConfig = new AWS.Config();
// declare a global results object
var results = {};
function getBasePath(path) {
var a = path.split("/");
a.pop();
return a.join("/");
}
module.exports = function (rootPath) {
let output = {};
// for rootPaths that don't end in "/", add it
if (rootPath.length - 1 != "/") {
rootPath = rootPath + "/";
}
if (AWSConfig.credentials == null) {
console.log(
"WARNING: No AWS credentials, not connecting to SSM for secrets..."
);
} else if (!AWSConfig.region) {
console.log(
"WARNING: No AWS region configured, not connecting to SSM for secrets..."
);
} else if (process.env.AWS_SSM == "false") {
console.log(
"INFO: AWS_SSM is set to false, not connecting to SSM for secrets..."
);
} else {
let parameters = awsParamStore.getParametersByPathSync(rootPath);
parameters.forEach((element) => {
const name = element.Name.split(rootPath)[1];
output[name] = element.Value;
});
}
return output;
};