2.0.0 • Published 2 years ago
@financial-times/vaultenv v2.0.0
vaultenv 
Load vars from Vault straight into process.env
- Get started with Vault
npm i -D @financial-times/vaultenv
FYI: use vaultenv for dev and ip-vault-sync for prod
Two ways of skinning a cat
1. Sync
Sync requires all configuration to be in the environment before the call to Vault is made.
Put this in your "dev script" in your package.json
VAULT_PATH=secret/teams/<your team>/<your thing>/<environment> node --require @financial-times/vaultenvIf you want to physically see your env vars printing out
- add
DEBUG=*at the beginning and -pe 'console.log()'at the end of your "dev script"
Required variables
VAULT_ADDR- the address of the vault instanceVAULT_AUTH_GITHUB_TOKEN- your github personal tokenVAULT_PATH- the full path to the secrets in vault (e.g.secret/teams/ateam/murdoch/production)- Without
VAULT_PATH, the path is made up ofnpm_package_team,npm_package_nameand the environment is derived fromCIandNODE_ENV- When
CIis true, the env will becontinuous-integration - When
NODE_ENVis set, then its value will be used, otherwise it'sdevelopment
- When
- Without
The vars below are for appRole auth and can be used instead of GitHub auth
VAULT_AUTH_ROLE_ID- a role id for approle authenticationVAULT_AUTH_SECRET_ID- a secret id for approle authentication
Optional variables
VAULT_OVERRIDE_EXISTING- can be set in the environment or within the secrets in vault- When
VAULT_OVERRIDE_EXISTINGis true, vault will override the existing environment variables - When
VAULT_OVERRIDE_EXISTINGis false (default), vault will not override the existing environment variables
- When
2. Async
This can be used during start up or while an app is running
const vault = require('@financial-times/vaultenv/async');
const start = async () => {
const vars = await vault('https://vault.instance', 'github token', '/path/to/secrets');
console.log(`env loaded: ${vars}`);
};
start();Development
vaultenv is an npm package, which is published whenever a tagged commit is created.
The easiest way to do this is to create a PR, make your changes and once approved:
- Merge the PR to the main branch.
- Draft a new release in GitHub.
- Click choose a tag then create a new tag, for example:
v1.0.3
- Give your release a title and description of the changes.
- Click publish release.
This will automatically trigger a publish in CircleCI, which will use the version of your release as the package version in NPM.