-
-
Notifications
You must be signed in to change notification settings - Fork 861
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #754 from motdotla/dotenv-key-option
Add failing test demonstrating need for DOTENV_KEY option
- Loading branch information
Showing
7 changed files
with
52 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -58,7 +58,7 @@ function _parseVault (options) { | |
|
||
// handle scenario for comma separated keys - for use with key rotation | ||
// example: DOTENV_KEY="dotenv://:[email protected]/vault/.env.vault?environment=prod,dotenv://:[email protected]/vault/.env.vault?environment=prod" | ||
const keys = _dotenvKey().split(',') | ||
const keys = _dotenvKey(options).split(',') | ||
const length = keys.length | ||
|
||
let decrypted | ||
|
@@ -99,11 +99,18 @@ function _debug (message) { | |
console.log(`[dotenv@${version}][DEBUG] ${message}`) | ||
} | ||
|
||
function _dotenvKey () { | ||
function _dotenvKey (options) { | ||
// prioritize developer directly setting options.DOTENV_KEY | ||
if (options && options.DOTENV_KEY && options.DOTENV_KEY.length > 0) { | ||
return options.DOTENV_KEY | ||
} | ||
|
||
// secondary infra already contains a DOTENV_KEY environment variable | ||
if (process.env.DOTENV_KEY && process.env.DOTENV_KEY.length > 0) { | ||
return process.env.DOTENV_KEY | ||
} | ||
|
||
// fallback to empty string | ||
return '' | ||
} | ||
|
||
|
@@ -212,7 +219,7 @@ function config (options) { | |
const vaultPath = _vaultPath(options) | ||
|
||
// fallback to original dotenv if DOTENV_KEY is not set | ||
if (_dotenvKey().length === 0) { | ||
if (_dotenvKey(options).length === 0) { | ||
return DotenvModule.configDotenv(options) | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ const e = process.env.DOTENV_CONFIG_ENCODING | |
const p = process.env.DOTENV_CONFIG_PATH | ||
const d = process.env.DOTENV_CONFIG_DEBUG | ||
const o = process.env.DOTENV_CONFIG_OVERRIDE | ||
const dk = process.env.DOTENV_CONFIG_DOTENV_KEY | ||
|
||
// get fresh object for each test | ||
function options () { | ||
|
@@ -30,6 +31,7 @@ delete process.env.DOTENV_CONFIG_ENCODING | |
delete process.env.DOTENV_CONFIG_PATH | ||
delete process.env.DOTENV_CONFIG_DEBUG | ||
delete process.env.DOTENV_CONFIG_OVERRIDE | ||
delete process.env.DOTENV_CONFIG_DOTENV_KEY | ||
|
||
t.same(options(), {}) | ||
|
||
|
@@ -45,8 +47,12 @@ testOption('DOTENV_CONFIG_DEBUG', 'true', { debug: 'true' }) | |
// sets override option | ||
testOption('DOTENV_CONFIG_OVERRIDE', 'true', { override: 'true' }) | ||
|
||
// sets DOTENV_KEY option | ||
testOption('DOTENV_CONFIG_DOTENV_KEY', 'dotenv://:[email protected]/vault/.env.vault?environment=development', { DOTENV_KEY: 'dotenv://:[email protected]/vault/.env.vault?environment=development' }) | ||
|
||
// restore existing env | ||
process.env.DOTENV_CONFIG_ENCODING = e | ||
process.env.DOTENV_CONFIG_PATH = p | ||
process.env.DOTENV_CONFIG_DEBUG = d | ||
process.env.DOTENV_CONFIG_OVERRIDE = o | ||
process.env.DOTENV_CONFIG_DOTENV_KEY = dk |