File tree Expand file tree Collapse file tree 1 file changed +22
-2
lines changed
app-config-encryption/src Expand file tree Collapse file tree 1 file changed +22
-2
lines changed Original file line number Diff line number Diff line change 1- import type { ParsingExtension } from '@app-config/core' ;
1+ import { AppConfigError , ParsingExtension } from '@app-config/core' ;
22import { named } from '@app-config/extension-utils' ;
33import { logger } from '@app-config/logging' ;
44import { environmentOptionsFromContext } from '@app-config/node' ;
@@ -22,8 +22,28 @@ export default function encryptedDirective(
2222 ) ;
2323 }
2424
25+ // we override the environment with what's specified in the key revision
26+ // so you can use the same key for multiple environments
27+
28+ const revision = value . split ( ':' ) [ 1 ] ;
29+
30+ if ( ! revision ) {
31+ throw new AppConfigError ( `Could not find key revision in encrypted value` ) ;
32+ }
33+
34+ const envRegex = / ^ (?: (?< env > \w * ) - ) ? (?: \d + ) $ / ;
35+ const env = envRegex . exec ( revision ) ?. groups ?. env ;
2536 const environmentOptions = environmentOptionsFromContext ( ctx ) ;
26- const decrypted = await decryptValue ( value , symmetricKey , environmentOptions ) ;
37+
38+ if ( env && environmentOptions ) {
39+ environmentOptions . override = env ;
40+ }
41+
42+ const decrypted = await decryptValue (
43+ value ,
44+ symmetricKey ,
45+ env ? environmentOptions : undefined ,
46+ ) ;
2747
2848 return parse ( decrypted , { fromSecrets : true , parsedFromEncryptedValue : true } ) ;
2949 } ;
You can’t perform that action at this time.
0 commit comments