-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathindex.js
48 lines (40 loc) · 1.08 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
46
47
48
const AWS = require("aws-sdk");
const argv = require("minimist")(process.argv.slice(2));
const {
secret,
region = "eu-west-1",
AWS_ACCESS_KEY_ID: accessKeyId,
AWS_SECRET_ACCESS_KEY: secretAccessKey,
} = argv;
const SecretId = secret;
const params = { region };
if (accessKeyId) Object.assign(params, { accessKeyId });
if (secretAccessKey) Object.assign(params, { secretAccessKey });
const client = new AWS.SecretsManager(params);
if (!secret) {
console.error("Missing SECRET_NAME or SECRET_ARN");
process.exit(1);
}
client.getSecretValue({ SecretId }, (err, data) => {
if (err) {
console.error(`${err.name}: ${err.message}`);
process.exit(1);
}
if ("SecretString" in data) {
try {
const secrets = JSON.parse(data.SecretString);
const keys = Object.keys(secrets);
keys.forEach(k => {
console.log(`${k}=${secrets[k]}`);
});
}
catch (e) {
console.error(data.SecretString);
}
}
// secret is a binary
else {
let buff = new Buffer(data.SecretBinary, "base64");
console.log(buff.toString("ascii"));
}
});