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

Fix and Improve Imports and Exports #448

Merged
merged 1 commit into from
Nov 5, 2024
Merged
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion src/cli/FrodoCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ const stateMap = {
[deploymentOption.attributeName()]: (type: string) =>
state.setDeploymentType(type),
[directoryOption.attributeName()]: (directory: string) =>
state.setDirectory(directory),
state.setDirectory(directory.replaceAll('\\', '/').replaceAll('C:', '')),
[insecureOption.attributeName()]: (insecure: boolean) =>
state.setAllowInsecureConnection(insecure),
[verboseOption.attributeName()]: (verbose: boolean) =>
Expand Down
2 changes: 1 addition & 1 deletion src/cli/config/config-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export default function setup() {
.addOption(
new Option(
'-s, --separate-mappings',
'Export sync.json mappings separately in their own directory. Ignored with -a.'
'Export sync.idm.json mappings separately in their own directory. Ignored with -a.'
)
)
.addOption(
Expand Down
31 changes: 30 additions & 1 deletion src/cli/config/config-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Option } from 'commander';
import * as s from '../../help/SampleData';
import { getTokens } from '../../ops/AuthenticateOps';
import {
importEntityfromFile,
importEverythingFromFile,
importEverythingFromFiles,
} from '../../ops/ConfigOps';
Expand All @@ -15,7 +16,12 @@ export default function setup() {

program
.description('Import full cloud configuration.')
.addOption(new Option('-f, --file <file>', 'Name of the file to import.'))
.addOption(
new Option(
'-f, --file <file>',
'Name of the file to import. Ignored with -A. If included without -a, it will import the single entity within the file.'
)
)
.addOption(
new Option(
'-a, --all',
Expand Down Expand Up @@ -61,6 +67,12 @@ export default function setup() {
'Host URL of the environment which performed secret value encryption. The URL must resolve to an existing connection profile. Use this option to import a file that was exported from a different source environment than the one you are importing to.'
)
)
.addOption(
new Option(
'-g, --global',
'Import global entity. Ignored with -a and -A.'
)
)
.addHelpText(
'after',
`How Frodo handles secrets:\n`['brightGreen'] +
Expand Down Expand Up @@ -135,6 +147,23 @@ export default function setup() {
});
if (!outcome) process.exitCode = 1;
}
// Import entity from file
else if (options.file && (await getTokens())) {
verboseMessage('Importing config entity from file...');
const outcome = await importEntityfromFile(
options.file,
options.global,
{
reUuidJourneys: options.reUuidJourneys,
reUuidScripts: options.reUuidScripts,
cleanServices: options.clean,
includeDefault: options.default,
includeActiveValues: options.includeActiveValues,
source: options.source,
}
);
if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
else {
verboseMessage(
Expand Down
99 changes: 57 additions & 42 deletions src/cli/idm/idm-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ import { Option } from 'commander';

import { getTokens } from '../../ops/AuthenticateOps';
import {
exportAllConfigEntities,
exportAllRawConfigEntities,
exportConfigEntity,
exportAllConfigEntitiesToFile,
exportAllConfigEntitiesToFiles,
exportConfigEntityToFile,
warnAboutOfflineConnectorServers,
} from '../../ops/IdmOps';
import { printMessage, verboseMessage } from '../../utils/Console';
Expand All @@ -20,8 +20,8 @@ export default function setup() {
.description('Export IDM configuration objects.')
.addOption(
new Option(
'-N, --name <name>',
'Config entity name. E.g. "managed", "sync", "provisioner-<connector-name>", etc.'
'-i, --entity-id <id>',
'Config entity id/name. E.g. "managed", "sync", "provisioner-<connector-name>", etc. If specified, -a and -A are ignored.'
)
)
.addOption(
Expand All @@ -33,31 +33,32 @@ export default function setup() {
.addOption(
new Option(
'-E, --entities-file [entities-file]',
'Name of the entity file. Ignored with -A.'
'Name of the entity file. Ignored with -i.'
)
)
.addOption(new Option('-e, --env-file [envfile]', 'Name of the env file.'))
.addOption(
new Option(
'-e, --env-file [envfile]',
'Name of the env file. Ignored with -A.'
'-a, --all',
'Export all IDM configuration objects into a single file in directory -D. Ignored with -i.'
)
)
.addOption(
new Option(
'-a, --all',
'Export all IDM configuration objects into a single file in directory -D. Ignored with -N.'
'-A, --all-separate',
'Export all IDM configuration objects into separate JSON files in directory -D. Ignored with -i, and -a.'
)
)
.addOption(
new Option(
'-A, --all-separate',
'Export all IDM configuration objects into separate JSON files in directory -D. Ignored with -N, and -a.'
'-s, --separate-mappings',
'Export sync.idm.json mappings separately in their own directory. Ignored with -a.'
)
)
.addOption(
new Option(
'-s, --separate-mappings',
'Export sync.json mappings separately in their own directory.'
'-N, --no-metadata',
'Does not include metadata in the export file.'
)
)
.action(
Expand All @@ -71,15 +72,48 @@ export default function setup() {
options,
command
);
const entitiesMessage = options.entitiesFile
? ` specified in ${options.entitiesFile}`
: '';
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()}`
: '';
// export by id/name
if (options.name && (await getTokens(false, true, deploymentTypes))) {
verboseMessage(`Exporting object "${options.name}"...`);
const outcome = await exportConfigEntity(
options.name,
if (
options.entityId &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(
`Exporting object "${options.entityId}"${envMessage}${fileMessage}...`
);
const outcome = await exportConfigEntityToFile(
options.entityId,
options.file,
options.separateMappings
options.envFile,
options.separateMappings,
options.metadata
);
if (!outcome) process.exitCode = 1;
// --all -a
} else if (
options.all &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(
`Exporting IDM configuration objects${entitiesMessage}${envMessage}${fileMessage}...`
);
const outcome = await exportAllConfigEntitiesToFile(
options.file,
options.entitiesFile,
options.envFile,
options.metadata
);
if (!outcome) process.exitCode = 1;
await warnAboutOfflineConnectorServers();
}
// require --directory -D for all-separate functions
else if (options.allSeparate && !state.getDirectory()) {
Expand All @@ -93,35 +127,16 @@ export default function setup() {
// --all-separate -A
else if (
options.allSeparate &&
options.entitiesFile &&
options.envFile &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(
`Exporting IDM configuration objects specified in ${
options.entitiesFile
} into separate files in ${state.getDirectory()} using ${
options.envFile
} for variable replacement...`
`Exporting IDM configuration objects${entitiesMessage}${envMessage}${directoryMessage}...`
);
const outcome = await exportAllConfigEntities(
const outcome = await exportAllConfigEntitiesToFiles(
options.entitiesFile,
options.envFile,
options.separateMappings
);
if (!outcome) process.exitCode = 1;
await warnAboutOfflineConnectorServers();
}
// --all-separate -A without variable replacement
else if (
options.allSeparate &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(
`Exporting all IDM configuration objects into separate files in ${state.getDirectory()}...`
);
const outcome = await exportAllRawConfigEntities(
options.separateMappings
options.separateMappings,
options.metadata
);
if (!outcome) process.exitCode = 1;
await warnAboutOfflineConnectorServers();
Expand Down
91 changes: 56 additions & 35 deletions src/cli/idm/idm-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Option } from 'commander';

import { getTokens } from '../../ops/AuthenticateOps';
import {
importAllConfigEntities,
importAllRawConfigEntities,
importAllConfigEntitiesFromFile,
importAllConfigEntitiesFromFiles,
importConfigEntityByIdFromFile,
importConfigEntityFromFile,
importFirstConfigEntityFromFile,
} from '../../ops/IdmOps';
import { printMessage, verboseMessage } from '../../utils/Console';
import { FrodoCommand } from '../FrodoCommand';
Expand All @@ -22,7 +22,7 @@ export default function setup() {
verbose?: boolean;
debug?: boolean;
curlirize?: boolean;
name?: string;
entityId?: string;
file?: string;
entitiesFile?: string;
envFile?: string;
Expand All @@ -35,27 +35,28 @@ export default function setup() {
.description('Import IDM configuration objects.')
.addOption(
new Option(
'-N, --name <name>',
'Config entity name. E.g. "managed", "sync", "provisioner-<connector-name>", etc.'
'-i, --entity-id <id>',
'Config entity id/name. E.g. "managed", "sync", "provisioner-<connector-name>", etc. If specified, -a and -A are ignored.'
)
)
.addOption(new Option('-f, --file [file]', 'Import file. Ignored with -A.'))
.addOption(
new Option(
'-E, --entities-file [entities-file]',
'Name of the entity file. Ignored with -A.'
'Name of the entity file. Ignored with -i.'
)
)
.addOption(new Option('-e, --env-file [envfile]', 'Name of the env file.'))
.addOption(
new Option(
'-e, --env-file [envfile]',
'Name of the env file. Ignored with -A.'
'-a, --all',
'Import all IDM configuration objects from a single file in directory -D. Ignored with -i.'
)
)
.addOption(
new Option(
'-A, --all-separate',
'Import all IDM configuration objects from separate files in directory -D. Ignored with -N, and -a.'
'Import all IDM configuration objects from separate files in directory -D. Ignored with -i, and -a.'
)
)
.action(
Expand All @@ -76,12 +77,44 @@ export default function setup() {
options,
command
);
const entitiesMessage = options.entitiesFile
? ` specified in ${options.entitiesFile}`
: '';
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()}`
: '';
// import by id/name
if (options.name && (await getTokens(false, true, deploymentTypes))) {
verboseMessage(`Importing object "${options.name}"...`);
if (
options.entityId &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(
`Importing object "${options.entityId}"${envMessage}${fileMessage}...`
);
const outcome = await importConfigEntityByIdFromFile(
options.name,
options.file
options.entityId,
options.file,
options.envFile
);
if (!outcome) process.exitCode = 1;
}
// --all -a
else if (
options.all &&
options.file &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(
`Importing IDM configuration objects${entitiesMessage}${envMessage}${fileMessage}`
);
const outcome = await importAllConfigEntitiesFromFile(
options.file,
options.entitiesFile,
options.envFile
);
if (!outcome) process.exitCode = 1;
}
Expand All @@ -90,8 +123,13 @@ export default function setup() {
options.file &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(`Importing object from file...`);
const outcome = await importConfigEntityFromFile(options.file);
verboseMessage(
`Importing first object${envMessage}${fileMessage}...`
);
const outcome = await importFirstConfigEntityFromFile(
options.file,
options.envFile
);
if (!outcome) process.exitCode = 1;
}
// require --directory -D for all-separate functions
Expand All @@ -106,34 +144,17 @@ export default function setup() {
// --all-separate -A
else if (
options.allSeparate &&
options.entitiesFile &&
options.envFile &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(
`Importing IDM configuration objects specified in ${
options.entitiesFile
} into separate files in ${state.getDirectory()} using ${
options.envFile
} for variable replacement...`
`Importing IDM configuration objects${entitiesMessage}${envMessage}${directoryMessage}`
);
const outcome = await importAllConfigEntities(
const outcome = await importAllConfigEntitiesFromFiles(
options.entitiesFile,
options.envFile
);
if (!outcome) process.exitCode = 1;
}
// --all-separate -A without variable replacement
else if (
options.allSeparate &&
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage(
`Importing all IDM configuration objects from separate files in ${state.getDirectory()}...`
);
const outcome = await importAllRawConfigEntities();
if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
else {
printMessage(
Expand Down
Loading
Loading