0.0.3 • Published 4 years ago
enconsec v0.0.3
Enconsec 
A dead simple module to take a configuration file by environment, retrieve secrets from AWS secret manager and merge them.
Install
> npm install --save enconsecUsage
- 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 Enconsec = require('Enconsec')
async function init () {
const enconsec = new Enconsec()
try {
let secrets = await enconsec.getMerged()
} catch (e) {
console.log('Error getting secrets ', e)
}
}API
new Enconsec([, 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>/.enconsecrcenv(String) - environment. Default:process.env.NODE_ENV || 'local'packageName(String) - name of your appsecretName(String) - name of your secret. Default:${packageName}/${env}
Enconsec.getDefaultConfigs()
Get default configuration from configDirPath by env. If you have default.json file it will marge it with <env>.json file.
Enconsec.getSecrets()
Get secrets from AWS SecretManager. Secret id will be secretName.
Enconsec.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.
Enconsec.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:true