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
26 changes: 9 additions & 17 deletions src/cli/idm/idm-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,21 +57,15 @@ export default function setup() {
)
.addOption(
new Option(
'-s, --separate-mappings',
'Export sync.idm.json mappings separately in their own directory. Ignored with -a.'
'-N, --no-metadata',
'Does not include metadata in the export file.'
)
)
.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',
'Does not include metadata in the export file.'
)
'-x, --no-extract',
'Do not extract and save idm scripts and save to separate files. Ignored with -a.'
).default(true, 'true')
)
.action(
// implement command logic inside action handler
Expand Down Expand Up @@ -106,9 +100,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 @@ -148,9 +141,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
19 changes: 12 additions & 7 deletions src/cli/idm/idm-schema-object-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ export default function setup() {
'Does not include metadata in the export file.'
)
)
.addOption(
new Option(
'-x, --no-extract',
'Do not extract and save idm scripts to separate files. Ignored with -a.'
).default(true, 'true')
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand Down Expand Up @@ -82,7 +88,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 @@ -97,9 +104,8 @@ export default function setup() {
'managed',
options.file,
options.envFile,
false,
false,
options.metadata
options.metadata,
false
Comment thread
phalestrivir marked this conversation as resolved.
);
if (!outcome) process.exitCode = 1;
} // -A, --all-separate
Expand All @@ -114,9 +120,8 @@ export default function setup() {
'managed',
options.file,
options.envFile,
false,
true,
options.metadata
options.metadata,
options.extract
);
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 @@ -64,6 +64,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, --no-extract',
'Do not extract and save idm scripts to separate files. Ignored with -a.'
).default(true, 'true')
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand All @@ -85,6 +91,7 @@ export default function setup() {
options.mappingId,
options.file,
options.metadata,
options.extract,
{
deps: options.deps,
useStringArrays: options.useStringArrays,
Expand Down Expand Up @@ -116,12 +123,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
64 changes: 37 additions & 27 deletions src/ops/ConfigOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ 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 +21,15 @@ 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 {
extractIdmScriptsToDirectory,
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 +92,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 +130,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 +142,7 @@ export async function exportEverythingToFiles(
`${baseDirectory}/realm/${realm}`,
includeMeta,
keepModifiedProperties,
extract,
separateMappings,
separateObjects
extract
)
)
);
Expand All @@ -163,8 +165,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 +173,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 +262,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 +273,35 @@ export function exportItem(
extract,
includeMeta
);
} else if (type === 'mapping') {
for (const mapping of Object.values(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') {
Comment thread
phalestrivir marked this conversation as resolved.
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 {
if (extract) {
extractIdmScriptsToDirectory(
id,
value,
`${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}/${id}`
);
}
const filename = `${id}.idm.json`;
if (filename.includes('/')) {
fs.mkdirSync(
Expand Down
Loading