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
14 changes: 0 additions & 14 deletions src/cli/config/config-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,18 +87,6 @@ export default function setup() {
'Export only the global config. If -r, --realm-only is also active, then the corresponding active realm config will also be exported.'
)
)
.addOption(
new Option(
'-s, --separate-mappings',
'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 @@ -188,8 +176,6 @@ export default function setup() {
verboseMessage('Exporting everything to separate files...');
const outcome = await exportEverythingToFiles(
options.extract,
options.separateMappings,
options.separateObjects,
options.metadata,
options.modifiedProperties,
{
Expand Down
24 changes: 8 additions & 16 deletions src/cli/idm/idm-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,20 +51,14 @@ export default function setup() {
)
.addOption(
new Option(
'-s, --separate-mappings',
'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.'
'-N, --no-metadata',
'Does not include metadata in the export file.'
)
)
.addOption(
new Option(
'-N, --no-metadata',
'Does not include metadata in the export file.'
'-x, --extract',
'Extract idm scripts and save the extracted scripts to separate files. Ignored with -a.'
)
)
.action(
Expand Down Expand Up @@ -100,9 +94,8 @@ export default function setup() {
options.entityId,
options.file,
options.envFile,
options.separateMappings,
options.separateObjects,
options.metadata
options.metadata,
options.extract
);
if (!outcome) process.exitCode = 1;
// --all -a
Expand Down Expand Up @@ -142,9 +135,8 @@ export default function setup() {
const outcome = await exportAllConfigEntitiesToFiles(
options.entitiesFile,
options.envFile,
options.separateMappings,
options.separateObjects,
options.metadata
options.metadata,
options.extract
);
if (!outcome) process.exitCode = 1;
await warnAboutOfflineConnectorServers();
Expand Down
20 changes: 13 additions & 7 deletions src/cli/idm/idm-schema-object-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ export default function setup() {
'Does not include metadata in the export file.'
)
)
.addOption(
new Option(
'-x, --extract',
'Extract idm scripts and save the extracted scripts to separate files. Ignored with -a.'
)
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand Down Expand Up @@ -76,7 +82,8 @@ export default function setup() {
const outcome = await exportManagedObjectToFile(
options.individualObject,
options.file,
options.envFile
options.envFile,
options.extract
);
if (!outcome) process.exitCode = 1;
} // -a, --all
Expand All @@ -91,9 +98,8 @@ export default function setup() {
'managed',
options.file,
options.envFile,
false,
false,
options.metadata
options.metadata,
false
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be options.extract (it should be supported for individual objects). For example, if I want to export only alpha_user, alpha_user may have an onUpdate script, onCreate script, etc.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one is for -a, and I dont think we want to extract script for -a option

);
if (!outcome) process.exitCode = 1;
} // -A, --all-separate
Expand All @@ -108,9 +114,9 @@ export default function setup() {
'managed',
options.file,
options.envFile,
false,
true,
options.metadata
options.metadata,
options.extract,
true
);
if (!outcome) process.exitCode = 1;
await warnAboutOfflineConnectorServers();
Expand Down
23 changes: 17 additions & 6 deletions src/cli/mapping/mapping-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,12 @@ export default function setup() {
'Where applicable, use string arrays to store multi-line text (e.g. scripts).'
).default(false, 'off')
)
.addOption(
new Option(
'-x, --extract',
'Extract idm scripts and save the extracted scripts to separate files. Ignored with -a.'
)
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand All @@ -78,6 +84,7 @@ export default function setup() {
options.mappingId,
options.file,
options.metadata,
options.extract,
{
deps: options.deps,
useStringArrays: options.useStringArrays,
Expand Down Expand Up @@ -109,12 +116,16 @@ export default function setup() {
(await getTokens(false, true, deploymentTypes))
) {
verboseMessage('Exporting all mappings to separate files...');
const outcome = await exportMappingsToFiles(options.metadata, {
connectorId: options.connectorId,
moType: options.managedObjectType,
deps: options.deps,
useStringArrays: options.useStringArrays,
});
const outcome = await exportMappingsToFiles(
options.metadata,
options.extract,
{
connectorId: options.connectorId,
moType: options.managedObjectType,
deps: options.deps,
useStringArrays: options.useStringArrays,
}
);
if (!outcome) process.exitCode = 1;
}
// unrecognized combination of options or no options
Expand Down
69 changes: 41 additions & 28 deletions src/ops/ConfigOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
FullImportOptions,
FullRealmExportInterface,
} from '@rockcarver/frodo-lib/types/ops/ConfigOps';
import { SyncSkeleton } from '@rockcarver/frodo-lib/types/ops/MappingOps';
import { MappingSkeleton, SyncSkeleton } from '@rockcarver/frodo-lib/types/ops/MappingOps';
import { CustomNodeExportInterface } from '@rockcarver/frodo-lib/types/ops/NodeOps';
import { ScriptExportInterface } from '@rockcarver/frodo-lib/types/ops/ScriptOps';
import fs from 'fs';
Expand All @@ -18,8 +18,16 @@ import {
} from '../utils/Config';
import { cleanupProgressIndicators, printError } from '../utils/Console';
import { saveServersToFiles } from './classic/ServerOps';
import { ManagedSkeleton, writeManagedJsonToDirectory } from './IdmOps';
import { writeSyncJsonToDirectory } from './MappingOps';
import {
extractIdmScriptToSameLevel,
findScriptsFromIdm,
ManagedSkeleton,
writeManagedJsonToDirectory,
} from './IdmOps';
import {
writeMappingJsonToDirectory,
writeSyncJsonToDirectory,
} from './MappingOps';
import { extractCustomNodeScriptsToFiles } from './NodeOps';
import { extractScriptsToFiles } from './ScriptOps';
import { errorHandler } from './utils/OpsUtils';
Expand Down Expand Up @@ -82,17 +90,13 @@ export async function exportEverythingToFile(
/**
* Export everything to separate files
* @param {boolean} extract Extracts the scripts from the exports into separate files if true
* @param {boolean} separateMappings separate sync.idm.json mappings if true, otherwise keep them in a single file
* @param {boolean} separateObjects separate managed.idm.json objects if true, otherwise keep them in a single file
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
* @param {boolean} keepModifiedProperties true to keep modified properties, otherwise delete them. Default: false
* @param {FullExportOptions} options export options
* @return {Promise<boolean>} a promise that resolves to true if successful, false otherwise
*/
export async function exportEverythingToFiles(
extract: boolean = false,
separateMappings: boolean = false,
separateObjects: boolean = false,
includeMeta: boolean = true,
keepModifiedProperties: boolean = false,
options: FullExportOptions = {
Expand Down Expand Up @@ -124,9 +128,7 @@ export async function exportEverythingToFiles(
`${baseDirectory}/global`,
includeMeta,
keepModifiedProperties,
extract,
separateMappings,
separateObjects
extract
)
);
Object.entries(exportData.realm).forEach(([realm, data]: [string, any]) =>
Expand All @@ -138,9 +140,7 @@ export async function exportEverythingToFiles(
`${baseDirectory}/realm/${realm}`,
includeMeta,
keepModifiedProperties,
extract,
separateMappings,
separateObjects
extract
)
)
);
Expand All @@ -163,8 +163,6 @@ export async function exportEverythingToFiles(
* @param {boolean} includeMeta true to include metadata, false otherwise. Default: true
* @param {boolean} keepModifiedProperties true to keep modified properties, otherwise delete them. Default: false
* @param {boolean} extract Extracts the scripts from the exports into separate files if true
* @param {boolean} separateMappings separate sync.idm.json mappings if true, otherwise keep them in a single file
* @param {boolean} separateObjects separate managed.idm.json objects if true, otherwise keep them in a single file
*/
export function exportItem(
exportData,
Expand All @@ -173,9 +171,7 @@ export function exportItem(
baseDirectory,
includeMeta,
keepModifiedProperties,
extract,
separateMappings = false,
separateObjects = false
extract
) {
if (!obj || !Object.keys(obj).length) {
return;
Expand Down Expand Up @@ -264,7 +260,8 @@ export function exportItem(
writeSyncJsonToDirectory(
obj as SyncSkeleton,
`${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}`,
includeMeta
includeMeta,
extract
);
} else if (type === 'server') {
saveServersToFiles(
Expand All @@ -274,24 +271,40 @@ export function exportItem(
extract,
includeMeta
);
} else if (type === 'mapping') {
for (const [id, mapping] of Object.entries(obj)){
writeMappingJsonToDirectory(
mapping as MappingSkeleton,
`${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}`,
includeMeta,
extract
);
}
} else {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Object.entries(obj).forEach(([id, value]: [string, any]) => {
if (type === 'idm') {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Everything inside this if statement is being repeated in IdmOps. We should have a helper function created that does this logic (put the helper function in IDM Ops, and call it something like writeIdmEntityToJson)

if (value != null) {
if (separateMappings && id === 'sync') {
writeSyncJsonToDirectory(
value as SyncSkeleton,
`${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}/sync`,
includeMeta
);
} else if (separateObjects && id === 'managed') {
if (extract && id === 'managed') {
writeManagedJsonToDirectory(
value as ManagedSkeleton,
`${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}/managed`,
includeMeta
includeMeta,
extract
);
} else {
}
else {
if (extract) {
const result = findScriptsFromIdm(value);
if (result.length !== 0) {
extractIdmScriptToSameLevel(
id,
value,
result,
`${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}/`
);
}
}
const filename = `${id}.idm.json`;
if (filename.includes('/')) {
fs.mkdirSync(
Expand Down
Loading