@@ -156,7 +156,7 @@ export async function loadPrivateKey(
156
156
if ( override ) {
157
157
overrideKey = override ;
158
158
} else {
159
- overrideKey = getKeyFromEnv ( 'private' , environmentOptions ) ;
159
+ overrideKey = await getKeyFromEnv ( 'private' , environmentOptions ) ;
160
160
}
161
161
162
162
if ( overrideKey ) {
@@ -200,7 +200,7 @@ export async function loadPublicKey(
200
200
if ( override ) {
201
201
overrideKey = override ;
202
202
} else {
203
- overrideKey = getKeyFromEnv ( 'public' , environmentOptions ) ;
203
+ overrideKey = await getKeyFromEnv ( 'public' , environmentOptions ) ;
204
204
}
205
205
206
206
if ( overrideKey ) {
@@ -219,7 +219,7 @@ export async function loadPublicKey(
219
219
return key ;
220
220
}
221
221
222
- function getKeyFromEnv ( keyType : 'private' | 'public' , envOptions ?: EnvironmentOptions ) {
222
+ async function getKeyFromEnv ( keyType : 'private' | 'public' , envOptions ?: EnvironmentOptions ) {
223
223
const env = currentEnvironment ( envOptions ) ;
224
224
225
225
const envVarPrefix =
@@ -231,24 +231,55 @@ function getKeyFromEnv(keyType: 'private' | 'public', envOptions?: EnvironmentOp
231
231
232
232
let key = process . env [ `${ envVarPrefix } _${ env . toUpperCase ( ) } ` ] ;
233
233
234
- // try an alias if we didn't find the key first try
235
- if ( ! key ) {
234
+ const tryAliases = ( envVarName : ( alias : string ) => string ) => {
236
235
const aliases = aliasesFor ( env , envOptions . aliases ) ;
237
236
238
237
for ( const alias of aliases ) {
239
- key = process . env [ ` ${ envVarPrefix } _ ${ alias . toUpperCase ( ) } ` ] ;
238
+ const val = process . env [ envVarName ( alias . toUpperCase ( ) ) ] ;
240
239
241
- if ( key ) {
242
- break ;
240
+ if ( val ) {
241
+ return val ;
243
242
}
244
243
}
244
+ } ;
245
+
246
+ // try an alias if we didn't find the key first try
247
+ if ( ! key ) {
248
+ key = tryAliases ( ( alias ) => `${ envVarPrefix } _${ alias } ` ) ;
249
+ }
250
+
251
+ // see if a file was specified for the environment
252
+ if ( ! key ) {
253
+ const file = process . env [ `${ envVarPrefix } _${ env . toUpperCase ( ) } _FILE` ] ;
254
+
255
+ if ( file ) {
256
+ key = ( await fs . readFile ( file ) ) . toString ( ) ;
257
+ }
258
+ }
259
+
260
+ // try an env alias if we don't have the key from a file
261
+ if ( ! key ) {
262
+ const file = tryAliases ( ( alias ) => `${ envVarPrefix } _${ alias } _FILE` ) ;
263
+
264
+ if ( file ) {
265
+ key = ( await fs . readFile ( file ) ) . toString ( ) ;
266
+ }
245
267
}
246
268
247
269
// if we didn't find a key with an environment, fallback on one without if it exists
248
270
if ( ! key ) {
249
271
key = process . env [ envVarPrefix ] ;
250
272
}
251
273
274
+ // if a key still wasn't found try read from a file specified
275
+ if ( ! key ) {
276
+ const file = process . env [ `${ envVarPrefix } _FILE` ] ;
277
+
278
+ if ( file ) {
279
+ key = ( await fs . readFile ( file ) ) . toString ( ) ;
280
+ }
281
+ }
282
+
252
283
return key ;
253
284
}
254
285
0 commit comments