feat: Add config-manager pull iga-workflows command#102
Conversation
| const { CLOUD_DEPLOYMENT_TYPE_KEY, FORGEOPS_DEPLOYMENT_TYPE_KEY } = | ||
| frodo.utils.constants; | ||
| const deploymentTypes = [ | ||
| CLOUD_DEPLOYMENT_TYPE_KEY, | ||
| FORGEOPS_DEPLOYMENT_TYPE_KEY, | ||
| ]; |
There was a problem hiding this comment.
Forgeops is not a supported deployment for IGA, only Cloud, so remove Forgeops from this.
| if (options.realm) { | ||
| realm = options.realm; | ||
| } |
There was a problem hiding this comment.
Workflows are global configuration, not realm specific, so remove this
| if (await getTokens(false, true, deploymentTypes)) { | ||
| verboseMessage('Exporting config entity iga-workflows'); | ||
| const outcome = await configManagerExportIgaWorkflows( | ||
| options.name, | ||
| options.includeImmutable | ||
| ); | ||
| if (!outcome) process.exitCode = 1; | ||
| } | ||
| }); |
There was a problem hiding this comment.
Change this code to look something like this:
This is almost correct, although we need to make sure we are setting the exit code to 1 in the event that getTokens fails, which this example does.
| realm = options.realm; | ||
| } | ||
| if (await getTokens(false, true, deploymentTypes)) { | ||
| verboseMessage('Exporting config entity iga-workflows'); |
There was a problem hiding this comment.
I would reword this message to be "Exporting IGA workflows...", since config entity is typically associated with IDM entities.
| let workflows = await readWorkflows(); | ||
| if (name) { | ||
| workflows = workflows.filter((workflow) => workflow.name === name); | ||
| } | ||
| if (!includeImmutable) { | ||
| workflows = workflows.filter((workflow) => workflow.mutable); | ||
| } | ||
| workflows.forEach((workflow) => { | ||
| processIgaWorkflow(workflow, 'iga/workflows'); | ||
| }); |
There was a problem hiding this comment.
You can simplify this to be:
(await readWorkflows())
.filter(w => (!name || w.name === name) && (includeImmutable || !w.mutable))
.forEach(processIgaWorkflow);For processIgaWorkflow you will need to modify it to no longer receive the fileDir, which is fine since there's no reason to pass it in as a parameter since it's a constant.
| try { | ||
| const workflowName = safeFileName(workflow.name); | ||
| const workflowPath = `${fileDir}/${workflowName}`; | ||
| if (Array.isArray(workflow.steps)) { |
There was a problem hiding this comment.
This check isn't necessary (steps will always be an array, even if there are no steps in the workflow)
| stepBody && | ||
| typeof stepBody === 'object' && | ||
| typeof stepBody.script === 'string' && | ||
| stepBody.script.length > 0 |
There was a problem hiding this comment.
You can simplify stepBody.script.length > 0 to just stepBody.script, since strings are falsy if they are empty.
| const CMD = 'frodo config-manager pull iga-workflows --help'; | ||
| const { stdout } = await exec(CMD); | ||
|
|
||
| test("CLI help interface for 'config export' should be expected english", async () => { |
There was a problem hiding this comment.
'config export' should be config-manager pull iga-workflows
| /* | ||
| FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-trivir-fairfax.forgeblocks.com/am frodo config-manager pull iga-workflows -D igaTestDir01 | ||
| FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-trivir-fairfax.forgeblocks.com/am frodo config-manager pull iga-workflows -n test_workflow_4 -D igaTestDir02 | ||
| FRODO_MOCK=record FRODO_NO_CACHE=1 FRODO_HOST=https://openam-trivir-fairfax.forgeblocks.com/am frodo config-manager pull iga-workflows -i -D igaTestDir03 |
There was a problem hiding this comment.
Add another two tests
- With
-iand-ntogether and try to export a non-mutable workflow (it should work) - With only
-nlike in test 2 (you will need to use--nameto differentiate from that test), and try to export a non-mutable workflow. It should fail indicating that the workflow was not found (fr-config-manager's wording is specificallyWorkflow BasicApplicationGrant not found). For this test, I would use the helper that I created likeawait testFail(CMD, env);to test that the command fails.
| if (options.realm) { | ||
| realm = options.realm; | ||
| } | ||
| if (await getTokens(false, true, deploymentTypes)) { |
There was a problem hiding this comment.
Before getTokens, I would add an if-statement checking if the tenant is an IGA tenant, and fail early if not, as I did for the Frodo workflow commands:
frodo-cli/src/cli/iga/config/iga-config-export.ts
Lines 92 to 99 in ccab984
| return false; | ||
| } | ||
|
|
||
| async function processIgaWorkflow(workflow, fileDir) { |
There was a problem hiding this comment.
Add a function comment to this. I would also rename it to processIgaWorkflowForExport to help differentiate it since there is also a function for processing a workflow for import in your push PR.
No description provided.