-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
43 lines (38 loc) · 1.58 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
const core = require("@actions/core");
const AWS = require("aws-sdk");
// // Uncomment me to use local credentials:
// const credentials = new AWS.SharedIniFileCredentials();
// AWS.config.credentials = credentials;
(async () => {
try {
const ssm = new AWS.SSM();
if (!ssm.config.credentials) {
throw new Error(
"No credentials. Try adding @aws-actions/configure-aws-credentials earlier in your job to set up AWS credentials.",
);
}
const prefix = core.getInput("prefix");
const Path = core.getInput("path", { required: true });
const WithDecryption = core.getInput("decrypt") === "true";
const Recursive = core.getInput("recursive") === "true";
const Parameters = [];
let NextToken;
do {
const result = await ssm.getParametersByPath({ Path, WithDecryption, Recursive, NextToken }).promise();
NextToken = result.NextToken;
Parameters.push(...result.Parameters);
} while (NextToken);
Parameters.forEach(({ Name, Value, Type }) => {
const variable = prefix + Name.toUpperCase().replace(/^\//, "").replace(/\//g, "_");
// If we are decrypting SecureStrings, make sure the decrypted value isn't getting printed in the logs
// (see https://docs.github.com/en/actions/reference/workflow-commands-for-github-actions#masking-a-value-in-log)
if (WithDecryption && Type === "SecureString") {
core.setSecret(Value);
}
core.exportVariable(variable, Value);
core.info(`Exported variable ${variable} (${Value})`);
});
} catch (error) {
core.setFailed(error.message);
}
})();