Skip to content
Open
Show file tree
Hide file tree
Changes from 2 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
49 changes: 33 additions & 16 deletions src/api/BaseApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,15 @@ export function generateAmApi({
const requestConfig = mergeDeep(
{
// baseURL: `${storage.session.getTenant()}/json`,
...(!process.env.FRODO_MOCK && {
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(state.getAllowInsecureConnection()),
}),
timeout,
headers: {
...headers,
...state.getAuthenticationHeaderOverrides(),
},
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(state.getAllowInsecureConnection()),
proxy: getProxy(),
},
requestOverride
Expand Down Expand Up @@ -269,8 +271,10 @@ export function generateOauth2Api({
...headers,
...state.getAuthenticationHeaderOverrides(),
},
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(state.getAllowInsecureConnection()),
...(!process.env.FRODO_MOCK && {
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(state.getAllowInsecureConnection()),
}),
proxy: getProxy(),
};

Expand Down Expand Up @@ -313,8 +317,10 @@ export function generateIdmApi({
Authorization: `Bearer ${state.getBearerToken()}`,
}),
},
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(state.getAllowInsecureConnection()),
...(!process.env.FRODO_MOCK && {
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(state.getAllowInsecureConnection()),
}),
proxy: getProxy(),
},
requestOverride
Expand Down Expand Up @@ -358,8 +364,10 @@ export function generateLogKeysApi({
{
timeout,
headers,
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(state.getAllowInsecureConnection()),
...(!process.env.FRODO_MOCK && {
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(state.getAllowInsecureConnection()),
}),
proxy: getProxy(),
},
requestOverride
Expand Down Expand Up @@ -401,8 +409,10 @@ export function generateLogApi({
// baseURL: getTenantURL(storage.session.getTenant()),
timeout,
headers,
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(state.getAllowInsecureConnection()),
...(!process.env.FRODO_MOCK && {
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(state.getAllowInsecureConnection()),
}),
proxy: getProxy(),
},
requestOverride
Expand Down Expand Up @@ -452,8 +462,10 @@ export function generateEnvApi({
timeout,
headers,
...requestOverride,
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(state.getAllowInsecureConnection()),
...(!process.env.FRODO_MOCK && {
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(state.getAllowInsecureConnection()),
}),
proxy: getProxy(),
};

Expand Down Expand Up @@ -500,8 +512,10 @@ export function generateGovernanceApi({
timeout,
headers,
...requestOverride,
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(state.getAllowInsecureConnection()),
...(!process.env.FRODO_MOCK && {
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(state.getAllowInsecureConnection()),
}),
proxy: getProxy(),
};

Expand Down Expand Up @@ -541,8 +555,11 @@ export function generateReleaseApi({
'Content-Type': 'application/json',
},
...requestOverride,
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(false, false),
...(!process.env.FRODO_MOCK && {
httpAgent: getHttpAgent(),
httpsAgent: getHttpsAgent(false, false),
}),

proxy: getProxy(),
};

Expand Down
69 changes: 69 additions & 0 deletions src/api/FrConfigServiceObjectsApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import util from 'util';

import { State } from '../shared/State';
import { verboseMessage } from '../utils/Console';
import { getIdmBaseUrl } from '../utils/ForgeRockUtils';
import { IdObjectSkeletonInterface } from './ApiTypes';
import { generateIdmApi } from './BaseApi';

export interface ServiceObjectTypeSkeleton {
[objectType: string]: ServiceObjectEntry[];
}

export interface ServiceObjectEntry {
searchField: string;
searchValue: string;
fields: string[];
overrides?: Record<string, string>;
}

export type ServiceObjectSkeleton = IdObjectSkeletonInterface & {
username?: string;
mail?: string[];
name?: string;
givenName?: string[];
description?: string;
status?: string;
[key: string]: unknown;
};

export async function getServiceObject({
objectType,
objectEntry,
state,
}: {
objectType: string;
objectEntry: ServiceObjectEntry;
state: State;
}): Promise<ServiceObjectSkeleton> {
verboseMessage({
message: 'FrConfigServiceObjectApi getServiceObject start',
state: state,
});
const baseUrl = getIdmBaseUrl(state);
const queryFilter = encodeURIComponent(
`${objectEntry.searchField} eq "${objectEntry.searchValue}"`
);
const fields = objectEntry.fields.join(',');

const urlString = util.format(
'%s/managed/%s?_queryFilter=%s&_fields=%s',
baseUrl,
objectType,
queryFilter,
fields
);

const { data } = await generateIdmApi({
requestOverride: {},
state,
}).get(urlString);

if (data.resultCount != 1) {
throw new Error(
`Unexpected result from search: ${data.resultCount} entries found for ${objectType} - ${objectEntry.searchValue}`
);
}

return data.result[0] as ServiceObjectSkeleton;
}
4 changes: 3 additions & 1 deletion src/api/IdmConfigApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@ export async function getConfigEntities({
export async function getConfigEntitiesByType({
type,
state,
onlyVisibleTemplates,
}: {
type: string;
state: State;
onlyVisibleTemplates?: boolean;
}): Promise<PagedResult<NoIdObjectSkeletonInterface>> {
// Due to a bug (as of Ping IDM 7.5.0) with the query filter for email templates (it happens using both sw or co), in order to get all the email templates you need to use 'emailTemplat' instead.
if (type === EMAIL_TEMPLATE_TYPE) {
if (type === EMAIL_TEMPLATE_TYPE && !onlyVisibleTemplates) {
type = EMAIL_TEMPLATE_TYPE.substring(0, EMAIL_TEMPLATE_TYPE.length - 1);
}
const urlString = util.format(
Expand Down
62 changes: 62 additions & 0 deletions src/api/RawApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import util from 'util';

import { State } from '../shared/State';
import { getIdmBaseUrl } from '../utils/ForgeRockUtils';
import { generateAmApi, generateEnvApi, generateIdmApi } from './BaseApi';

const idmTemplate: string = '%s/%s';
const amTemplate: string = '%s/%s';
const envTemplate: string = '%s/environment/%s';

export async function restGetRawIdm({
state,
url,
}: {
state: State;
url: string;
}) {
const urlString = util.format(idmTemplate, getIdmBaseUrl(state), url);
const { data } = await generateIdmApi({ state }).get(urlString);

return data;
}

export async function restGetRawAm({
state,
url,
}: {
state: State;
url: string;
}) {
const urlString = util.format(amTemplate, state.getHost(), url);
const { data } = await generateAmApi({
resource: { apiVersion: 'protocol=2.1,resource=1.0' },
state,
}).get(urlString, { withCredentials: true });

return data;
}

export async function restGetRawEnv({
state,
url,
}: {
state: State;
url: string;
}) {
const urlString = util.format(
envTemplate,
state
.getHost()
.split('/')
.filter((_, i, a) => i !== a.length - 1)
.join('/'),
url
);
const { data } = await generateEnvApi({
resource: { apiVersion: 'protocol=2.1,resource=1.0' },
state,
}).get(urlString, { withCredentials: true });

return data;
}
35 changes: 35 additions & 0 deletions src/api/classic/SecretStoreApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,41 @@ export type SecretStoreMappingSkeleton = IdObjectSkeletonInterface & {
aliases: string[];
};

/**
* Get secret store
* @param {string} secretStoreId Secret store id
* @param {string} secretStoreTypeId Secret store type id
* @param {boolean} globalConfig true if the secret store is global, false otherwise. Default: false.
* @returns {Promise<SecretStoreMappingSkeleton>} a promise that resolves to an array of secret store mapping objects
*/
export async function getSecretStore({
secretStoreId,
secretStoreTypeId,
globalConfig = false,
state,
}: {
secretStoreId: string;
secretStoreTypeId: string;
globalConfig: boolean;
state: State;
}): Promise<PagedResult<SecretStoreMappingSkeleton>> {
const urlString = util.format(
secretStoreURLTemplate,
state.getHost(),
getRealmPathGlobal(globalConfig, state),
getConfigPath(globalConfig),
secretStoreTypeId,
secretStoreId
);
const { data } = await generateAmApi({
resource: getApiConfig(globalConfig),
state,
}).get(urlString, {
withCredentials: true,
});
return data;
}

/**
* Get all secret stores
* @param {boolean} globalConfig true if the secret store is global, false otherwise. Default: false.
Expand Down
10 changes: 10 additions & 0 deletions src/lib/FrodoLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ import ConnectionProfileOps, {
} from '../ops/ConnectionProfileOps';
import ConnectorOps, { Connector } from '../ops/ConnectorOps';
import EmailTemplateOps, { EmailTemplate } from '../ops/EmailTemplateOps';
import FrConfigServiceObjectsOps, {
FrConfigServiceObject,
} from '../ops/FrConfigServiceObjectsOps';
import IdmConfigOps, { IdmConfig } from '../ops/IdmConfigOps';
import IdmCryptoOps, { IdmCrypto } from '../ops/IdmCryptoOps';
import IdmScriptOps, { IdmScript } from '../ops/IdmScriptOps';
Expand All @@ -75,6 +78,7 @@ import OAuth2TrustedJwtIssuerOps, {
import OrganizationOps, { Organization } from '../ops/OrganizationOps';
import PolicyOps, { Policy } from '../ops/PolicyOps';
import PolicySetOps, { PolicySet } from '../ops/PolicySetOps';
import RawOps, { Raw } from '../ops/RawOps';
import RealmOps, { Realm } from '../ops/RealmOps';
import ReconOps, { Recon } from '../ops/ReconOps';
import ResourceTypeOps, { ResourceType } from '../ops/ResourceTypeOps';
Expand Down Expand Up @@ -182,6 +186,8 @@ export type Frodo = {
issuer: OAuth2TrustedJwtIssuer;
};

raw: Raw;

realm: Realm;

role: InternalRole;
Expand All @@ -196,6 +202,7 @@ export type Frodo = {
server: Server;
secretStore: SecretStore;
service: Service;
serviceObject: FrConfigServiceObject;
session: Session;
site: Site;

Expand Down Expand Up @@ -354,6 +361,8 @@ const FrodoLib = (config: StateInterface = {}): Frodo => {
issuer: OAuth2TrustedJwtIssuerOps(state),
},

raw: RawOps(state),

realm: RealmOps(state),

role: InternalRoleOps(state),
Expand All @@ -368,6 +377,7 @@ const FrodoLib = (config: StateInterface = {}): Frodo => {
server: ServerOps(state),
secretStore: SecretStoreOps(state),
service: ServiceOps(state),
serviceObject: FrConfigServiceObjectsOps(state),
session: SessionOps(state),
site: SiteOps(state),

Expand Down
2 changes: 2 additions & 0 deletions src/ops/AuthenticationSettingsOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ export async function exportAuthenticationSettings({
}
}

export async function exportAuthenticationSettingsForAllRealms() {}

/**
* Import authentication settings
* @param {AuthenticationSettingsExportInterface} importData import data
Expand Down
Loading
Loading