0.0.3 • Published 3 years ago

enconsec v0.0.3

Weekly downloads
-
License
Apache-2.0
Repository
-
Last release
3 years ago

Enconsec JavaScript Style Guide

A dead simple module to take a configuration file by environment, retrieve secrets from AWS secret manager and merge them.

Install

> npm install --save enconsec

Usage

  1. Go to AWS secret manager and create secret with the following naming convention:
<app name>/<environment>

Ex:

log-collector/prod
  1. Create a config folder that will contain the app configuration. Should be file per environment:

config/local.json

{
  "port": 3000,
  "db": "secret!"
}
  1. 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>/config
  • localRCPath (String) - local rc file path. Default: <current working dir>/.enconsecrc
  • env (String) - environment. Default: process.env.NODE_ENV || 'local'
  • packageName (String) - name of your app
  • secretName (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 in is<Env> = true pattern. Default: false
  • isGetLocal - pull secrets from AWS SecretManager on local env as well. Default: true