forked from say8425/aws-secrets-manager-actions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
31 lines (26 loc) · 915 Bytes
/
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
const core = require('@actions/core')
const aws = require('aws-sdk')
const secretName = core.getInput('SECRET_NAME')
const secretsManager = new aws.SecretsManager({
accessKeyId: core.getInput('AWS_ACCESS_KEY_ID'),
secretAccessKey: core.getInput('AWS_SECRET_ACCESS_KEY'),
region: core.getInput('AWS_DEFAULT_REGION')
})
async function getSecretValue (secretsManager, secretName) {
return secretsManager.getSecretValue({ SecretId: secretName }).promise()
}
getSecretValue(secretsManager, secretName).then(resp => {
core.setSecret(resp.SecretString)
const secret = resp.SecretString
if (secret) {
const parsedSecret = JSON.parse(secret)
Object.entries(parsedSecret).forEach(([key, value]) => {
core.exportVariable(key, value)
})
} else {
core.warning(`${secretName} has no secret values`)
}
}).catch(err => {
core.setFailed(err)
})
exports.getSecretValue = getSecretValue