From a503aa9543f40b1d6f5d9dcbaf5a02114e47fc20 Mon Sep 17 00:00:00 2001 From: recursivefunk Date: Tue, 10 Jun 2025 10:44:54 -0400 Subject: [PATCH 1/2] store secrets in process.env --- README.md | 2 ++ package.json | 2 +- src/index.js | 4 +++- test/test.js | 4 ++++ 4 files changed, 10 insertions(+), 2 deletions(-) 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..98c9042 100644 --- a/src/index.js +++ b/src/index.js @@ -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(); }); From 6781b98e9a5684cf6cf30df20b4ffde5c94300a5 Mon Sep 17 00:00:00 2001 From: recursivefunk Date: Tue, 10 Jun 2025 10:46:32 -0400 Subject: [PATCH 2/2] appease linter --- src/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/index.js b/src/index.js index 98c9042..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({