diff --git a/README.md b/README.md index b749488..9dfb5d3 100644 --- a/README.md +++ b/README.md @@ -168,6 +168,8 @@ const credentials = env.getAWS({ region: 'us-west-2' }); Some folks like to store secrets in AWS secrets manager in the form of a JSON object as opposed (or in addition) to environment variables. It's me, I'm some folks. Good Env now supports this pattern. To avoid introducing a dependency you'll have to bring your own instance of AWS Secrets Manager though. Be sure to specify your AWS region as an environment variable, otherwise, it'll default to `us-east-1`. +Not only will your secrets be merged with the Good Env store, but they will also be stored in the underlying `process.env` object in case there are components that are still pulling from the environment directly. + Note, if something goes wrong, this function _will_ throw an error. ```javascript diff --git a/package.json b/package.json index 26023df..6dbd00a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "good-env", - "version": "7.6.0", + "version": "7.6.1", "description": "Better environment variable handling for Twelve-Factor node apps", "main": "src/index.js", "scripts": { diff --git a/src/index.js b/src/index.js index 7127e86..011cec7 100644 --- a/src/index.js +++ b/src/index.js @@ -13,7 +13,7 @@ const isFunction = x => is(x) === '[object Function]'; const parse = (items, converter) => items.map(t => converter(t, 10)); const mapNums = items => parse(items, parseInt); const validType = item => ['number', 'boolean', 'string'].includes(item); -let store = { ...process.env }; +const store = { ...process.env }; module.exports = Object .create({ @@ -43,7 +43,9 @@ module.exports = Object ); const secretStr = response.SecretString; const secret = JSON.parse(secretStr); - store = { ...store, ...secret }; + Object.entries(secret).forEach(([key, value]) => { + this.set(key, value); + }); }, /** * @description Fetches an IP address from the environment. If the value found under the specified key is not a valid IPv4 diff --git a/test/test.js b/test/test.js index 9aff442..35ea77a 100644 --- a/test/test.js +++ b/test/test.js @@ -40,6 +40,10 @@ test('it uses secrets manager (happy path)', async (t) => { t.equals(secretVal1, 'val1'); t.equals(secretVal2, 'val2'); + // Ensure it updates the environment variables + t.equals(process.env.secretVal1, 'val1'); + t.equals(process.env.secretVal2, 'val2'); + t.end(); });