@@ -58,7 +58,7 @@ function _parseVault (options) {
5858
5959 // handle scenario for comma separated keys - for use with key rotation
6060 // example: DOTENV_KEY="dotenv://:[email protected] /vault/.env.vault?environment=prod,dotenv://:[email protected] /vault/.env.vault?environment=prod" 61- const keys = _dotenvKey ( ) . split ( ',' )
61+ const keys = _dotenvKey ( options ) . split ( ',' )
6262 const length = keys . length
6363
6464 let decrypted
@@ -99,11 +99,18 @@ function _debug (message) {
9999 console . log ( `[dotenv@${ version } ][DEBUG] ${ message } ` )
100100}
101101
102- function _dotenvKey ( ) {
102+ function _dotenvKey ( options ) {
103+ // prioritize developer directly setting options.DOTENV_KEY
104+ if ( options && options . DOTENV_KEY && options . DOTENV_KEY . length > 0 ) {
105+ return options . DOTENV_KEY
106+ }
107+
108+ // secondary infra already contains a DOTENV_KEY environment variable
103109 if ( process . env . DOTENV_KEY && process . env . DOTENV_KEY . length > 0 ) {
104110 return process . env . DOTENV_KEY
105111 }
106112
113+ // fallback to empty string
107114 return ''
108115}
109116
@@ -212,7 +219,7 @@ function config (options) {
212219 const vaultPath = _vaultPath ( options )
213220
214221 // fallback to original dotenv if DOTENV_KEY is not set
215- if ( _dotenvKey ( ) . length === 0 ) {
222+ if ( _dotenvKey ( options ) . length === 0 ) {
216223 return DotenvModule . configDotenv ( options )
217224 }
218225
0 commit comments