Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new commands for managing managed objects #467

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
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
7 changes: 7 additions & 0 deletions src/cli/config/config-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,12 @@ export default function setup() {
'Export sync.idm.json mappings separately in their own directory. Ignored with -a.'
)
)
.addOption(
new Option(
'-o, --separate-objects',
'Export managed.idm.json objects separately in their own directory. Ignored with -a.'
)
)
.addOption(
new Option(
'--include-active-values',
Expand Down Expand Up @@ -145,6 +151,7 @@ export default function setup() {
const outcome = await exportEverythingToFiles(
options.extract,
options.separateMappings,
options.separateObjects,
options.metadata,
{
useStringArrays: options.useStringArrays,
Expand Down
8 changes: 8 additions & 0 deletions src/cli/idm/idm-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ export default function setup() {
'Export sync.idm.json mappings separately in their own directory. Ignored with -a.'
)
)
.addOption(
new Option(
'-o, --separate-objects',
'Export managed.idm.json objects separately in their own directory. Ignored with -a.'
)
)
.addOption(
new Option(
'-N, --no-metadata',
Expand Down Expand Up @@ -95,6 +101,7 @@ export default function setup() {
options.file,
options.envFile,
options.separateMappings,
options.separateObjects,
options.metadata
);
if (!outcome) process.exitCode = 1;
Expand Down Expand Up @@ -136,6 +143,7 @@ export default function setup() {
options.entitiesFile,
options.envFile,
options.separateMappings,
options.separateObjects,
options.metadata
);
if (!outcome) process.exitCode = 1;
Expand Down
130 changes: 130 additions & 0 deletions src/cli/idm/idm-schema-object-export.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import { state } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { getTokens } from '../../ops/AuthenticateOps';
import {
exportConfigEntityToFile,
exportManagedObjectToFile,
warnAboutOfflineConnectorServers,
} from '../../ops/IdmOps';
import { printMessage, verboseMessage } from '../../utils/Console';
import { FrodoCommand } from '../FrodoCommand';

const deploymentTypes = ['cloud', 'forgeops'];

export default function setup() {
const program = new FrodoCommand(
'frodo idm schema object export',
[],
deploymentTypes
);

program
.description('Export IDM configuration managed objects.')
.addOption(
new Option(
'-a, --all',
'Export all IDM configuration managed objects into a single file in directory -D.'
)
)
.addOption(
new Option(
'-A, --all-separate',
'Export all IDM configuration managed objects into separate JSON files in directory -D.'
)
)
.addOption(
new Option(
'-i, --individual-object <name>',
'Export an individual managed object by specifying an objects name. E.g. "alpha_user", "bravo_role", etc. If specified, -a and -A are ignored.'
)
)
.addOption(new Option('-f, --file [file]', 'Export file. Ignored with -A.'))
.addOption(
new Option(
'-N, --no-metadata',
'Does not include metadata in the export file.'
)
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
const envMessage = options.envFile
? ` using ${options.envFile} for variable replacement`
: '';
const fileMessage = options.file ? ` into ${options.file}` : '';
const directoryMessage = state.getDirectory()
? ` into separate files in ${state.getDirectory()}`
: '';
// -i, --individual-object <name>
if (
options.individualObject &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(
`Exporting managed object "${options.individualObject}"${envMessage}${fileMessage}...`
);
const outcome = await exportManagedObjectToFile(
options.individualObject,
options.file,
options.envFile
);
if (!outcome) process.exitCode = 1;
} // -a, --all
else if (
options.all &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(
`Exporting managed objects ${envMessage}${fileMessage}...`
);
const outcome = await exportConfigEntityToFile(
'managed',
options.file,
options.envFile,
false,
false,
options.metadata
);
if (!outcome) process.exitCode = 1;
} // -A, --all-separate
else if (
options.allSeparate &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(
`Exporting managed objects ${envMessage}${directoryMessage}...`
);
const outcome = await exportConfigEntityToFile(
'managed',
options.file,
options.envFile,
false,
true,
options.metadata
);
if (!outcome) process.exitCode = 1;
await warnAboutOfflineConnectorServers();
} // unrecognized combination of options or no options
else {
printMessage(
'Unrecognized combination of options or no options...',
'error'
);
program.help();
process.exitCode = 1;
}
}
// end command logic inside action handler
);

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

import { getTokens } from '../../ops/AuthenticateOps';
import {
importAllConfigEntitiesFromFile,
importAllConfigEntitiesFromFiles,
importManagedObjectFromFile,
} from '../../ops/IdmOps';
import { printMessage, verboseMessage } from '../../utils/Console';
import { FrodoCommand } from '../FrodoCommand';

const deploymentTypes = ['cloud', 'forgeops'];

export default function setup() {
const program = new FrodoCommand(
'frodo idm schema object import',
[],
deploymentTypes
);

program
.description('Import IDM configuration managed objects.')
.addOption(new Option('-f, --file [file]', 'Import file.'))
.addOption(
new Option(
'-i, --individual-object',
'Import an individual object. Requires the use of the -f to specify the file.'
)
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
const envMessage = options.envFile
? ` using ${options.envFile} for variable replacement`
: '';
const fileMessage = options.file ? ` from ${options.file}` : '';
const directoryMessage = state.getDirectory()
? ` from separate files in ${state.getDirectory()}`
: '';

// require -D --directory or -f --file to import managed objects
if (!state.getDirectory() && !options.file) {
printMessage(
'-D, --directory or -f, --file required to import managed objects',
'error'
);
program.help();
process.exitCode = 1;
} // -i, --individual-object
else if (
options.individualObject &&
options.file &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(
`Importing managed object ${envMessage}${fileMessage}...`
);
const outcome = await importManagedObjectFromFile(
options.file,
undefined,
options.envFile
);
if (!outcome) process.exitCode = 1;
} else if (
options.file &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(
`Importing IDM configuration objects ${envMessage}${fileMessage}`
);
const outcome = await importAllConfigEntitiesFromFile(
options.file,
undefined,
options.envFile
);
if (!outcome) process.exitCode = 1;
} else if (
state.getDirectory() &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(
`Importing IDM configuration objects ${envMessage}${directoryMessage}`
);
const outcome = await importAllConfigEntitiesFromFiles(
undefined,
options.envFile
);
if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
else {
printMessage(
'Unrecognized combination of options or no options...',
'error'
);
program.help();
process.exitCode = 1;
}
}
// end command logic inside action handler
);

return program;
}
15 changes: 15 additions & 0 deletions src/cli/idm/idm-schema-object.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { FrodoStubCommand } from '../FrodoCommand';
import ExportCmd from './idm-schema-object-export';
import ImportCmd from './idm-schema-object-import';

export default function setup() {
const program = new FrodoStubCommand('frodo idm schema object');

program.description('Manage IDM configuration objects.');

program.addCommand(ExportCmd().name('export'));

program.addCommand(ImportCmd().name('import'));

return program;
}
12 changes: 12 additions & 0 deletions src/cli/idm/idm-schema.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { FrodoStubCommand } from '../FrodoCommand';
import Objects from './idm-schema-object';

export default function setup() {
const program = new FrodoStubCommand('frodo idm schema');

program.description('Manage IDM schema.');

program.addCommand(Objects().name('object'));

return program;
}
3 changes: 3 additions & 0 deletions src/cli/idm/idm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import CountCmd from './idm-count.js';
import ExportCmd from './idm-export.js';
import ImportCmd from './idm-import.js';
import ListCmd from './idm-list.js';
import Schema from './idm-schema.js';

export default function setup() {
const program = new FrodoStubCommand('idm').description(
Expand All @@ -17,5 +18,7 @@ export default function setup() {

program.addCommand(CountCmd().name('count'));

program.addCommand(Schema().name('schema'));

return program;
}
Loading