@@ -16,7 +16,7 @@ import {
16
16
FailedToSelectSubObject ,
17
17
EmptyStdinOrPromptResponse ,
18
18
} from '@app-config/core' ;
19
- import { promptUser , consumeStdin } from '@app-config/node' ;
19
+ import { promptUser , consumeStdin , asEnvOptions } from '@app-config/node' ;
20
20
import { checkTTY , LogLevel , logger } from '@app-config/logging' ;
21
21
import {
22
22
LoadedConfiguration ,
@@ -577,13 +577,23 @@ export const cli = yargs
577
577
'Creates properties in meta file, making you the first trusted user' ,
578
578
] ,
579
579
] ,
580
+ options : {
581
+ environmentOverride : environmentOverrideOption ,
582
+ environmentVariableName : environmentVariableNameOption ,
583
+ } ,
580
584
} ,
581
- async ( ) => {
585
+ async ( opts ) => {
586
+ const environmentOptions = asEnvOptions (
587
+ opts . environmentOverride ,
588
+ undefined ,
589
+ opts . environmentVariableName ,
590
+ ) ;
591
+
582
592
const myKey = await loadPublicKeyLazy ( ) ;
583
593
const privateKey = await loadPrivateKeyLazy ( ) ;
584
594
585
595
// we trust ourselves, essentially
586
- await trustTeamMember ( myKey , privateKey ) ;
596
+ await trustTeamMember ( myKey , privateKey , environmentOptions ) ;
587
597
logger . info ( 'Initialized team members and a symmetric key' ) ;
588
598
} ,
589
599
) ,
@@ -599,10 +609,20 @@ export const cli = yargs
599
609
'Sets up a new symmetric key with the latest revision number' ,
600
610
] ,
601
611
] ,
612
+ options : {
613
+ environmentOverride : environmentOverrideOption ,
614
+ environmentVariableName : environmentVariableNameOption ,
615
+ } ,
602
616
} ,
603
- async ( ) => {
604
- const keys = await loadSymmetricKeys ( ) ;
605
- const teamMembers = await loadTeamMembersLazy ( ) ;
617
+ async ( opts ) => {
618
+ const environmentOptions = asEnvOptions (
619
+ opts . environmentOverride ,
620
+ undefined ,
621
+ opts . environmentVariableName ,
622
+ ) ;
623
+
624
+ const keys = await loadSymmetricKeys ( undefined , environmentOptions ) ;
625
+ const teamMembers = await loadTeamMembersLazy ( environmentOptions ) ;
606
626
607
627
let revision : number ;
608
628
@@ -612,7 +632,12 @@ export const cli = yargs
612
632
revision = 1 ;
613
633
}
614
634
615
- await saveNewSymmetricKey ( await generateSymmetricKey ( revision ) , teamMembers ) ;
635
+ await saveNewSymmetricKey (
636
+ await generateSymmetricKey ( revision ) ,
637
+ teamMembers ,
638
+ environmentOptions ,
639
+ ) ;
640
+
616
641
logger . info ( `Saved a new symmetric key, revision ${ revision } ` ) ;
617
642
} ,
618
643
) ,
@@ -670,12 +695,27 @@ export const cli = yargs
670
695
name : 'ci' ,
671
696
description :
672
697
'Creates an encryption key that can be used without a passphrase (useful for CI)' ,
698
+ options : {
699
+ environmentOverride : environmentOverrideOption ,
700
+ environmentVariableName : environmentVariableNameOption ,
701
+ } ,
673
702
} ,
674
- async ( ) => {
703
+ async ( opts ) => {
704
+ const environmentOptions = asEnvOptions (
705
+ opts . environmentOverride ,
706
+ undefined ,
707
+ opts . environmentVariableName ,
708
+ ) ;
709
+
675
710
logger . info ( 'Creating a new trusted CI encryption key' ) ;
676
711
677
712
const { privateKeyArmored, publicKeyArmored } = await initializeKeys ( false ) ;
678
- await trustTeamMember ( await loadKey ( publicKeyArmored ) , await loadPrivateKeyLazy ( ) ) ;
713
+
714
+ await trustTeamMember (
715
+ await loadKey ( publicKeyArmored ) ,
716
+ await loadPrivateKeyLazy ( ) ,
717
+ environmentOptions ,
718
+ ) ;
679
719
680
720
process . stdout . write ( `\n${ publicKeyArmored } \n\n${ privateKeyArmored } \n\n` ) ;
681
721
@@ -708,11 +748,21 @@ export const cli = yargs
708
748
description : 'Filepath of public key' ,
709
749
} ,
710
750
} ,
751
+ options : {
752
+ environmentOverride : environmentOverrideOption ,
753
+ environmentVariableName : environmentVariableNameOption ,
754
+ } ,
711
755
} ,
712
756
async ( opts ) => {
757
+ const environmentOptions = asEnvOptions (
758
+ opts . environmentOverride ,
759
+ undefined ,
760
+ opts . environmentVariableName ,
761
+ ) ;
762
+
713
763
const key = await loadKey ( await readFile ( opts . keyPath ) ) ;
714
764
const privateKey = await loadPrivateKeyLazy ( ) ;
715
- await trustTeamMember ( key , privateKey ) ;
765
+ await trustTeamMember ( key , privateKey , environmentOptions ) ;
716
766
717
767
logger . info ( `Trusted ${ key . getUserIds ( ) . join ( ', ' ) } ` ) ;
718
768
} ,
@@ -736,10 +786,22 @@ export const cli = yargs
736
786
description : 'User ID email address' ,
737
787
} ,
738
788
} ,
789
+ options : {
790
+ environmentOverride : environmentOverrideOption ,
791
+ environmentVariableName : environmentVariableNameOption ,
792
+ } ,
739
793
} ,
740
794
async ( opts ) => {
795
+ const environmentOptions = asEnvOptions (
796
+ opts . environmentOverride ,
797
+ undefined ,
798
+ opts . environmentVariableName ,
799
+ ) ;
800
+
741
801
const privateKey = await loadPrivateKeyLazy ( ) ;
742
- await untrustTeamMember ( opts . email , privateKey ) ;
802
+
803
+ // TODO: by default, untrust for all envs?
804
+ await untrustTeamMember ( opts . email , privateKey , environmentOptions ) ;
743
805
} ,
744
806
) ,
745
807
)
@@ -761,9 +823,17 @@ export const cli = yargs
761
823
options : {
762
824
clipboard : clipboardOption ,
763
825
agent : secretAgentOption ,
826
+ environmentOverride : environmentOverrideOption ,
827
+ environmentVariableName : environmentVariableNameOption ,
764
828
} ,
765
829
} ,
766
830
async ( opts ) => {
831
+ const environmentOptions = asEnvOptions (
832
+ opts . environmentOverride ,
833
+ undefined ,
834
+ opts . environmentVariableName ,
835
+ ) ;
836
+
767
837
shouldUseSecretAgent ( opts . agent ) ;
768
838
769
839
// load these right away, so user unlocks asap
@@ -797,7 +867,7 @@ export const cli = yargs
797
867
}
798
868
}
799
869
800
- const encrypted = await encryptValue ( secretValue ) ;
870
+ const encrypted = await encryptValue ( secretValue , undefined , environmentOptions ) ;
801
871
802
872
if ( opts . clipboard ) {
803
873
await clipboardy . write ( encrypted ) ;
@@ -825,9 +895,17 @@ export const cli = yargs
825
895
options : {
826
896
clipboard : clipboardOption ,
827
897
agent : secretAgentOption ,
898
+ environmentOverride : environmentOverrideOption ,
899
+ environmentVariableName : environmentVariableNameOption ,
828
900
} ,
829
901
} ,
830
902
async ( opts ) => {
903
+ const environmentOptions = asEnvOptions (
904
+ opts . environmentOverride ,
905
+ undefined ,
906
+ opts . environmentVariableName ,
907
+ ) ;
908
+
831
909
shouldUseSecretAgent ( opts . agent ) ;
832
910
833
911
// load these right away, so user unlocks asap
@@ -855,7 +933,9 @@ export const cli = yargs
855
933
throw new EmptyStdinOrPromptResponse ( 'Failed to read from stdin or prompt' ) ;
856
934
}
857
935
858
- process . stdout . write ( JSON . stringify ( await decryptValue ( encryptedText ) ) ) ;
936
+ const decrypted = await decryptValue ( encryptedText , undefined , environmentOptions ) ;
937
+
938
+ process . stdout . write ( JSON . stringify ( decrypted ) ) ;
859
939
process . stdout . write ( '\n' ) ;
860
940
} ,
861
941
) ,
0 commit comments