Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { frodo } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { configManagerExportIgaWorkflows } from '../../../configManagerOps/FrConfigIgaWorkflowsOps';
import { getTokens } from '../../../ops/AuthenticateOps';
import { verboseMessage } from '../../../utils/Console';
import { FrodoCommand } from '../../FrodoCommand';

const { CLOUD_DEPLOYMENT_TYPE_KEY, FORGEOPS_DEPLOYMENT_TYPE_KEY } =
frodo.utils.constants;
const deploymentTypes = [
CLOUD_DEPLOYMENT_TYPE_KEY,
FORGEOPS_DEPLOYMENT_TYPE_KEY,
];

export default function setup() {
const program = new FrodoCommand(
'frodo config-manager pull iga-workflows',
[],
deploymentTypes
);
program
.description('Export iga-workflows.')
.addOption(
new Option(
'-n, --name <name>',
'Workflow name. Only export the workflow with this name.'
)
)
.addOption(
new Option('-i, --include-immutable ', 'Include immutable IGA workflows.')
)
.action(async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
if (options.realm) {
realm = options.realm;
}
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;
}
});
return program;
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import CustomNodes from './config-manager-pull-custom-nodes';
import EmailProvider from './config-manager-pull-email-provider';
import EmailTemplates from './config-manager-pull-email-templates';
import Endpoints from './config-manager-pull-endpoints';
import IgaWorkflows from './config-manager-pull-iga-workflows';
import InternalRoles from './config-manager-pull-internal-roles';
import Journeys from './config-manager-pull-journeys';
import Kba from './config-manager-pull-kba';
Expand Down Expand Up @@ -79,6 +80,7 @@ export default function setup() {
program.addCommand(Test().name('test'));
program.addCommand(UiConfig().name('ui-config'));
program.addCommand(Variables().name('variables'));
program.addCommand(IgaWorkflows().name('iga-workflows'));

return program;
}
2 changes: 2 additions & 0 deletions src/cli/config/config-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export default function setup() {
includeReadOnly: options.readOnly,
onlyRealm: options.realmOnly,
onlyGlobal: options.globalOnly,
includeNonCustom: false,
}
);
if (!outcome) process.exitCode = 1;
Expand Down Expand Up @@ -202,6 +203,7 @@ export default function setup() {
includeReadOnly: options.readOnly,
onlyRealm: options.realmOnly,
onlyGlobal: options.globalOnly,
includeNonCustom: false,
}
);
if (!outcome) process.exitCode = 1;
Expand Down
3 changes: 3 additions & 0 deletions src/cli/config/config-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export default function setup() {
includeDefault: options.default,
includeActiveValues: options.includeActiveValues,
source: options.source,
includeNonCustom: false,
});
if (!outcome) process.exitCode = 1;
}
Expand All @@ -152,6 +153,7 @@ export default function setup() {
includeDefault: options.default,
includeActiveValues: options.includeActiveValues,
source: options.source,
includeNonCustom: false,
});
if (!outcome) process.exitCode = 1;
}
Expand All @@ -169,6 +171,7 @@ export default function setup() {
includeDefault: options.default,
includeActiveValues: options.includeActiveValues,
source: options.source,
includeNonCustom: false,
}
);
if (!outcome) process.exitCode = 1;
Expand Down
70 changes: 70 additions & 0 deletions src/configManagerOps/FrConfigIgaWorkflowsOps.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { frodo } from '@rockcarver/frodo-lib';

import { extractFrConfigDataToFile } from '../utils/Config';
import { printError } from '../utils/Console';
import { safeFileName } from '../utils/FrConfig';

const { saveJsonToFile, getFilePath } = frodo.utils;
const { readWorkflows } = frodo.cloud.iga.workflow;

/**
* Export IGA workflows in fr-config-manager format.
* @param {string} name optional workflow name to filter by
* @param {boolean} includeImmutable if true, also export immutable workflows
* @returns {Promise<boolean>} a promise that resolves to true if successful, false otherwise
*/
export async function configManagerExportIgaWorkflows(
name?: string,
includeImmutable: boolean = false
): Promise<boolean> {
try {
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');
});
return true;
} catch (error) {
printError(error, 'Error exporting iga-workflows to files');
}
return false;
}

async function processIgaWorkflow(workflow, fileDir) {
try {
const workflowName = safeFileName(workflow.name);
const workflowPath = `${fileDir}/${workflowName}`;
if (Array.isArray(workflow.steps)) {
const stepsPath = `${workflowPath}/steps`;
workflow.steps.forEach((step) => {
const uniqueId = safeFileName(`${step.displayName} - ${step.name}`);
const stepPath = `${stepsPath}/${uniqueId}`;
const stepBody = step[step.type];
if (
stepBody &&
typeof stepBody === 'object' &&
typeof stepBody.script === 'string' &&
stepBody.script.length > 0
) {
const scriptFilename = `${uniqueId}.js`;
extractFrConfigDataToFile(stepBody.script, scriptFilename, stepPath);
stepBody.script = {
file: scriptFilename,
};
}
const stepFileName = `${stepPath}/${uniqueId}.json`;
saveJsonToFile(step, getFilePath(stepFileName, true), false, true);
});
delete workflow.steps;
}
const fileName = `${workflowPath}/${workflowName}.json`;
saveJsonToFile(workflow, getFilePath(fileName, true), false, true);
} catch (err) {
printError(err);
}
}
5 changes: 5 additions & 0 deletions src/ops/ConfigOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ export async function exportEverythingToFile(
includeReadOnly: false,
onlyRealm: false,
onlyGlobal: false,
includeNonCustom: false,
}
): Promise<boolean> {
try {
Expand Down Expand Up @@ -105,6 +106,7 @@ export async function exportEverythingToFiles(
includeReadOnly: false,
onlyRealm: false,
onlyGlobal: false,
includeNonCustom: false,
}
): Promise<boolean> {
try {
Expand Down Expand Up @@ -382,6 +384,7 @@ export async function importEverythingFromFile(
includeDefault: false,
includeActiveValues: false,
source: '',
includeNonCustom: false,
}
): Promise<boolean> {
try {
Expand All @@ -408,6 +411,7 @@ export async function importEverythingFromFiles(
includeDefault: false,
includeActiveValues: false,
source: '',
includeNonCustom: false,
}
): Promise<boolean> {
try {
Expand All @@ -431,6 +435,7 @@ export async function importEntityfromFile(
includeDefault: false,
includeActiveValues: false,
source: '',
includeNonCustom: false,
}
): Promise<boolean> {
try {
Expand Down
1 change: 1 addition & 0 deletions src/utils/Config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ export async function getFullExportConfig(
includeReadOnly: true,
onlyRealm: false,
onlyGlobal: false,
includeNonCustom: false,
},
errorHandler
);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CLI help interface for 'config export' should be expected english 1`] = `
"Usage: frodo config-manager pull iga-workflows [options] [host] [realm] [username] [password]

[Experimental] Export iga-workflows.

Arguments:
host AM base URL, e.g.: https://cdk.iam.example.com/am.
To use a connection profile, just specify a unique
substring or alias.
realm Realm. Specify realm as '/' for the root realm or
'realm' or '/parent/child' otherwise. (default:
"alpha" for Identity Cloud tenants, "/" otherwise.)
username Username to login with. Must be an admin user with
appropriate rights to manage authentication
journeys/trees.
password Password.

Options:
-i, --include-immutable Include immutable IGA workflows.
-n, --name <name> Workflow name. Only export the workflow with this
name.
-h, --help Help
-hh, --help-more Help with all options.
-hhh, --help-all Help with all options, environment variables, and
usage examples.
"
`;
10 changes: 10 additions & 0 deletions test/client_cli/en/config-manager-export-iga-workflows.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import cp from 'child_process';
import { promisify } from 'util';

const exec = promisify(cp.exec);
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 () => {
expect(stdout).toMatchSnapshot();
});
Loading