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
13 changes: 11 additions & 2 deletions src/cli/idm/idm-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ export default function setup() {
'Does not include metadata in the export file.'
)
)

.addOption(
new Option(
'-x, --extract',
'Extract the scripts from the exported file, and save it to a separate file. Ignored with -a.'
)
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand Down Expand Up @@ -112,7 +119,8 @@ export default function setup() {
options.envFile,
options.separateMappings,
options.separateObjects,
options.metadata
options.metadata,
options.extract
);
if (!outcome) process.exitCode = 1;
// --all -a
Expand Down Expand Up @@ -154,7 +162,8 @@ export default function setup() {
options.envFile,
options.separateMappings,
options.separateObjects,
options.metadata
options.metadata,
options.extract
);
if (!outcome) process.exitCode = 1;
await warnAboutOfflineConnectorServers();
Expand Down
13 changes: 11 additions & 2 deletions src/cli/idm/idm-schema-object-export.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ export default function setup() {
'Does not include metadata in the export file.'
)
)
.addOption(
new Option(
'-x, --extract',
'Extract scripts from the exported file, and save it to a separate file. Ignored with -a.'
)
)

.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand Down Expand Up @@ -103,7 +110,8 @@ export default function setup() {
options.envFile,
false,
false,
options.metadata
options.metadata,
false
);
if (!outcome) process.exitCode = 1;
} // -A, --all-separate
Expand All @@ -120,7 +128,8 @@ export default function setup() {
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 @@ -68,6 +68,13 @@ 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 the script from the exported file, and save it to a separate file. Ignored with -a.'
)
)
.action(
// implement command logic inside action handler
async (host, realm, user, password, options, command) => {
Expand Down Expand Up @@ -120,12 +127,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
83 changes: 76 additions & 7 deletions src/ops/ConfigOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,19 @@ 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 {
extractIdmEndpointScript,
extractIdmScriptsToFolder,
extractIdmScriptToSameLevel,
findScriptsFromIdm,
ManagedSkeleton,
writeManagedJsonToDirectory,
} from './IdmOps';
import {
extractMappingScripts,
writeMappingJsonToDirectory,
writeSyncJsonToDirectory,
} from './MappingOps';
import { extractScriptsToFiles } from './ScriptOps';

const {
Expand Down Expand Up @@ -245,7 +256,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 @@ -255,24 +267,79 @@ export function exportItem(
extract,
includeMeta
);
} else if (type === 'mapping') {
writeMappingJsonToDirectory(
obj,
`${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') {
if (value != null) {
if (separateMappings && id === 'sync') {
if ((separateMappings || extract) && id === 'sync') {
writeSyncJsonToDirectory(
value as SyncSkeleton,
`${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}/sync`,
includeMeta
includeMeta,
extract
);
} else if (separateObjects && id === 'managed') {
} else if ((separateObjects || extract) && id === 'managed') {
writeManagedJsonToDirectory(
value as ManagedSkeleton,
`${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}/managed`,
includeMeta
includeMeta,
extract
);
} else {
if (extract) {
if (id.includes('endpoint/')) {
const result = findScriptsFromIdm(value);
if (result.length !== 0) {
const endpointId = id.replace('endpoint/', '');
extractIdmEndpointScript(
endpointId,
value,
result,
`${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}/endpoint/`
);
}
} else if (id.includes('schedule/')) {
const result = findScriptsFromIdm(value);
if (result.length !== 0) {
const scheduleId = id.replace('schedule/', '');
extractIdmScriptToSameLevel(
scheduleId,
value,
result,
`${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}/schedule/`
);
}
} else if (id.includes('mapping/')) {
const result = findScriptsFromIdm(obj);
if (result.length !== 0) {
const mappingId = id.replace('mapping/', '');
extractMappingScripts(
`${mappingId}.mapping.script`,
obj,
result,
`mapping/`
);
}
} else {
const result = findScriptsFromIdm(value);
if (result.length !== 0) {
extractIdmScriptsToFolder(
`${id}.idm.scripts`,
value,
result,
`${baseDirectory.substring(getWorkingDirectory(false).length + 1)}/${fileType}`
);
}
}
}
const filename = `${id}.idm.json`;
if (filename.includes('/')) {
fs.mkdirSync(
Expand Down Expand Up @@ -387,6 +454,8 @@ export async function importEverythingFromFiles(
try {
const data = await getFullExportConfigFromDirectory(getWorkingDirectory());
const collectErrors: Error[] = [];
saveJsonToFile(data, '../idmtest/aasdfasdf.json');

await importFullConfiguration(data, options, collectErrors);
if (collectErrors.length > 0) {
throw new FrodoError(
Expand Down
Loading