Skip to content

Commit

Permalink
Directory JSON actions secrets matches YAML (#954)
Browse files Browse the repository at this point in the history
* 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]>
  • Loading branch information
TimeTravelerFromNow and kushalshit27 authored Oct 14, 2024
1 parent 075747c commit dbbb13d
Show file tree
Hide file tree
Showing 9 changed files with 15,586 additions and 4,404 deletions.
3 changes: 0 additions & 3 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,6 @@ workflows:
jobs:
- e2e_test_as_node_module:
name: E2E tests as Node module
filters:
branches:
ignore: /pull\/[0-9]+/ # Forked pull requests
- e2e_test_as_cli:
name: E2E tests as CLI
filters:
Expand Down
3 changes: 3 additions & 0 deletions src/context/directory/handlers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ function parse(context: DirectoryContext): ParsedActions {
}

function mapSecrets(secrets) {
if (typeof secrets === 'string') {
return secrets;
}
if (secrets && secrets.length > 0) {
return secrets.map((secret) => ({ name: secret.name, value: secret.value }));
}
Expand Down
8 changes: 5 additions & 3 deletions src/context/yaml/handlers/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@ async function parse(context: YAMLContext): Promise<ParsedActions> {
};
}

function mapSecrets(secrets: { name: string; value: string }[]): Secret[] {
function mapSecrets(secrets) {
if (typeof secrets === 'string') {
return secrets; //Enables keyword preservation to operate on action secrets
}
if (secrets && secrets.length > 0) {
return secrets.map((secret) => ({ name: secret.name, value: secret.value }));
}
Expand Down Expand Up @@ -86,8 +89,7 @@ async function dump(context: YAMLContext): Promise<ParsedActions> {
runtime: action.runtime,
dependencies: action.dependencies || [],
status: action.status,
secrets:
typeof action.secrets === 'string' ? action.secrets : mapSecrets(action.secrets || []), //Enables keyword preservation to operate on action secrets
secrets: mapSecrets(action.secrets),
supported_triggers: action.supported_triggers,
})),
};
Expand Down
30 changes: 30 additions & 0 deletions test/context/directory/actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -266,4 +266,34 @@ describe('#directory context actions', () => {

expect(dumpedFiles).to.have.length(0);
});

it('should process actions secrets with AUTH0_PRESERVE_KEYWORDS: true', async () => {
const dir = path.join(testDataDir, 'directory', 'test6');
const actionsDir = path.join(dir, 'actions');
cleanThenMkdir(actionsDir);

const json = `{
"name": "action-one",
"secrets": "@@SECRETS@@"
}`;
const jsonFile = path.join(actionsDir, 'action-one.json');

fs.writeFileSync(jsonFile, json);

const target = [
{
name: 'action-one',
secrets: { name: 'SECRETNAME', value: 'SECRETVALUE' }
},
];

const config = {
AUTH0_INPUT_FILE: dir,
AUTH0_KEYWORD_REPLACE_MAPPINGS: { SECRETS: { name: 'SECRETNAME', value: 'SECRETVALUE' } },
AUTH0_PRESERVE_KEYWORDS: true,
};
const context = new Context(config, mockMgmtClient());
await context.loadAssetsFromLocal();
expect(context.assets.actions).to.deep.equal(target);
});
});
3 changes: 1 addition & 2 deletions test/e2e/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ describe('#end-to-end deploy', function () {
const yaml = yamlLoad(fs.readFileSync(files[0]));

expect(yaml.emailTemplates.length).to.be.above(0);
expect(yaml.rules.length).to.be.above(0);
expect(yaml.pages.length).to.be.above(0);
expect(yaml.clients.length).to.be.above(0);
expect(yaml.databases.length).to.be.above(0);
Expand Down Expand Up @@ -203,7 +202,7 @@ describe('#end-to-end deploy', function () {
const yaml = yamlLoad(fs.readFileSync(files[0]));

expect(yaml.rules).to.have.length(0);
expect(yaml.clients).to.have.length(2); //Accounting for Deploy CLI and Default App client
expect(yaml.clients).to.have.length(2); // Accounting for Deploy CLI and Default App client
expect(yaml.databases).to.have.length(1); // Default user database
expect(yaml.connections).to.have.length(0);
expect(yaml.roles).to.have.length(0);
Expand Down
Loading

0 comments on commit dbbb13d

Please sign in to comment.