Skip to content

Instantly share code, notes, and snippets.

@crrobinson14
Last active February 6, 2020 17:06
Show Gist options
  • Save crrobinson14/bfbd224689f999fa4d2d427ecd4b2cc4 to your computer and use it in GitHub Desktop.
Save crrobinson14/bfbd224689f999fa4d2d427ecd4b2cc4 to your computer and use it in GitHub Desktop.
ActionHero Secrets-Loading Boot Routine
const { loadSecrets } = require('./src/lib/secrets');
exports.default = async function BOOT() {
await loadSecrets('path/to/my/secret');
};
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
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