Skip to content

Commit ac2d077

Browse files
committed
fix: encryption environment adding and reading old key revisions
1 parent 4620708 commit ac2d077

File tree

3 files changed

+34
-9
lines changed

3 files changed

+34
-9
lines changed

app-config-cli/src/index.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import {
4444
shouldUseSecretAgent,
4545
startAgent,
4646
disconnectAgents,
47+
getRevisionNumber,
4748
} from '@app-config/encryption';
4849
import { loadSchema, JSONSchema } from '@app-config/schema';
4950
import { generateTypeFiles } from '@app-config/generate';
@@ -595,7 +596,6 @@ export const cli = yargs
595596
],
596597
options: {
597598
environmentOverride: environmentOverrideOption,
598-
environmentVariableName: environmentVariableNameOption,
599599
},
600600
},
601601
async (opts) => {
@@ -623,7 +623,6 @@ export const cli = yargs
623623
],
624624
options: {
625625
environmentOverride: environmentOverrideOption,
626-
environmentVariableName: environmentVariableNameOption,
627626
},
628627
},
629628
async (opts) => {
@@ -636,7 +635,14 @@ export const cli = yargs
636635
let revision: string;
637636

638637
if (keys.length > 0) {
639-
revision = latestSymmetricKeyRevision(keys);
638+
const latestRevison = latestSymmetricKeyRevision(keys);
639+
const revNumber = getRevisionNumber(latestRevison);
640+
641+
if (environment) {
642+
revision = `${environment}-${revNumber + 1}`;
643+
} else {
644+
revision = `${revNumber + 1}`;
645+
}
640646
} else if (environment) {
641647
revision = `${environment}-1`;
642648
} else {
@@ -708,7 +714,6 @@ export const cli = yargs
708714
'Creates an encryption key that can be used without a passphrase (useful for CI)',
709715
options: {
710716
environmentOverride: environmentOverrideOption,
711-
environmentVariableName: environmentVariableNameOption,
712717
},
713718
},
714719
async (opts) => {
@@ -757,7 +762,6 @@ export const cli = yargs
757762
},
758763
options: {
759764
environmentOverride: environmentOverrideOption,
760-
environmentVariableName: environmentVariableNameOption,
761765
},
762766
},
763767
async (opts) => {
@@ -791,7 +795,6 @@ export const cli = yargs
791795
},
792796
options: {
793797
environmentOverride: environmentOverrideOption,
794-
environmentVariableName: environmentVariableNameOption,
795798
},
796799
},
797800
async (opts) => {
@@ -822,7 +825,6 @@ export const cli = yargs
822825
clipboard: clipboardOption,
823826
agent: secretAgentOption,
824827
environmentOverride: environmentOverrideOption,
825-
environmentVariableName: environmentVariableNameOption,
826828
},
827829
},
828830
async (opts) => {
@@ -890,7 +892,6 @@ export const cli = yargs
890892
clipboard: clipboardOption,
891893
agent: secretAgentOption,
892894
environmentOverride: environmentOverrideOption,
893-
environmentVariableName: environmentVariableNameOption,
894895
},
895896
},
896897
async (opts) => {

app-config-meta/src/index.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,9 @@ export async function loadMetaConfig({
101101
const parsed = await source.read(defaultMetaExtensions());
102102
const value = parsed.toJSON() as MetaProperties;
103103

104+
// normalize all revisions to be strings even if they're numbers
105+
normalizeMetaEncryptionKeyRevisions(value);
106+
104107
const fileSources = parsed.sources.filter((s) => s instanceof FileSource) as FileSource[];
105108
const [{ filePath, fileType }] = fileSources.filter((s) => s.filePath.includes(fileNameBase));
106109

@@ -124,6 +127,26 @@ export async function loadMetaConfig({
124127
}
125128
}
126129

130+
function normalizeMetaEncryptionKeyRevisions(meta: MetaProperties): MetaProperties {
131+
const stringifyRevision = (keys: EncryptedSymmetricKey[]) => {
132+
for (const key of keys) {
133+
if (typeof key.revision !== 'string') {
134+
key.revision = (key.revision as number).toString();
135+
}
136+
}
137+
};
138+
139+
if (Array.isArray(meta.encryptionKeys)) {
140+
stringifyRevision(meta.encryptionKeys);
141+
} else if (meta.encryptionKeys) {
142+
for (const env of Object.keys(meta.encryptionKeys)) {
143+
stringifyRevision(meta.encryptionKeys[env]);
144+
}
145+
}
146+
147+
return meta;
148+
}
149+
127150
let metaConfig: Promise<MetaConfiguration> | undefined;
128151

129152
export async function loadMetaConfigLazy(options?: MetaLoadingOptions): Promise<MetaConfiguration> {

docs/guide/intro/encryption.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,4 +213,5 @@ encryptionKeys:
213213
- revision: 1
214214
key: '...'
215215
```
216-
To create a new encryption environment use the `init-key` CLI subcommand while setting one of the standard App-Config environment variables (`ENV`, `NODE_ENV`, or `APP_CONFIG_ENV`) with the new encryption environment.
216+
217+
To create a new encryption environment use the `init-repo` CLI subcommand while setting one of the standard App-Config environment variables (`ENV`, `NODE_ENV`, or `APP_CONFIG_ENV`) with the new encryption environment.

0 commit comments

Comments
 (0)