import { AgentGroupSkeleton, AgentSkeleton } from '../api/AgentApi'; import { AmConfigEntitiesInterface } from '../api/AmConfigApi'; import { IdObjectSkeletonInterface } from '../api/ApiTypes'; import { AuthenticationSettingsSkeleton } from '../api/AuthenticationSettingsApi'; import { CircleOfTrustSkeleton } from '../api/CirclesOfTrustApi'; import { SiteSkeleton } from '../api/classic/SiteApi'; import { CertificationTemplateSkeleton } from '../api/cloud/iga/IgaCertificationTemplateApi'; import { EventSkeleton } from '../api/cloud/iga/IgaEventApi'; import { GlossarySchemaItemSkeleton } from '../api/cloud/iga/IgaGlossaryApi'; import { RequestFormSkeleton } from '../api/cloud/iga/IgaRequestFormApi'; import { RequestTypeSkeleton } from '../api/cloud/iga/IgaRequestTypeApi'; import { SecretSkeleton } from '../api/cloud/SecretsApi'; import { TelemetryExporters } from '../api/cloud/TelemetryApi'; import { VariableSkeleton } from '../api/cloud/VariablesApi'; import { CustomNodeSkeleton } from '../api/NodeApi'; import { CIMDProfileSkeleton } from '../api/OAuth2CIMDProfileApi'; import { OAuth2ClientSkeleton } from '../api/OAuth2ClientApi'; import { OAuth2TrustedJwtIssuerSkeleton } from '../api/OAuth2TrustedJwtIssuerApi'; import { PolicySkeleton } from '../api/PoliciesApi'; import { PolicySetSkeleton } from '../api/PolicySetApi'; import { RealmSkeleton } from '../api/RealmApi'; import { ResourceTypeSkeleton } from '../api/ResourceTypesApi'; import { Saml2ProviderSkeleton } from '../api/Saml2Api'; import { ScriptSkeleton } from '../api/ScriptApi'; import { AmServiceSkeleton } from '../api/ServiceApi'; import { SocialIdpSkeleton } from '../api/SocialIdentityProvidersApi'; import Constants from '../shared/Constants'; import { State } from '../shared/State'; import { createProgressIndicator, debugMessage, stopProgressIndicator, } from '../utils/Console'; import { exportWithErrorHandling, getErrorCallback, getMetadata, importWithErrorHandling, } from '../utils/ExportImportUtils'; import { getRealmsForExport, getRealmUsingExportFormat, skipsDeniedRootRealmRequests, } from '../utils/ForgeRockUtils'; import { exportAgentGroups, exportAgents, importAgentGroups, importAgents, } from './AgentOps'; import { ConfigEntityExportInterface, exportAmConfigEntities, importAmConfigEntities, } from './AmConfigOps'; import { ApplicationGlossarySkeleton, exportApplications, importApplications, } from './ApplicationOps'; import { exportAuthenticationSettings, importAuthenticationSettings, } from './AuthenticationSettingsOps'; import { CirclesOfTrustExportInterface, exportCirclesOfTrust, importCirclesOfTrust, } from './CirclesOfTrustOps'; import { exportServers, importServers, ServerExportInterface, } from './classic/ServerOps'; import { exportSites, importSites } from './classic/SiteOps'; import { exportCertificationTemplates, importCertificationTemplates, } from './cloud/iga/IgaCertificationTemplateOps'; import { exportEvents, importEvents } from './cloud/iga/IgaEventOps'; import { exportGlossarySchemas, importGlossarySchemas, } from './cloud/iga/IgaGlossaryOps'; import { exportRequestForms, importRequestForms, } from './cloud/iga/IgaRequestFormOps'; import { exportRequestTypes, importRequestTypes, } from './cloud/iga/IgaRequestTypeOps'; import { exportWorkflows, importWorkflows, WorkflowGroups, } from './cloud/iga/IgaWorkflowOps'; import { exportSecrets, importSecrets } from './cloud/SecretsOps'; import { exportTelemetry, importTelemetry } from './cloud/TelemetryOps'; import { exportVariables, importVariables } from './cloud/VariablesOps'; import { EmailTemplateSkeleton, exportEmailTemplates, importEmailTemplates, } from './EmailTemplateOps'; import { exportConfigEntities, importConfigEntities } from './IdmConfigOps'; import { exportSocialIdentityProviders, importSocialIdentityProviders, } from './IdpOps'; import { routeAgentSection } from './internal/AgentSectionRouting'; import { exportInternalRoles, importInternalRoles, InternalRoleSkeleton, } from './InternalRoleOps'; import { exportJourneys, importJourneys, SingleTreeExportInterface, } from './JourneyOps'; import { exportMappings, importMappings, MappingSkeleton, SyncSkeleton, } from './MappingOps'; import { exportCustomNodes, importCustomNodes } from './NodeOps'; import { exportCIMDProfiles, importCIMDProfiles } from './OAuth2CIMDProfileOps'; import { exportOAuth2Clients, importOAuth2Clients } from './OAuth2ClientOps'; import { exportOAuth2TrustedJwtIssuers, importOAuth2TrustedJwtIssuers, } from './OAuth2TrustedJwtIssuerOps'; import { ExportMetaData, ResultCallback } from './OpsTypes'; import { exportPolicies, importPolicies } from './PolicyOps'; import { exportPolicySets, importPolicySets } from './PolicySetOps'; import { exportRealms, importRealms } from './RealmOps'; import { exportResourceTypes, importResourceTypes } from './ResourceTypeOps'; import { exportSaml2Providers, importSaml2Providers } from './Saml2Ops'; import { exportScripts, importScripts } from './ScriptOps'; import { exportScriptTypes, importScriptTypes, ScriptTypeExportSkeleton, } from './ScriptTypeOps'; import { exportSecretStores, importSecretStores, SecretStoreExportSkeleton, } from './SecretStoreOps'; import { exportServices, importServices } from './ServiceOps'; import { exportThemes, importThemes, ThemeSkeleton } from './ThemeOps'; export type Config = { /** * Export full configuration * @param {FullExportOptions} options export options * @param {ResultCallback} resultCallback Optional callback to process individual results. A section that cannot be exported, also for lack of a scope of the credential, is reported to it as an error that names the section (code INSUFFICIENT_SCOPE for a missing scope) and the other sections are still exported; without a callback the error is thrown. A section that the deployment does not offer (PingOne Advanced Identity Cloud answers that the operation is not available) is skipped silently. * @returns {Promise} a promise resolving to a full export object */ exportFullConfiguration( options: FullExportOptions, resultCallback: ResultCallback ): Promise; /** * Import full configuration * @param {FullExportInterface} importData import data * @param {FullImportOptions} options import options * @param {ResultCallback} resultCallback Optional callback to process individual results. A section that cannot be imported, also for lack of a scope of the credential, is reported to it as an error that names the section (code INSUFFICIENT_SCOPE for a missing scope) and the other sections are still imported; without a callback the error is thrown. */ importFullConfiguration( importData: FullExportInterface, options: FullImportOptions, resultCallback: ResultCallback ): Promise<(object | any[])[]>; }; export default (state: State): Config => { return { async exportFullConfiguration( options: FullExportOptions = { useStringArrays: true, noDecode: false, coords: true, includeDefault: false, includeActiveValues: true, target: '', includeReadOnly: false, onlyRealm: false, onlyGlobal: false, onlyCustom: false, includeStatic: true, includeDynamic: true, }, resultCallback = void 0 ) { return exportFullConfiguration({ options, resultCallback, state }); }, async importFullConfiguration( importData: FullExportInterface, options: FullImportOptions = { reUuidJourneys: false, reUuidScripts: false, reUuidCustomNodes: false, cleanServices: false, includeDefault: false, includeActiveValues: true, onlyCustom: false, includeStatic: true, includeDynamic: true, }, resultCallback = void 0 ): Promise<(object | any[])[]> { return importFullConfiguration({ importData, options, resultCallback, state, }); }, }; }; /** * Full export options */ export interface FullExportOptions { /** * Use string arrays to store multi-line text in scripts. */ useStringArrays: boolean; /** * Do not include decoded variable value in export */ noDecode: boolean; /** * Include x and y coordinate positions of the journey/tree/workflow nodes. */ coords: boolean; /** * Include default scripts in export if true */ includeDefault: boolean; /** * Include active and loaded secret values */ includeActiveValues: boolean; /** * Host URL of target environment to encrypt secret values for */ target?: string; /** * Include read only config in export if true */ includeReadOnly: boolean; /** * Export config only for the current realm */ onlyRealm: boolean; /** * Export only global config */ onlyGlobal: boolean; /** * Include only custom request types in export if true. */ onlyCustom: boolean; /** * Include static configuration. Default: true. * * Static configuration is what an environment promotion carries from one * environment to the next: AM config entities, realms, script types, scripts, * journeys, authentication settings, services, secret stores, social identity * providers, themes, email templates, IDM config entities, mappings, and custom * nodes. * * Leaving both this and `includeDynamic` out (or passing `true` for both) * exports everything. Passing `false` for both exports nothing. */ includeStatic?: boolean; /** * Include dynamic configuration. Default: true. * * Dynamic configuration is what changes at run time in the environment where * it is made and is not promoted: servers, sites, agents and agent groups, * OAuth2 clients, trusted JWT issuers, CIMD profiles, SAML providers and * circles of trust, policies, policy sets, resource types, managed * applications, internal roles, ESV secrets and variables, telemetry, and the * IGA objects (certification templates, events, glossary schemas, request * forms and types, workflows). */ includeDynamic?: boolean; } /** * Full import options */ export interface FullImportOptions { /** * Generate new UUIDs for all journey nodes during import. */ reUuidJourneys: boolean; /** * Validate journeys before import. Defaults to true. Journeys are validated * as a batch: a validation error rejects the whole journeys section. */ validateJourneys?: boolean; /** * Generate new UUIDs for all scripts during import. */ reUuidScripts: boolean; /** * Generate new UUIDs and service names for all custom nodes during import. */ reUuidCustomNodes: boolean; /** * Indicates whether to remove previously existing services of the same id before importing */ cleanServices: boolean; /** * Include default scripts in import if true */ includeDefault: boolean; /** * Include active secret values */ includeActiveValues: boolean; /** * Host URL of source environment to decrypt secret values from */ source?: string; /** * Include only custom request types in import if true. * Note that non-custom request type imports will only modify the workflow ID as in the UI. */ onlyCustom: boolean; /** * Include static configuration. Default: true. * * Static configuration is what an environment promotion carries from one * environment to the next: AM config entities, realms, script types, scripts, * journeys, authentication settings, services, secret stores, social identity * providers, themes, email templates, IDM config entities, mappings, and custom * nodes. * * Leaving both this and `includeDynamic` out (or passing `true` for both) * imports everything. Passing `false` for both imports nothing. */ includeStatic?: boolean; /** * Include dynamic configuration. Default: true. * * Dynamic configuration is what changes at run time in the environment where * it is made and is not promoted: servers, sites, agents and agent groups, * OAuth2 clients, trusted JWT issuers, CIMD profiles, SAML providers and * circles of trust, policies, policy sets, resource types, managed * applications, internal roles, ESV secrets and variables, telemetry, and the * IGA objects (certification templates, events, glossary schemas, request * forms and types, workflows). */ includeDynamic?: boolean; } export interface FullExportInterface { meta?: ExportMetaData; global: FullGlobalExportInterface; realm: Record; } export interface FullGlobalExportInterface extends AmConfigEntitiesInterface { agent: Record | undefined; authentication: AuthenticationSettingsSkeleton | undefined; certificationTemplate: Record | undefined; emailTemplate: Record | undefined; event: Record | undefined; glossarySchema: Record> | undefined; idm: Record | undefined; internalRole: Record; mapping: Record | undefined; nodeTypes: Record | undefined; realm: Record | undefined; requestForm: Record | undefined; requestType: Record | undefined; scripttype: Record | undefined; secret: Record | undefined; secretstore: Record | undefined; server: ServerExportInterface | undefined; service: Record | undefined; site: Record | undefined; sync: SyncSkeleton | undefined; telemetry: TelemetryExporters | undefined; variable: Record | undefined; workflow: WorkflowGroups | undefined; } export interface FullRealmExportInterface extends AmConfigEntitiesInterface { agentGroup: Record | undefined; agent: Record | undefined; application: Record | undefined; authentication: AuthenticationSettingsSkeleton | undefined; /** * The CIMD profiles of the realm, keyed by id. The key is left out when the * realm has none, or does not offer the type. */ cimdProfile?: Record; idp: Record | undefined; managedApplication: Record | undefined; policy: Record | undefined; policyset: Record | undefined; resourcetype: Record | undefined; saml: | { hosted: Record; remote: Record; metadata: Record; cot: Record | undefined; } | undefined; script: Record | undefined; secretstore: Record | undefined; service: Record | undefined; theme: Record | undefined; trees: Record | undefined; trustedJwtIssuer: Record | undefined; } /** * Export full configuration * @param {FullExportOptions} options export options * @param {ResultCallback} resultCallback Optional callback to process individual results */ export async function exportFullConfiguration({ options = { useStringArrays: true, noDecode: false, coords: true, includeDefault: false, includeActiveValues: true, target: '', includeReadOnly: false, onlyRealm: false, onlyGlobal: false, onlyCustom: false, includeStatic: true, includeDynamic: true, }, resultCallback = void 0, state, }: { options: FullExportOptions; resultCallback: ResultCallback; state: State; }): Promise { const { useStringArrays, noDecode, coords, includeDefault, includeActiveValues, target, includeReadOnly, onlyRealm, onlyGlobal, onlyCustom, includeStatic = true, includeDynamic = true, } = options; const stateObj = { state }; const globalStateObj = { globalConfig: true, state }; const realmStateObj = { globalConfig: false, state }; const isClassicDeployment = state.getDeploymentType() === Constants.CLASSIC_DEPLOYMENT_TYPE_KEY; const isCloudDeployment = state.getDeploymentType() === Constants.CLOUD_DEPLOYMENT_TYPE_KEY; const isForgeOpsDeployment = state.getDeploymentType() === Constants.FORGEOPS_DEPLOYMENT_TYPE_KEY; const isIdmDeployment = isCloudDeployment || isForgeOpsDeployment; const isFullAmDeployment = isClassicDeployment || isForgeOpsDeployment; const errorCallback = getErrorCallback(resultCallback); const config = await exportWithErrorHandling( exportAmConfigEntities, { includeReadOnly, onlyRealm, onlyGlobal, resultCallback, state, }, 'AM Config Entities', resultCallback, includeStatic ); // export global config let globalConfig = {} as FullGlobalExportInterface; if (!onlyRealm || onlyGlobal) { // Export mappings const mappings = await exportWithErrorHandling( exportMappings, { options: { useStringArrays, deps: false, connectorId: undefined, moType: undefined, }, state, }, 'Mappings', resultCallback, isIdmDeployment && includeStatic ); // Export servers and server properties const serverExport = await exportWithErrorHandling( exportServers, { options: { includeDefault: true }, state }, 'Servers', resultCallback, isFullAmDeployment && includeDynamic ); if (serverExport) { delete serverExport.meta; } // Export global config globalConfig = { agent: ( await exportWithErrorHandling( exportAgents, globalStateObj, 'Global Agents', resultCallback, isFullAmDeployment && includeDynamic ) )?.agent, authentication: ( await exportWithErrorHandling( exportAuthenticationSettings, globalStateObj, 'Global Authentication Settings', resultCallback, isFullAmDeployment && includeStatic ) )?.authentication, certificationTemplate: ( await exportWithErrorHandling( exportCertificationTemplates, { options: { deps: false, // The event templates are exported with the events includeEventTemplates: false, }, state, }, 'Certification Templates', resultCallback, !!state.getIsIGA() && includeDynamic ) )?.certificationTemplate, emailTemplate: ( await exportWithErrorHandling( exportEmailTemplates, { includeDefault: includeReadOnly, state }, 'Email Templates', resultCallback, isIdmDeployment && includeStatic ) )?.emailTemplate, event: ( await exportWithErrorHandling( exportEvents, { options: { deps: false, }, state, }, 'Events', resultCallback, !!state.getIsIGA() && includeDynamic ) )?.event, glossarySchema: ( await exportWithErrorHandling( exportGlossarySchemas, { options: { includeInternal: includeReadOnly, }, state, }, 'Glossary Schemas', resultCallback, !!state.getIsIGA() && includeDynamic ) )?.glossarySchema, idm: ( await exportWithErrorHandling( exportConfigEntities, { options: { envReplaceParams: undefined, entitiesToExport: undefined, }, resultCallback: errorCallback, state, }, 'IDM Config Entities', resultCallback, isIdmDeployment && includeStatic ) )?.idm, internalRole: ( await exportWithErrorHandling( exportInternalRoles, stateObj, 'Internal Roles', resultCallback, isIdmDeployment && includeDynamic ) )?.internalRole, mapping: mappings?.mapping, nodeTypes: ( await exportWithErrorHandling( exportCustomNodes, { options: { useStringArrays, }, state, }, 'Custom Nodes', resultCallback, includeStatic ) )?.nodeTypes, realm: ( await exportWithErrorHandling( exportRealms, stateObj, 'Realms', resultCallback, (includeReadOnly || isFullAmDeployment) && includeStatic ) )?.realm, requestForm: ( await exportWithErrorHandling( exportRequestForms, { options: { deps: false, useStringArrays, }, resultCallback: errorCallback, state, }, 'Request Forms', resultCallback, !!state.getIsIGA() && includeDynamic ) )?.requestForm, requestType: ( await exportWithErrorHandling( exportRequestTypes, { options: { onlyCustom, useStringArrays, }, state, }, 'Request Types', resultCallback, !!state.getIsIGA() && includeDynamic ) )?.requestType, scripttype: ( await exportWithErrorHandling( exportScriptTypes, // with a callback each failed script type is reported by name and the // others are kept; without one every script type is tried and the // section fails with one combined error { resultCallback: resultCallback ? errorCallback : undefined, state }, 'Script Types', resultCallback, (includeReadOnly || isFullAmDeployment) && includeStatic ) )?.scripttype, secret: ( await exportWithErrorHandling( exportSecrets, { options: { includeActiveValues, target }, state }, 'ESV Secrets', resultCallback, isCloudDeployment && includeDynamic ) )?.secret, secretstore: ( await exportWithErrorHandling( exportSecretStores, globalStateObj, 'Global Secret Stores', resultCallback, isFullAmDeployment && includeStatic ) )?.secretstore, server: serverExport, service: ( await exportWithErrorHandling( exportServices, globalStateObj, 'Services', resultCallback, includeStatic ) )?.service, site: ( await exportWithErrorHandling( exportSites, stateObj, 'Sites', resultCallback, isFullAmDeployment && includeDynamic ) )?.site, sync: mappings?.sync, telemetry: ( await exportWithErrorHandling( exportTelemetry, stateObj, 'Telemetry', resultCallback, isCloudDeployment && includeDynamic ) )?.telemetry, variable: ( await exportWithErrorHandling( exportVariables, { noDecode, state, }, 'ESV Variables', resultCallback, isCloudDeployment && includeDynamic ) )?.variable, workflow: ( await exportWithErrorHandling( exportWorkflows, { options: { deps: false, useStringArrays, coords, includeReadOnly, }, resultCallback: errorCallback, state, }, 'Workflows', resultCallback, !!state.getIsIGA() && includeDynamic ) )?.workflow, ...config?.global, } as FullGlobalExportInterface; // Clean up duplicates if (globalConfig.idm) { Object.keys(globalConfig.idm) .filter( (k) => k === 'ui/themerealm' || k === 'sync' || k.startsWith('mapping/') || k.startsWith('emailTemplate/') ) .forEach((k) => delete globalConfig.idm[k]); } if (globalConfig.event && globalConfig.certificationTemplate) { const eventTemplateIds = new Set( Object.values(globalConfig.event) .map((e) => e.action?.template?.id) .filter((i) => i) ); const templateIds = Object.keys(globalConfig.certificationTemplate); for (const templateId of templateIds) { if (eventTemplateIds.has(templateId)) { delete globalConfig.certificationTemplate[templateId]; } } } } const realmConfig = {}; if (!onlyGlobal || onlyRealm) { // Export realm configs const activeRealm = state.getRealm(); // The realms to export are those of the AM config entities export. That // export is skipped when static configuration is not wanted, but the // realm-level dynamic configuration (OAuth2 clients, agents, policies, // SAML providers, ...) still needs its realms, so ask for them directly. const exportRealms = includeStatic ? Object.keys(config?.realm ?? {}) : includeDynamic ? ((await exportWithErrorHandling( getRealmsForExport, { state }, 'Realms', resultCallback )) ?? []) : []; // restore the realm also when an error leaves the loop (no result callback) try { for (const realm of exportRealms) { const currentRealm = getRealmUsingExportFormat(realm); if ( onlyRealm && (activeRealm.startsWith('/') ? activeRealm : '/' + activeRealm) !== currentRealm ) { continue; } state.setRealm(currentRealm); // Identity Cloud denies (403) the exports guarded by `requestable` in its root realm; the authorization // config (policies, policy sets, resource types) can be read there and is not guarded const requestable = !skipsDeniedRootRealmRequests({ realm: currentRealm, onlyRealm, state, }); // Export saml2 providers and circle of trusts let saml = ( (await exportWithErrorHandling( exportSaml2Providers, stateObj, 'SAML2 Providers', resultCallback, requestable && includeDynamic )) as CirclesOfTrustExportInterface )?.saml; const cotExport = await exportWithErrorHandling( exportCirclesOfTrust, stateObj, 'Circle of Trusts', resultCallback, requestable && includeDynamic ); if (saml) { saml.cot = cotExport?.saml.cot; } else { saml = cotExport?.saml; } // CIMD profiles have a module and an export key of their own, so the // generic agent export above does not carry them. The key is left out // when the realm has none or does not offer the type, which keeps // every export of a realm without profiles as it always was. // // CIMD profiles are dynamic configuration, so this step runs with // includeDynamic. Checked 2026-11-13 with a real promotion between the // development and production tenant of a promotion pair: the profile was // not carried and the promotion report never listed it // (https://github.com/rockcarver/frodo-lib/issues/1021). Repeat the // check when Ping publishes promotion documentation for PingAM 9.0. const cimdProfile = ( await exportWithErrorHandling( exportCIMDProfiles, stateObj, 'CIMD Profiles', resultCallback, requestable && includeDynamic ) )?.cimdProfile; realmConfig[realm] = { agentGroup: ( await exportWithErrorHandling( exportAgentGroups, stateObj, 'Agent Groups', resultCallback, requestable && includeDynamic ) )?.agentGroup, agent: ( await exportWithErrorHandling( exportAgents, realmStateObj, 'Agents', resultCallback, requestable && includeDynamic ) )?.agent, application: ( await exportWithErrorHandling( exportOAuth2Clients, { options: { deps: false, useStringArrays }, state, }, 'OAuth2 Client Applications', resultCallback, requestable && includeDynamic ) )?.application, authentication: ( await exportWithErrorHandling( exportAuthenticationSettings, realmStateObj, 'Authentication Settings', resultCallback, requestable && includeStatic ) )?.authentication, idp: ( await exportWithErrorHandling( exportSocialIdentityProviders, stateObj, 'Social Identity Providers', resultCallback, requestable && includeStatic ) )?.idp, trees: ( await exportWithErrorHandling( exportJourneys, { options: { deps: false, useStringArrays, coords, }, resultCallback: errorCallback, state, }, 'Journeys', resultCallback, requestable && includeStatic ) )?.trees, managedApplication: ( await exportWithErrorHandling( exportApplications, { options: { deps: false, useStringArrays }, state, }, 'Applications', resultCallback, isIdmDeployment && includeDynamic ) )?.managedApplication, policy: ( await exportWithErrorHandling( exportPolicies, { options: { deps: false, prereqs: false, useStringArrays }, state, }, 'Policies', resultCallback, includeDynamic ) )?.policy, policyset: ( await exportWithErrorHandling( exportPolicySets, { options: { deps: false, prereqs: false, useStringArrays }, state, }, 'Policy Sets', resultCallback, includeDynamic ) )?.policyset, resourcetype: ( await exportWithErrorHandling( exportResourceTypes, stateObj, 'Resource Types', resultCallback, includeDynamic ) )?.resourcetype, saml, script: ( await exportWithErrorHandling( exportScripts, { options: { deps: false, includeDefault, useStringArrays, }, resultCallback: errorCallback, state, }, 'Scripts', resultCallback, requestable && includeStatic ) )?.script, secretstore: ( await exportWithErrorHandling( exportSecretStores, realmStateObj, 'Secret Stores', resultCallback, requestable && includeStatic ) )?.secretstore, service: ( await exportWithErrorHandling( exportServices, realmStateObj, 'Services', resultCallback, requestable && includeStatic ) )?.service, theme: ( await exportWithErrorHandling( exportThemes, { state, }, 'Themes', resultCallback, isIdmDeployment && includeStatic ) )?.theme, trustedJwtIssuer: ( await exportWithErrorHandling( exportOAuth2TrustedJwtIssuers, { options: { deps: false, useStringArrays }, state, }, 'Trusted JWT Issuers', resultCallback, requestable && includeDynamic ) )?.trustedJwtIssuer, ...(cimdProfile && Object.keys(cimdProfile).length > 0 ? { cimdProfile } : {}), ...config?.realm[realm], }; //Clean up realm duplicates if ( realmConfig[realm].service && realmConfig[realm].service['SocialIdentityProviders'] ) { delete realmConfig[realm].service['SocialIdentityProviders'] .nextDescendents; } } } finally { state.setRealm(activeRealm); } } const fullConfig = { meta: getMetadata(stateObj), global: globalConfig as FullGlobalExportInterface, realm: realmConfig, }; return fullConfig; } /** * Import full configuration * @param {FullExportInterface} importData import data * @param {FullImportOptions} options import options * @param {ResultCallback} resultCallback Optional callback to process individual results */ export async function importFullConfiguration({ importData, options = { reUuidJourneys: false, reUuidScripts: false, reUuidCustomNodes: false, cleanServices: false, includeDefault: false, includeActiveValues: true, source: '', onlyCustom: false, includeStatic: true, includeDynamic: true, }, resultCallback = void 0, state, }: { importData: FullExportInterface; options: FullImportOptions; resultCallback: ResultCallback; state: State; }): Promise<(object | any[])[]> { let response: (object | any[])[] = []; const isClassicDeployment = state.getDeploymentType() === Constants.CLASSIC_DEPLOYMENT_TYPE_KEY; const isCloudDeployment = state.getDeploymentType() === Constants.CLOUD_DEPLOYMENT_TYPE_KEY; const isForgeOpsDeployment = state.getDeploymentType() === Constants.FORGEOPS_DEPLOYMENT_TYPE_KEY; const isIdmDeployment = isCloudDeployment || isForgeOpsDeployment; const isFullAmDeployment = isClassicDeployment || isForgeOpsDeployment; const { reUuidJourneys, validateJourneys, reUuidScripts, reUuidCustomNodes, cleanServices, includeDefault, includeActiveValues, source, onlyCustom, includeStatic = true, includeDynamic = true, } = options; const errorCallback = getErrorCallback(resultCallback); // Import to global let indicatorId = createProgressIndicator({ total: 22, message: `Importing everything for global...`, state, }); response.push( await importWithErrorHandling( importServers, { serverId: '', serverUrl: '', importData: importData.global.server, options: { includeDefault: true, }, state, }, indicatorId, 'Servers', resultCallback, isFullAmDeployment && includeDynamic && !!importData.global.server ) ); response.push( await importWithErrorHandling( importSites, { siteId: '', siteUrl: '', importData: importData.global, state, }, indicatorId, 'Sites', resultCallback, isFullAmDeployment && includeDynamic && !!importData.global.site ) ); response.push( await importWithErrorHandling( importRealms, { realmId: '', realmName: '', importData: importData.global, state, }, indicatorId, 'Realms', resultCallback, isFullAmDeployment && includeStatic && !!importData.global.realm ) ); response.push( await importWithErrorHandling( importCustomNodes, { nodeId: '', nodeName: '', importData: importData.global, options: { reUuid: reUuidCustomNodes, wait: false, }, resultCallback: errorCallback, state, }, indicatorId, 'Custom Nodes', resultCallback, !!importData.global.nodeTypes && includeStatic ) ); response.push( await importWithErrorHandling( importScriptTypes, { scriptTypeId: '', importData: importData.global, state, }, indicatorId, 'Script Types', resultCallback, isFullAmDeployment && includeStatic && !!importData.global.scripttype ) ); response.push( await importWithErrorHandling( importSecretStores, { importData: importData.global, globalConfig: true, secretStoreId: '', state, }, indicatorId, 'Secret Stores', resultCallback, isFullAmDeployment && includeStatic && !!importData.global.secretstore ) ); response.push( await importWithErrorHandling( importSecrets, { importData: importData.global, options: { includeActiveValues, source, }, state, }, indicatorId, 'Secrets', resultCallback, isCloudDeployment && includeDynamic && !!importData.global.secret ) ); response.push( await importWithErrorHandling( importVariables, { importData: importData.global, state, }, indicatorId, 'Variables', resultCallback, isCloudDeployment && includeDynamic && !!importData.global.variable ) ); response.push( await importWithErrorHandling( importConfigEntities, { importData: importData.global, options: { envReplaceParams: undefined, entitiesToImport: undefined, validate: false, }, resultCallback: errorCallback, state, }, indicatorId, 'IDM Config Entities', resultCallback, isIdmDeployment && includeStatic && !!importData.global.idm ) ); response.push( await importWithErrorHandling( importGlossarySchemas, { importData: importData.global, options: { includeInternal: false, }, resultCallback: errorCallback, state, }, indicatorId, 'Glossary Schemas', resultCallback, !!state.getIsIGA() && includeDynamic && !!importData.global.glossarySchema ) ); response.push( await importWithErrorHandling( importEmailTemplates, { importData: importData.global, state, }, indicatorId, 'Email Templates', resultCallback, isIdmDeployment && includeStatic && !!importData.global.emailTemplate ) ); response.push( await importWithErrorHandling( importMappings, { importData: importData.global, options: { deps: false }, state, }, indicatorId, 'Mappings', resultCallback, isIdmDeployment && includeStatic ) ); response.push( await importWithErrorHandling( importServices, { importData: importData.global, options: { clean: cleanServices, global: true, realm: false }, state, }, indicatorId, 'Services', resultCallback, !!importData.global.service && includeStatic ) ); response.push( await importWithErrorHandling( importAgents, { importData: importData.global, globalConfig: true, state }, indicatorId, 'Agents', resultCallback, isFullAmDeployment && includeDynamic && !!importData.global.agent ) ); response.push( await importWithErrorHandling( importAuthenticationSettings, { importData: importData.global, globalConfig: true, state, }, indicatorId, 'Authentication Settings', resultCallback, isFullAmDeployment && includeStatic && !!importData.global.authentication ) ); response.push( await importWithErrorHandling( importInternalRoles, { importData: importData.global, state, }, indicatorId, 'Internal Roles', resultCallback, isIdmDeployment && includeDynamic && !!importData.global.internalRole ) ); response.push( await importWithErrorHandling( importRequestTypes, { importData: importData.global, options: { onlyCustom, }, resultCallback: errorCallback, state, }, indicatorId, 'Request Types', resultCallback, !!state.getIsIGA() && includeDynamic && !!importData.global.requestType ) ); response.push( await importWithErrorHandling( importRequestForms, { importData: importData.global, options: { deps: false, }, resultCallback: errorCallback, state, }, indicatorId, 'Request Forms', resultCallback, !!state.getIsIGA() && includeDynamic && !!importData.global.requestForm ) ); response.push( await importWithErrorHandling( importCertificationTemplates, { importData: importData.global, options: { deps: false, }, resultCallback: errorCallback, state, }, indicatorId, 'Certification Templates', resultCallback, !!state.getIsIGA() && includeDynamic && !!importData.global.certificationTemplate ) ); response.push( await importWithErrorHandling( importWorkflows, { importData: importData.global, options: { deps: false }, resultCallback: errorCallback, state, }, indicatorId, 'Workflows', resultCallback, !!state.getIsIGA() && includeDynamic && !!importData.global.workflow ) ); response.push( await importWithErrorHandling( importEvents, { importData: importData.global, options: { deps: false, }, resultCallback: errorCallback, state, }, indicatorId, 'Events', resultCallback, !!state.getIsIGA() && includeDynamic && !!importData.global.event ) ); response.push( await importWithErrorHandling( importTelemetry, { importData: importData.global, state, }, indicatorId, 'Telemetry', resultCallback, isCloudDeployment && includeDynamic && !!importData.global.telemetry ) ); stopProgressIndicator({ id: indicatorId, message: 'Finished Importing Everything to global!', status: 'success', state, }); // Import to realms const currentRealm = state.getRealm(); // restore the realm also when an error leaves the loop (no result callback) try { for (const realm of Object.keys(importData.realm)) { state.setRealm(getRealmUsingExportFormat(realm)); // An object that a module owns (a trusted JWT issuer, a CIMD profile) is // written once, by its module, whichever section of the file holds it. // An export of 4.0.0 and later holds each issuer under `agent` and under // `trustedJwtIssuer`; an `agent` export of the 4.x line only under // `agent`. A CIMD profile that an export made before the module existed // holds under `agent` is written by the module as well, so a deployment // that does not offer the type is told once, in the same words as for // the `cimdProfile` section. const routing = routeAgentSection(importData.realm[realm]); for (const { id, key } of routing.skipped) { debugMessage({ message: `ConfigOps.importFullConfiguration: skipped the agent copy of ${id}: the ${key} section has it`, state, }); } indicatorId = createProgressIndicator({ total: 18, message: `Importing everything for ${realm} realm...`, state, }); // Order of imports matter here since we want dependencies to be imported first. For example, journeys depend on a lot of things, so they are last, and many things depend on scripts, so they are first. response.push( await importWithErrorHandling( importScripts, { scriptName: '', importData: importData.realm[realm], options: { deps: false, reUuid: reUuidScripts, includeDefault, }, validate: false, resultCallback: errorCallback, state, }, indicatorId, 'Scripts', resultCallback, includeStatic && !!importData.realm[realm].script ) ); response.push( await importWithErrorHandling( importThemes, { importData: importData.realm[realm], state, }, indicatorId, 'Themes', resultCallback, isIdmDeployment && includeStatic && !!importData.realm[realm].theme ) ); response.push( await importWithErrorHandling( importSecretStores, { importData: importData.realm[realm], globalConfig: false, secretStoreId: '', state, }, indicatorId, 'Secret Stores', resultCallback, includeStatic && !!importData.realm[realm].secretstore ) ); response.push( await importWithErrorHandling( importAgentGroups, { importData: importData.realm[realm], state }, indicatorId, 'Agent Groups', resultCallback, includeDynamic && !!importData.realm[realm].agentGroup ) ); response.push( await importWithErrorHandling( importAgents, { importData: { ...importData.realm[realm], agent: routing.agent }, globalConfig: false, state, }, indicatorId, 'Agents', resultCallback, includeDynamic && !!routing.agent ) ); response.push( await importWithErrorHandling( importResourceTypes, { importData: importData.realm[realm], state, }, indicatorId, 'Resource Types', resultCallback, includeDynamic && !!importData.realm[realm].resourcetype ) ); response.push( await importWithErrorHandling( importCirclesOfTrust, { importData: importData.realm[realm], state, }, indicatorId, 'Circles of Trust', resultCallback, includeDynamic && !!importData.realm[realm].saml && !!importData.realm[realm].saml.cot ) ); response.push( await importWithErrorHandling( importSaml2Providers, { importData: importData.realm[realm], options: { deps: false }, state, }, indicatorId, 'Saml2 Providers', resultCallback, includeDynamic && !!importData.realm[realm].saml ) ); response.push( await importWithErrorHandling( importSocialIdentityProviders, { importData: importData.realm[realm], options: { deps: false }, state, }, indicatorId, 'Social Identity Providers', resultCallback, includeStatic && !!importData.realm[realm].idp ) ); response.push( await importWithErrorHandling( importOAuth2Clients, { importData: importData.realm[realm], options: { deps: false }, state, }, indicatorId, 'OAuth2 Clients', resultCallback, includeDynamic && !!importData.realm[realm].application ) ); response.push( await importWithErrorHandling( importOAuth2TrustedJwtIssuers, { importData: { trustedJwtIssuer: routing.routed.trustedJwtIssuer, }, // only a callback of the caller makes the issuers items of their own, as for the journeys resultCallback: resultCallback ? errorCallback : undefined, state, }, indicatorId, 'Trusted JWT Issuers', resultCallback, includeDynamic && !!routing.routed.trustedJwtIssuer ) ); response.push( await importWithErrorHandling( importApplications, { importData: importData.realm[realm], options: { deps: false }, state, }, indicatorId, 'Applications', resultCallback, includeDynamic && isIdmDeployment && !!importData.realm[realm].managedApplication ) ); response.push( await importWithErrorHandling( importPolicySets, { importData: importData.realm[realm], options: { deps: false, prereqs: false }, state, }, indicatorId, 'Policy Sets', resultCallback, includeDynamic && !!importData.realm[realm].policyset ) ); response.push( await importWithErrorHandling( importPolicies, { importData: importData.realm[realm], options: { deps: false, prereqs: false }, state, }, indicatorId, 'Policies', resultCallback, includeDynamic && !!importData.realm[realm].policy ) ); response.push( await importWithErrorHandling( importJourneys, { importData: importData.realm[realm], options: { deps: false, reUuid: reUuidJourneys, validate: validateJourneys, }, // only a callback of the caller makes the journeys items of their own: the error callback of a caller // without one throws, which would turn the journeys into a batch that fails at its first invalid journey resultCallback: resultCallback ? errorCallback : undefined, state, }, indicatorId, 'Journeys', resultCallback, includeStatic && !!importData.realm[realm].trees ) ); response.push( await importWithErrorHandling( importServices, { importData: importData.realm[realm], options: { clean: cleanServices, global: false, realm: true }, state, }, indicatorId, 'Services', resultCallback, includeStatic && !!importData.realm[realm].service ) ); response.push( await importWithErrorHandling( importAuthenticationSettings, { importData: importData.realm[realm], globalConfig: false, state, }, indicatorId, 'Authentication Settings', resultCallback, includeStatic && !!importData.realm[realm].authentication ) ); // Last: a profile names scripts, journeys and policy sets of the realm // and the server refuses to write one that names a missing script or // journey. // // CIMD profiles are dynamic configuration, so this step runs with // includeDynamic (see the export step: a real promotion on 2026-11-13 did // not carry a profile and its report never listed it, // https://github.com/rockcarver/frodo-lib/issues/1021). Repeat the check // when Ping publishes promotion documentation for PingAM 9.0. response.push( await importWithErrorHandling( importCIMDProfiles, { importData: { cimdProfile: routing.routed.cimdProfile }, // only a callback of the caller makes the profiles items of their own, as for the journeys resultCallback: resultCallback ? errorCallback : undefined, state, }, indicatorId, 'CIMD Profiles', resultCallback, includeDynamic && !!routing.routed.cimdProfile ) ); stopProgressIndicator({ id: indicatorId, message: `Finished Importing Everything to ${realm} realm!`, status: 'success', state, }); } } finally { state.setRealm(currentRealm); } // Import everything else indicatorId = createProgressIndicator({ total: 1, message: `Importing all other AM config entities`, state, }); response.push( await importWithErrorHandling( importAmConfigEntities, { importData: importData as unknown as ConfigEntityExportInterface, resultCallback: errorCallback, state, }, indicatorId, 'Other AM Config Entities', resultCallback, includeStatic ) ); // Filter out any null or empty results response = response.filter( (o) => o && (!Array.isArray(o) || o.length > 0) && (!(o as ServerExportInterface).server || Object.keys((o as ServerExportInterface).server).length > 0) ); stopProgressIndicator({ id: indicatorId, message: `Finished Importing all other AM config entities!`, status: 'success', state, }); return response; }