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
75 changes: 75 additions & 0 deletions src/cli/iga/config/iga-config-describe.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import { frodo, state } from '@rockcarver/frodo-lib';
import { Option } from 'commander';

import { getTokens } from '../../../ops/AuthenticateOps';
import { describeConfigByKey } from '../../../ops/cloud/iga/IgaConfigOps';
import { printMessage, verboseMessage } from '../../../utils/Console';
import { FrodoCommand } from '../../FrodoCommand';

const { CLOUD_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;

const deploymentTypes = [CLOUD_DEPLOYMENT_TYPE_KEY];

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

program
.description('Describe iga config.')
.addOption(
new Option(
'-n, --config-key <config-key>',
'Iga config key. If not specified, will describe first iga config key in the provided export file.'
)
)
.addOption(
new Option(
'-f, --file <file>',
'Name of the iga config export file to describe. If not specified, will automatically pull the iga config export data of the provided id from the tenant.'
)
)
.action(async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
if (!options.configKey && !options.file) {
printMessage(
'Unrecognized combination of options or no options...',
'error'
);
program.help();
process.exitCode = 1;
return;
}
const getTokensIsSuccessful = await getTokens(
false,
true,
deploymentTypes
);
if (!getTokensIsSuccessful) {
printMessage('Error getting tokens', 'error');
process.exitCode = 1;
return;
}
if (!state.getIsIGA()) {
printMessage(
'Command not supported for non-IGA cloud tenants',
'error'
);
process.exitCode = 1;
return;
}
verboseMessage(`Describing iga config ${options.configKey}...`);
const outcome = await describeConfigByKey(
options.configKey,
options.file
);
if (!outcome) process.exitCode = 1;
});

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

import { getTokens } from '../../../ops/AuthenticateOps';
import {
exportConfigByKeyToFile,
exportConfigurationsToFile,
exportConfigurationsToFiles,
} from '../../../ops/cloud/iga/IgaConfigOps';
import { printMessage, verboseMessage } from '../../../utils/Console.js';
import { FrodoCommand } from '../../FrodoCommand';

const { CLOUD_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;

const deploymentTypes = [CLOUD_DEPLOYMENT_TYPE_KEY];

export default function setup() {
const program = new FrodoCommand(
'frodo iga config export',
[],
deploymentTypes
);

program
.description('Export config.')
.addOption(
new Option(
'-n, --config-key <config-key>',
'Config key. If specified, -a and -A are ignored.'
)
)
.addOption(
new Option(
'-f, --file [file]',
'Name of the export file. Ignored with -A. Defaults to <config-key>.config.json.'
)
)
.addOption(
new Option(
'-a, --all',
'Export all iga config to a single file. Ignored with -i.'
)
)
.addOption(
new Option(
'-A, --all-separate',
'Export all iga config as separate files <config-key>.config.json. Ignored with -n, and -a.'
)
)
.addOption(
new Option(
'-N, --no-metadata',
'Do not include metadata in the export file.'
)
)
.addOption(
new Option(
'-M, --modified-properties',
'Include modified properties in export (e.g. lastModifiedDate, lastModifiedBy, createdBy, creationDate, etc.)'
).default(false, 'false')
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
if (!options.configKey && !options.all && !options.allSeparate) {
printMessage(
'Unrecognized combination of options or no options...',
'error'
);
program.help();
process.exitCode = 1;
return;
}
const getTokensIsSuccessful = await getTokens(
false,
true,
deploymentTypes
);
if (!getTokensIsSuccessful) {
printMessage('Error getting tokens', 'error');
process.exitCode = 1;
return;
}
if (!state.getIsIGA()) {
printMessage(
'Command not supported for non-IGA cloud tenants',
'error'
);
process.exitCode = 1;
return;
}
// --config-key -n
if (options.configKey) {
verboseMessage(`Exporting iga config "${options.configKey}"...`);
const outcome = await exportConfigByKeyToFile(
options.configKey,
options.file,
options.metadata,
options.modifiedProperties
);
if (!outcome) process.exitCode = 1;
}
// --all -a
else if (options.all) {
verboseMessage('Exporting all iga config to a single file...');
const outcome = await exportConfigurationsToFile(
options.file,
options.metadata,
options.modifiedProperties
);
if (!outcome) process.exitCode = 1;
}
// --all-separate -A
else if (options.allSeparate) {
verboseMessage('Exporting all iga config to separate files...');
const outcome = await exportConfigurationsToFiles(
options.metadata,
options.modifiedProperties
);
if (!outcome) process.exitCode = 1;
}
}
// end command logic inside action handler
);

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

import { getTokens } from '../../../ops/AuthenticateOps';
import {
importConfigFromFile,
importConfigurationsFromFile,
importConfigurationsFromFiles,
importFirstConfigFromFile,
} from '../../../ops/cloud/iga/IgaConfigOps';
import { printMessage, verboseMessage } from '../../../utils/Console.js';
import { FrodoCommand } from '../../FrodoCommand';

const { CLOUD_DEPLOYMENT_TYPE_KEY } = frodo.utils.constants;

const deploymentTypes = [CLOUD_DEPLOYMENT_TYPE_KEY];

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

program
.description('Import iga config.')
.addOption(
new Option(
'-n, --config-key <wconfig-key>',
'Config key. If specified, -a and -A are ignored.'
)
)
.addOption(new Option('-f, --file <file>', 'Name of the import file.'))
.addOption(
new Option(
'-a, --all',
'Import all iga config from single file. Ignored with -i.'
)
)
.addOption(
new Option(
'-A, --all-separate',
'import all iga config as separate files <config-key>.config.json. Ignored with -n, and -a.'
)
)

.action(
// implement program logic inside action handler
async (host, realm, user, password, options, command) => {
command.handleDefaultArgsAndOpts(
host,
realm,
user,
password,
options,
command
);
const isImportById = options.configKey && options.file;
const isImportAll = options.all && options.file;
const isImportAllSeparate = options.allSeparate && !options.file;
const isImportFirst = !!options.file;
if (
!isImportById &&
!isImportAll &&
!isImportAllSeparate &&
!isImportFirst
) {
printMessage(
'Unrecognized combination of options or no options...',
'error'
);
program.help();
process.exitCode = 1;
return;
}
const getTokensIsSuccessful = await getTokens(
false,
true,
deploymentTypes
);
if (!getTokensIsSuccessful) {
printMessage('Error getting tokens', 'error');
process.exitCode = 1;
return;
}
if (!state.getIsIGA()) {
printMessage(
'Command not supported for non-IGA cloud tenants',
'error'
);
process.exitCode = 1;
return;
}
// import by id
if (isImportById) {
verboseMessage(`Importing iga config "${options.configKey}"...`);
const outcome = await importConfigFromFile(
options.configKey,
options.file
);
if (!outcome) process.exitCode = 1;
}
// --all -a
else if (isImportAll) {
verboseMessage(
`Importing all iga config from a single file (${options.file})...`
);
const outcome = await importConfigurationsFromFile(options.file);
if (!outcome) process.exitCode = 1;
}
// --all-separate -A
else if (options.allSeparate) {
verboseMessage('Importing all iga config to separate files...');
const outcome = await importConfigurationsFromFiles();
if (!outcome) process.exitCode = 1;
}
// import first iga config from file
else if (isImportFirst) {
verboseMessage(
`Importing first iga config from file "${options.file}"...`
);
const outcome = await importFirstConfigFromFile(options.file);
if (!outcome) process.exitCode = 1;
}
}
// end program logic inside action handler
);

return program;
}
Loading