Skip to content

Commit dbbb13d

Browse files
Directory JSON actions secrets matches YAML (#954)
* Directory JSON actions secrets matches YAML Signed-off-by: Sebastian Detering <[email protected]> * Unit test for actions secrets KEYWORD Signed-off-by: Sebastian Detering <[email protected]> * existing mapSecrets string placeholder return Signed-off-by: Sebastian Detering <[email protected]> * type check in YAML mapSecrets Signed-off-by: Sebastian Detering <[email protected]> Rebased to master * update e2e recordings --------- Signed-off-by: Sebastian Detering <[email protected]> Co-authored-by: kushalshit27 <[email protected]>
1 parent 075747c commit dbbb13d

9 files changed

+15586
-4404
lines changed

.circleci/config.yml

-3
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,6 @@ workflows:
8282
jobs:
8383
- e2e_test_as_node_module:
8484
name: E2E tests as Node module
85-
filters:
86-
branches:
87-
ignore: /pull\/[0-9]+/ # Forked pull requests
8885
- e2e_test_as_cli:
8986
name: E2E tests as CLI
9087
filters:

src/context/directory/handlers/actions.ts

+3
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ function parse(context: DirectoryContext): ParsedActions {
4343
}
4444

4545
function mapSecrets(secrets) {
46+
if (typeof secrets === 'string') {
47+
return secrets;
48+
}
4649
if (secrets && secrets.length > 0) {
4750
return secrets.map((secret) => ({ name: secret.name, value: secret.value }));
4851
}

src/context/yaml/handlers/actions.ts

+5-3
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,10 @@ async function parse(context: YAMLContext): Promise<ParsedActions> {
3636
};
3737
}
3838

39-
function mapSecrets(secrets: { name: string; value: string }[]): Secret[] {
39+
function mapSecrets(secrets) {
40+
if (typeof secrets === 'string') {
41+
return secrets; //Enables keyword preservation to operate on action secrets
42+
}
4043
if (secrets && secrets.length > 0) {
4144
return secrets.map((secret) => ({ name: secret.name, value: secret.value }));
4245
}
@@ -86,8 +89,7 @@ async function dump(context: YAMLContext): Promise<ParsedActions> {
8689
runtime: action.runtime,
8790
dependencies: action.dependencies || [],
8891
status: action.status,
89-
secrets:
90-
typeof action.secrets === 'string' ? action.secrets : mapSecrets(action.secrets || []), //Enables keyword preservation to operate on action secrets
92+
secrets: mapSecrets(action.secrets),
9193
supported_triggers: action.supported_triggers,
9294
})),
9395
};

test/context/directory/actions.test.js

+30
Original file line numberDiff line numberDiff line change
@@ -266,4 +266,34 @@ describe('#directory context actions', () => {
266266

267267
expect(dumpedFiles).to.have.length(0);
268268
});
269+
270+
it('should process actions secrets with AUTH0_PRESERVE_KEYWORDS: true', async () => {
271+
const dir = path.join(testDataDir, 'directory', 'test6');
272+
const actionsDir = path.join(dir, 'actions');
273+
cleanThenMkdir(actionsDir);
274+
275+
const json = `{
276+
"name": "action-one",
277+
"secrets": "@@SECRETS@@"
278+
}`;
279+
const jsonFile = path.join(actionsDir, 'action-one.json');
280+
281+
fs.writeFileSync(jsonFile, json);
282+
283+
const target = [
284+
{
285+
name: 'action-one',
286+
secrets: { name: 'SECRETNAME', value: 'SECRETVALUE' }
287+
},
288+
];
289+
290+
const config = {
291+
AUTH0_INPUT_FILE: dir,
292+
AUTH0_KEYWORD_REPLACE_MAPPINGS: { SECRETS: { name: 'SECRETNAME', value: 'SECRETVALUE' } },
293+
AUTH0_PRESERVE_KEYWORDS: true,
294+
};
295+
const context = new Context(config, mockMgmtClient());
296+
await context.loadAssetsFromLocal();
297+
expect(context.assets.actions).to.deep.equal(target);
298+
});
269299
});

test/e2e/e2e.test.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ describe('#end-to-end deploy', function () {
140140
const yaml = yamlLoad(fs.readFileSync(files[0]));
141141

142142
expect(yaml.emailTemplates.length).to.be.above(0);
143-
expect(yaml.rules.length).to.be.above(0);
144143
expect(yaml.pages.length).to.be.above(0);
145144
expect(yaml.clients.length).to.be.above(0);
146145
expect(yaml.databases.length).to.be.above(0);
@@ -203,7 +202,7 @@ describe('#end-to-end deploy', function () {
203202
const yaml = yamlLoad(fs.readFileSync(files[0]));
204203

205204
expect(yaml.rules).to.have.length(0);
206-
expect(yaml.clients).to.have.length(2); //Accounting for Deploy CLI and Default App client
205+
expect(yaml.clients).to.have.length(2); // Accounting for Deploy CLI and Default App client
207206
expect(yaml.databases).to.have.length(1); // Default user database
208207
expect(yaml.connections).to.have.length(0);
209208
expect(yaml.roles).to.have.length(0);

0 commit comments

Comments
 (0)