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
16 changes: 7 additions & 9 deletions src/cli/FrodoCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -388,15 +388,13 @@ function decorateDescriptionWithStability(
*/
function cloneOption(option: Option): Option {
const cloned = Object.assign(new Option(option.flags, option.description), {
defaultValue: option.defaultValue,
defaultValueDescription: option.defaultValueDescription,
presetArg: option.presetArg,
envVar: option.envVar,
parseArg: option.parseArg,
hidden: option.hidden,
mandatory: option.mandatory,
argChoices: option.argChoices ? [...option.argChoices] : option.argChoices,
helpGroupHeading: option.helpGroupHeading,
...option,
// @ts-expect-error: CommanderJS Typings needs an update for node_modules to recognize conflictsWith
conflictsWith: option.conflictsWith
? // @ts-expect-error: Linter will do this and ts-expect-error cant be multi line.
[...option.conflictsWith]
: // @ts-expect-error: Linter will do this and ts-expect-error cant be multi line.
option.conflictsWith,
});

setStabilityMetadata(cloned, getStabilityMetadata(option));
Expand Down
117 changes: 117 additions & 0 deletions src/cli/iga/glossary/iga-glossary-delete.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
import { frodo, state } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { getTokens } from '../../../ops/AuthenticateOps';
import {
deleteGlossarySchema,
deleteGlossarySchemas,
} from '../../../ops/cloud/iga/IgaGlossaryOps';
import { printMessage, verboseMessage } from '../../../utils/Console.js';
import { FrodoCommand } from '../../FrodoCommand';
import { GlossaryObjectType } from '@rockcarver/frodo-lib/types/api/cloud/iga/IgaGlossaryApi';
import { object } from 'zod';

const { CLOUD_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;

const deploymentTypes = [CLOUD_DEPLOYMENT_TYPE_KEY];

const glossaryTypeMap: Record<string, GlossaryObjectType> = {
role: '/openidm/managed/role',
entitlement: '/openidm/managed/assignment',
application: '/openidm/managed/application',
account: '/iga/governance/account',
};

export default function setup() {
const program = new FrodoCommand('frodo iga glossary delete');

program
.description('Delete glossaries.')
.addOption(
new Option(
'-i, --glossary-id <glossary-id>',
'glossary id. If specified, -n and -a cannot be used. '
).conflicts(['glossaryName', 'all'])
).addOption(
new Option(
'-n, --glossary-name <glossary-name>',
'Specify a glossary name. If specified, -i cannot be used.'
).conflicts(['glossaryId'])
)
.addOption(
new Option(
'-a, --all',
'Delete all glossaries. Cannot be used with -a and -i.'
).conflicts(['glossaryName', 'glossaryId'])
)
.addOption(
new Option(
'-t, --glossary-type <type>',
'Filter glossary schema by type: role, entitlement, application, or account'
)
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
if (!options.glossaryId && !options.glossaryName && !options.all) {
printMessage(
'Unrecognized combination of options or no options...',
'error'
);
process.exitCode = 1;
program.help();
}
const getTokensIsSuccessful = await getTokens(
false,
true,
deploymentTypes
);
if (!getTokensIsSuccessful) process.exit(1);
if (!state.getIsIGA()) {
printMessage(
'Command not supported for non-IGA cloud tenants',
'error'
);
process.exit(1);
}
const objectType = options.glossaryType
? glossaryTypeMap[options.glossaryType]
: null;

if (options.glossaryType && !objectType) {
printMessage('Please provide a valid Object Type', 'error');
process.exitCode = 1;
program.help();
}

// delete by id
if (options.glossaryId || options.glossaryName) {
verboseMessage('Deleting glossary...');
console.log("CLI: NAME", options.glossaryName)
const outcome = await deleteGlossarySchema(
options.glossaryId,
options.glossaryName,
objectType
);
if (!outcome) process.exitCode = 1;
}
// --all -a
else if (options.all) {
verboseMessage('Deleting all glossaries...');
const outcome = await deleteGlossarySchemas(objectType);
if (!outcome) process.exitCode = 1;
}
}
// end command logic inside action handler
);

return program;
}
95 changes: 95 additions & 0 deletions src/cli/iga/glossary/iga-glossary-describe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import { frodo, state } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { getTokens } from '../../../ops/AuthenticateOps';
import { describeGlossary } from '../../../ops/cloud/iga/IgaGlossaryOps';
import { printMessage, verboseMessage } from '../../../utils/Console';
import { FrodoCommand } from '../../FrodoCommand';
import { GlossaryObjectType } from '@rockcarver/frodo-lib/types/api/cloud/iga/IgaGlossaryApi';

const { CLOUD_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;

const deploymentTypes = [CLOUD_DEPLOYMENT_TYPE_KEY];

const glossaryTypeMap: Record<string, GlossaryObjectType> = {
role: '/openidm/managed/role',
entitlement: '/openidm/managed/assignment',
application: '/openidm/managed/application',
account: '/iga/governance/account',
};

export default function setup() {
const program = new FrodoCommand('frodo iga glossary describe');

program
.description('Describe glossaries.')
.addOption(
new Option(
'-i, --glossary-id <glossary-id>',
'glossary id. If not specified, will describe first glossary in the provided export file.'
).conflicts(['glossaryName'])
)
.addOption(
new Option(
'-n, --glossary-name <glossary-name>',
'Specify a glossary name. If specified, -i cannot be used.'
).conflicts(['glossaryId'])
)
.addOption(
new Option(
'-f, --file <file>',
'Name of the glossary export file to describe. If not specified, will automatically pull the glossary export data of the provided id from the tenant.'
)
)
.addOption(
new Option(
'-t, --glossary-type <type>',
'Filter glossary schema by type: role, entitlement, application, or account'
)
)
.action(async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
if (!options.glossaryId && !options.glossaryName && !options.file) {
printMessage(
'Unrecognized combination of options or no options...',
'error'
);
process.exitCode = 1;
program.help();
}
const getTokensIsSuccessful = await getTokens(
false,
true,
deploymentTypes
);
if (!getTokensIsSuccessful) process.exit(1);

if (!state.getIsIGA()) {
printMessage(
'Command not supported for non-IGA cloud tenants',
'error'
);
process.exit(1);
}
const objectType = options.glossaryType
? glossaryTypeMap[options.glossaryType]
: undefined;
if (options.glossaryType && !objectType) {
printMessage('Please provide a valid Object Type', 'error');
process.exitCode = 1;
program.help();
}
verboseMessage(`Describing glossary ${options.glossaryName ? options.glossaryId : options.glossaryName}...`);
const outcome = await describeGlossary(options.glossaryId, options.glossaryName, objectType, options.file);
if (!outcome) process.exitCode = 1;
});

return program;
}
Loading