mysterio v2.1.0
Mysterio 
A dead simple module to take a configuration file by environment, retrieve secrets from AWS secret manager and merge them.
Install
> npm install --save mysterioUsage
- Go to AWS secret manager and create secret with the following naming convention:
<app name>/<environment>Ex:
log-collector/prod- Create a config folder that will contain the app configuration. Should be file per environment:
config/local.json
{
"port": 3000,
"db": "secret!"
}- Create a new instance and merged the configuration
const { name } = require('package.json')
const { Mysterio } = require('mysterio')
async function init () {
const mysterio = new Mysterio()
try {
const secrets = await mysterio.getMerged()
} catch (e) {
console.log('Error getting secrets ', e)
}
}- You can also use Mysterio helper to just get secrets
const { name } = require('package.json')
const { getSecretsClient } = require('mysterio')
async function init () {
const getSecrets = getSecretsClient({})
try {
const secrets = await getSecrets('my-secret-name')
} catch (e) {
console.log('Error getting secrets ', e)
}
}API
new Mysterio([, options])
awsParams(Object) - AWS SecretManager constructor params. Default:{ region: 'us-east-1' }configDirPath(String) - config folder path. Default:<current working dir>/configlocalRCPath(String) - local rc file path. Default:<current working dir>/.mysteriorcenv(String) - environment. Default:process.env.NODE_ENV || 'local'packageName(String) - name of your appsecretName(String) - name of your secret. Default:${packageName}/${env}
Mysterio.getDefaultConfigs()
Get default configuration from configDirPath by env. If you have default.json file it will marge it with <env>.json file.
Mysterio.getSecrets()
Get secrets from AWS SecretManager. Secret id will be secretName.
Mysterio.getLocalRC()
Get configuration from localRCPath. This file will load last. It is usually used as a helper while developing services with this module. You can add it to your .gitignore file to make sure it will stay only on yor computer.
Mysterio.getMerged([, options])
Get a merged secret object with your AWS SecretManager secret and your local config files.
isAddEnvProp- add an env prop to the merged secrets inis<Env> = truepattern. Default:falseisGetLocal- pull secrets from AWS SecretManager onlocalenv as well. Default:trueisGetTest- pull secrets from AWS SecretManager ontestenv as well. Default:false
getSecretsClient([, options])
Get secrets from AWS SecretManager by secret name. This method will return an async function that accepts a secret name and returns the secrets object.
awsParams(Object) - AWS SecretManager constructor params. Default:{ region: 'us-east-1' }