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' ;
2
2
import { named } from '@app-config/extension-utils' ;
3
3
import { logger } from '@app-config/logging' ;
4
4
import { environmentOptionsFromContext } from '@app-config/node' ;
@@ -22,8 +22,28 @@ export default function encryptedDirective(
22
22
) ;
23
23
}
24
24
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 ;
25
36
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
+ ) ;
27
47
28
48
return parse ( decrypted , { fromSecrets : true , parsedFromEncryptedValue : true } ) ;
29
49
} ;
You can’t perform that action at this time.
0 commit comments