Skip to content

Commit 315e6e3

Browse files
committed
feat: use meta file environmentOptions when looking up environment for encryption subcommands
1 parent 155908a commit 315e6e3

File tree

1 file changed

+23
-36
lines changed

1 file changed

+23
-36
lines changed

app-config-cli/src/index.ts

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ import {
4848
import { loadSchema, JSONSchema } from '@app-config/schema';
4949
import { generateTypeFiles } from '@app-config/generate';
5050
import { validateAllConfigVariants } from './validation';
51+
import { loadMetaConfigLazy } from '@app-config/meta';
5152

5253
enum OptionGroups {
5354
Options = 'Options:',
@@ -318,6 +319,21 @@ function fileTypeForFormatOption(option: string): FileType {
318319
}
319320
}
320321

322+
async function loadEnvironmentOptions(opts: {
323+
environmentOverride?: string;
324+
environmentVariableName?: string;
325+
}) {
326+
const {
327+
value: { environmentAliases, environmentSourceNames },
328+
} = await loadMetaConfigLazy();
329+
330+
return asEnvOptions(
331+
opts.environmentOverride,
332+
environmentAliases,
333+
opts.environmentVariableName ?? environmentSourceNames,
334+
);
335+
}
336+
321337
export const cli = yargs
322338
.scriptName('app-config')
323339
.wrap(Math.max(yargs.terminalWidth() - 5, 80))
@@ -583,11 +599,7 @@ export const cli = yargs
583599
},
584600
},
585601
async (opts) => {
586-
const environmentOptions = asEnvOptions(
587-
opts.environmentOverride,
588-
undefined,
589-
opts.environmentVariableName,
590-
);
602+
const environmentOptions = await loadEnvironmentOptions(opts);
591603

592604
const myKey = await loadPublicKeyLazy();
593605
const privateKey = await loadPrivateKeyLazy();
@@ -615,11 +627,7 @@ export const cli = yargs
615627
},
616628
},
617629
async (opts) => {
618-
const environmentOptions = asEnvOptions(
619-
opts.environmentOverride,
620-
undefined,
621-
opts.environmentVariableName,
622-
);
630+
const environmentOptions = await loadEnvironmentOptions(opts);
623631

624632
const keys = await loadSymmetricKeys(undefined, environmentOptions);
625633
const teamMembers = await loadTeamMembersLazy(environmentOptions);
@@ -701,11 +709,7 @@ export const cli = yargs
701709
},
702710
},
703711
async (opts) => {
704-
const environmentOptions = asEnvOptions(
705-
opts.environmentOverride,
706-
undefined,
707-
opts.environmentVariableName,
708-
);
712+
const environmentOptions = await loadEnvironmentOptions(opts);
709713

710714
logger.info('Creating a new trusted CI encryption key');
711715

@@ -754,11 +758,7 @@ export const cli = yargs
754758
},
755759
},
756760
async (opts) => {
757-
const environmentOptions = asEnvOptions(
758-
opts.environmentOverride,
759-
undefined,
760-
opts.environmentVariableName,
761-
);
761+
const environmentOptions = await loadEnvironmentOptions(opts);
762762

763763
const key = await loadKey(await readFile(opts.keyPath));
764764
const privateKey = await loadPrivateKeyLazy();
@@ -792,12 +792,7 @@ export const cli = yargs
792792
},
793793
},
794794
async (opts) => {
795-
const environmentOptions = asEnvOptions(
796-
opts.environmentOverride,
797-
undefined,
798-
opts.environmentVariableName,
799-
);
800-
795+
const environmentOptions = await loadEnvironmentOptions(opts);
801796
const privateKey = await loadPrivateKeyLazy();
802797

803798
// TODO: by default, untrust for all envs?
@@ -828,11 +823,7 @@ export const cli = yargs
828823
},
829824
},
830825
async (opts) => {
831-
const environmentOptions = asEnvOptions(
832-
opts.environmentOverride,
833-
undefined,
834-
opts.environmentVariableName,
835-
);
826+
const environmentOptions = await loadEnvironmentOptions(opts);
836827

837828
shouldUseSecretAgent(opts.agent);
838829

@@ -900,11 +891,7 @@ export const cli = yargs
900891
},
901892
},
902893
async (opts) => {
903-
const environmentOptions = asEnvOptions(
904-
opts.environmentOverride,
905-
undefined,
906-
opts.environmentVariableName,
907-
);
894+
const environmentOptions = await loadEnvironmentOptions(opts);
908895

909896
shouldUseSecretAgent(opts.agent);
910897

0 commit comments

Comments
 (0)