diff --git a/package-lock.json b/package-lock.json index 81e6e2a21..96c68ff48 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "@rockcarver/frodo-lib", - "version": "2.3.1-0", + "version": "2.4.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@rockcarver/frodo-lib", - "version": "2.3.1-0", + "version": "2.4.0", "license": "MIT", "devDependencies": { "@jest/globals": "^29.0.1", diff --git a/package.json b/package.json index 138cece89..7e8263c55 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@rockcarver/frodo-lib", - "version": "2.3.1-0", + "version": "2.4.0", "type": "commonjs", "main": "./dist/index.js", "module": "./dist/index.mjs", diff --git a/src/ops/ApplicationOps.ts b/src/ops/ApplicationOps.ts index 6dd972207..5b4b6bb67 100644 --- a/src/ops/ApplicationOps.ts +++ b/src/ops/ApplicationOps.ts @@ -435,11 +435,18 @@ export function createApplicationExportTemplate({ } export function getRealmManagedApplication({ state }: { state: State }) { - let realmManagedOrg = 'application'; - if (state.getDeploymentType() === constants.CLOUD_DEPLOYMENT_TYPE_KEY) { - realmManagedOrg = `${getCurrentRealmName(state)}_application`; + let realmManagedApp = 'application'; + if ( + state.getDeploymentType() === constants.CLOUD_DEPLOYMENT_TYPE_KEY || + state.getUseRealmPrefixOnManagedObjects() === true + ) { + realmManagedApp = `${getCurrentRealmName(state)}_application`; + debugMessage({ + message: `DeploymentType === cloud or UseRealmPrefixOnManagedObjects is true, returning '${realmManagedApp}'`, + state: state, + }); } - return realmManagedOrg; + return realmManagedApp; } export async function createApplication({ diff --git a/src/ops/OrganizationOps.ts b/src/ops/OrganizationOps.ts index 6e4f56e05..7b71c4e99 100644 --- a/src/ops/OrganizationOps.ts +++ b/src/ops/OrganizationOps.ts @@ -2,6 +2,7 @@ import { IdObjectSkeletonInterface } from '../api/ApiTypes'; import { queryAllManagedObjectsByType } from '../api/ManagedObjectApi'; import Constants from '../shared/Constants'; import { State } from '../shared/State'; +import { debugMessage } from '../utils/Console'; import { FrodoError } from './FrodoError'; export type Organization = { @@ -53,8 +54,15 @@ export default (state: State): Organization => { */ export function getRealmManagedOrganization({ state }: { state: State }) { let realmManagedOrg = 'organization'; - if (state.getDeploymentType() === Constants.CLOUD_DEPLOYMENT_TYPE_KEY) { + if ( + state.getDeploymentType() === Constants.CLOUD_DEPLOYMENT_TYPE_KEY || + state.getUseRealmPrefixOnManagedObjects() === true + ) { realmManagedOrg = `${state.getRealm()}_organization`; + debugMessage({ + message: `DeploymentType === cloud or UseRealmPrefixOnManagedObjects is true, returning '${realmManagedOrg}'`, + state: state, + }); } return realmManagedOrg; } diff --git a/src/shared/State.ts b/src/shared/State.ts index 3fb21fb55..9d29fe6a1 100644 --- a/src/shared/State.ts +++ b/src/shared/State.ts @@ -43,6 +43,8 @@ export type State = { getPassword(): string; setRealm(realm: string): void; getRealm(): string; + setUseRealmPrefixOnManagedObjects(useRealmPrefixOnManagedObjects: boolean): void; + getUseRealmPrefixOnManagedObjects(): boolean; setDeploymentType(type: string): void; getDeploymentType(): string; setAdminClientId(type: string): void; @@ -207,6 +209,13 @@ export default (initialState: StateInterface): State => { return state.realm || process.env.FRODO_REALM; }, + setUseRealmPrefixOnManagedObjects(useRealmPrefixOnManagedObjects: boolean) { + state.useRealmPrefixOnManagedObjects = useRealmPrefixOnManagedObjects; + }, + getUseRealmPrefixOnManagedObjects() { + return state.useRealmPrefixOnManagedObjects || false; + }, + setDeploymentType(type: string) { state.deploymentType = type; }, @@ -500,6 +509,7 @@ export interface StateInterface { username?: string; password?: string; realm?: string; + useRealmPrefixOnManagedObjects?: boolean; deploymentType?: string; adminClientId?: string; adminClientRedirectUri?: string; diff --git a/src/utils/ForgeRockUtils.ts b/src/utils/ForgeRockUtils.ts index 0dd5d3212..2f18074ce 100644 --- a/src/utils/ForgeRockUtils.ts +++ b/src/utils/ForgeRockUtils.ts @@ -1,6 +1,7 @@ import { getRealms } from '../ops/RealmOps'; import Constants from '../shared/Constants'; import { State } from '../shared/State'; +import { debugMessage } from '../utils/Console'; export type FRUtils = { applyNameCollisionPolicy(name: string): string; @@ -211,8 +212,15 @@ export function getCurrentRealmManagedUser({ state: State; }): string { let realmManagedUser = 'user'; - if (state.getDeploymentType() === Constants.CLOUD_DEPLOYMENT_TYPE_KEY) { + if ( + state.getDeploymentType() === Constants.CLOUD_DEPLOYMENT_TYPE_KEY || + state.getUseRealmPrefixOnManagedObjects() === true + ) { realmManagedUser = `${getCurrentRealmName(state)}_user`; + debugMessage({ + message: `DeploymentType === cloud or UseRealmPrefixOnManagedObjects is true, returning '${realmManagedUser}'`, + state: state, + }); } return realmManagedUser; }