Last active
February 6, 2020 17:06
-
-
Save crrobinson14/bfbd224689f999fa4d2d427ecd4b2cc4 to your computer and use it in GitHub Desktop.
ActionHero Secrets-Loading Boot Routine
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { loadSecrets } = require('./src/lib/secrets'); | |
exports.default = async function BOOT() { | |
await loadSecrets('path/to/my/secret'); | |
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const { secrets } = require('../lib/secrets'); | |
// secrets is a singleton, a constant object that will be filled by the boot sequence with the secret value. | |
// So if your secret contained { DB_PASS: 'xyz' } you could access this as secrets.DB_PASS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const AWS = require('aws-sdk'); | |
const secretsmanager = new AWS.SecretsManager({ region: 'us-east-1' }); | |
const secrets = {}; | |
async function loadSecrets(SecretId) { | |
const value = await secretsmanager.getSecretValue({ SecretId }).promise(); | |
Object.assign(secrets, JSON.parse(value.SecretString)); | |
} | |
module.exports = { | |
secrets, | |
loadSecrets, | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment