-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathindex.js
67 lines (61 loc) · 1.96 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
const core = require('@actions/core');
const ssm = require('./ssm-helper');
async function run_action()
{
try
{
const ssmPath = core.getInput('ssm-path', { required: true });
const getChildren = core.getInput('get-children') === 'true';
const prefix = core.getInput('prefix');
const region = process.env.AWS_DEFAULT_REGION;
const decryption = core.getInput('decryption') === 'true';
const maskValues = core.getInput('mask-values') === 'true';
const params = await ssm.getParameters(ssmPath, getChildren, decryption, region);
for (let param of params)
{
const parsedValue = parseValue(param.Value);
if (typeof(parsedValue) === 'object') // Assume JSON object
{
core.debug(`parsedValue: ${JSON.stringify(parsedValue)}`);
// Assume basic JSON structure
for (var key in parsedValue)
{
setEnvironmentVar(prefix + key, parsedValue[key], maskValues);
}
}
else
{
core.debug(`parsedValue: ${parsedValue}`);
// Set environment variable with ssmPath name as the env variable
var split = param.Name.split('/');
var envVarName = prefix + split[split.length - 1];
core.debug(`Using prefix + end of ssmPath for env var name: ${envVarName}`);
setEnvironmentVar(envVarName, parsedValue, maskValues);
}
}
}
catch (e)
{
core.setFailed(e.message);
}
}
function parseValue(val)
{
try
{
return JSON.parse(val);
}
catch
{
core.debug('JSON parse failed - assuming parameter is to be taken as a string literal');
return val;
}
}
function setEnvironmentVar(key, value, maskValue)
{
if (maskValue) {
core.setSecret(value);
}
core.exportVariable(key, value);
}
run_action();