@@ -16,7 +16,7 @@ import {
1616 FailedToSelectSubObject ,
1717 EmptyStdinOrPromptResponse ,
1818} from '@app-config/core' ;
19- import { promptUser , consumeStdin } from '@app-config/node' ;
19+ import { promptUser , consumeStdin , asEnvOptions } from '@app-config/node' ;
2020import { checkTTY , LogLevel , logger } from '@app-config/logging' ;
2121import {
2222 LoadedConfiguration ,
@@ -577,13 +577,23 @@ export const cli = yargs
577577 'Creates properties in meta file, making you the first trusted user' ,
578578 ] ,
579579 ] ,
580+ options : {
581+ environmentOverride : environmentOverrideOption ,
582+ environmentVariableName : environmentVariableNameOption ,
583+ } ,
580584 } ,
581- async ( ) => {
585+ async ( opts ) => {
586+ const environmentOptions = asEnvOptions (
587+ opts . environmentOverride ,
588+ undefined ,
589+ opts . environmentVariableName ,
590+ ) ;
591+
582592 const myKey = await loadPublicKeyLazy ( ) ;
583593 const privateKey = await loadPrivateKeyLazy ( ) ;
584594
585595 // we trust ourselves, essentially
586- await trustTeamMember ( myKey , privateKey ) ;
596+ await trustTeamMember ( myKey , privateKey , environmentOptions ) ;
587597 logger . info ( 'Initialized team members and a symmetric key' ) ;
588598 } ,
589599 ) ,
@@ -599,10 +609,20 @@ export const cli = yargs
599609 'Sets up a new symmetric key with the latest revision number' ,
600610 ] ,
601611 ] ,
612+ options : {
613+ environmentOverride : environmentOverrideOption ,
614+ environmentVariableName : environmentVariableNameOption ,
615+ } ,
602616 } ,
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 ) ;
606626
607627 let revision : number ;
608628
@@ -612,7 +632,12 @@ export const cli = yargs
612632 revision = 1 ;
613633 }
614634
615- await saveNewSymmetricKey ( await generateSymmetricKey ( revision ) , teamMembers ) ;
635+ await saveNewSymmetricKey (
636+ await generateSymmetricKey ( revision ) ,
637+ teamMembers ,
638+ environmentOptions ,
639+ ) ;
640+
616641 logger . info ( `Saved a new symmetric key, revision ${ revision } ` ) ;
617642 } ,
618643 ) ,
@@ -670,12 +695,27 @@ export const cli = yargs
670695 name : 'ci' ,
671696 description :
672697 'Creates an encryption key that can be used without a passphrase (useful for CI)' ,
698+ options : {
699+ environmentOverride : environmentOverrideOption ,
700+ environmentVariableName : environmentVariableNameOption ,
701+ } ,
673702 } ,
674- async ( ) => {
703+ async ( opts ) => {
704+ const environmentOptions = asEnvOptions (
705+ opts . environmentOverride ,
706+ undefined ,
707+ opts . environmentVariableName ,
708+ ) ;
709+
675710 logger . info ( 'Creating a new trusted CI encryption key' ) ;
676711
677712 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+ ) ;
679719
680720 process . stdout . write ( `\n${ publicKeyArmored } \n\n${ privateKeyArmored } \n\n` ) ;
681721
@@ -708,11 +748,21 @@ export const cli = yargs
708748 description : 'Filepath of public key' ,
709749 } ,
710750 } ,
751+ options : {
752+ environmentOverride : environmentOverrideOption ,
753+ environmentVariableName : environmentVariableNameOption ,
754+ } ,
711755 } ,
712756 async ( opts ) => {
757+ const environmentOptions = asEnvOptions (
758+ opts . environmentOverride ,
759+ undefined ,
760+ opts . environmentVariableName ,
761+ ) ;
762+
713763 const key = await loadKey ( await readFile ( opts . keyPath ) ) ;
714764 const privateKey = await loadPrivateKeyLazy ( ) ;
715- await trustTeamMember ( key , privateKey ) ;
765+ await trustTeamMember ( key , privateKey , environmentOptions ) ;
716766
717767 logger . info ( `Trusted ${ key . getUserIds ( ) . join ( ', ' ) } ` ) ;
718768 } ,
@@ -736,10 +786,22 @@ export const cli = yargs
736786 description : 'User ID email address' ,
737787 } ,
738788 } ,
789+ options : {
790+ environmentOverride : environmentOverrideOption ,
791+ environmentVariableName : environmentVariableNameOption ,
792+ } ,
739793 } ,
740794 async ( opts ) => {
795+ const environmentOptions = asEnvOptions (
796+ opts . environmentOverride ,
797+ undefined ,
798+ opts . environmentVariableName ,
799+ ) ;
800+
741801 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 ) ;
743805 } ,
744806 ) ,
745807 )
@@ -761,9 +823,17 @@ export const cli = yargs
761823 options : {
762824 clipboard : clipboardOption ,
763825 agent : secretAgentOption ,
826+ environmentOverride : environmentOverrideOption ,
827+ environmentVariableName : environmentVariableNameOption ,
764828 } ,
765829 } ,
766830 async ( opts ) => {
831+ const environmentOptions = asEnvOptions (
832+ opts . environmentOverride ,
833+ undefined ,
834+ opts . environmentVariableName ,
835+ ) ;
836+
767837 shouldUseSecretAgent ( opts . agent ) ;
768838
769839 // load these right away, so user unlocks asap
@@ -797,7 +867,7 @@ export const cli = yargs
797867 }
798868 }
799869
800- const encrypted = await encryptValue ( secretValue ) ;
870+ const encrypted = await encryptValue ( secretValue , undefined , environmentOptions ) ;
801871
802872 if ( opts . clipboard ) {
803873 await clipboardy . write ( encrypted ) ;
@@ -825,9 +895,17 @@ export const cli = yargs
825895 options : {
826896 clipboard : clipboardOption ,
827897 agent : secretAgentOption ,
898+ environmentOverride : environmentOverrideOption ,
899+ environmentVariableName : environmentVariableNameOption ,
828900 } ,
829901 } ,
830902 async ( opts ) => {
903+ const environmentOptions = asEnvOptions (
904+ opts . environmentOverride ,
905+ undefined ,
906+ opts . environmentVariableName ,
907+ ) ;
908+
831909 shouldUseSecretAgent ( opts . agent ) ;
832910
833911 // load these right away, so user unlocks asap
@@ -855,7 +933,9 @@ export const cli = yargs
855933 throw new EmptyStdinOrPromptResponse ( 'Failed to read from stdin or prompt' ) ;
856934 }
857935
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 ) ) ;
859939 process . stdout . write ( '\n' ) ;
860940 } ,
861941 ) ,
0 commit comments