Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resolves #328 and fixes #331 #332

Merged
merged 3 commits into from
Oct 19, 2023
Merged
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
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/api/BaseApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ export function generateAmApi({

/**
* Generates an OAuth2 Axios API instance
* @param {object} resource Takes an object takes a resource object. example:
* @param {object} resource Takes a resource object. example:
* @param {object} requestOverride Takes an object of AXIOS parameters that can be used to either
* add on extra information or override default properties https://github.com/axios/axios#request-config
*
Expand Down
244 changes: 244 additions & 0 deletions src/api/ReconApi.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,244 @@
import util from 'util';

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

const apiVersion = 'resource=1.0';
const apiConfig = { headers: { 'Accept-API-Version': apiVersion } };

const reconUrlTemplate = '%s/openidm/recon';
const reconByIdUrlTemplate = '%s/openidm/recon/%s';
const startReconUrlTemplate = '%s/openidm/recon?_action=recon&mapping=%s';
const startReconByIdUrlTemplate =
'%s/openidm/recon?_action=reconById&mapping=%s&id=%s';
const cancelReconUrlTemplate = '%s/openidm/recon/%s?_action=cancel';

export type ReconType = IdObjectSkeletonInterface & {
mapping: string;
state: 'SUCCESS' | string;
stage: 'COMPLETED_SUCCESS' | string;
stageDescription: string;
progress: {
source: { existing: { processed: number; total: string } };
target: {
existing: { processed: number; total: string };
created: number;
unchanged: number;
updated: number;
deleted: number;
};
links: { existing: { processed: number; total: string }; created: number };
};
situationSummary: {
SOURCE_IGNORED: number;
TARGET_CHANGED: number;
SOURCE_TARGET_CONFLICT: number;
FOUND_ALREADY_LINKED: number;
UNQUALIFIED: number;
ABSENT: number;
TARGET_IGNORED: number;
MISSING: number;
ALL_GONE: number;
UNASSIGNED: number;
AMBIGUOUS: number;
CONFIRMED: number;
LINK_ONLY: number;
SOURCE_MISSING: number;
FOUND: number;
};
statusSummary: { SUCCESS: number; FAILURE: number };
durationSummary: {
sourceQuery: {
min: number;
max: number;
mean: number;
count: number;
sum: number;
stdDev: number;
};
auditLog: {
min: number;
max: number;
mean: number;
count: number;
sum: number;
stdDev: number;
};
defaultPropertyMapping: {
min: number;
max: number;
mean: number;
count: number;
sum: number;
stdDev: number;
};
sourceLinkQuery: {
min: number;
max: number;
mean: number;
count: number;
sum: number;
stdDev: number;
};
updateTargetObject: {
min: number;
max: number;
mean: number;
count: number;
sum: number;
stdDev: number;
};
propertyMappingScript: {
min: number;
max: number;
mean: number;
count: number;
sum: number;
stdDev: number;
};
updateLastSync: {
min: number;
max: number;
mean: number;
count: number;
sum: number;
stdDev: number;
};
targetObjectQuery: {
min: number;
max: number;
mean: number;
count: number;
sum: number;
stdDev: number;
};
sourcePhase: {
min: number;
max: number;
mean: number;
count: number;
sum: number;
stdDev: number;
};
};
parameters: {
sourceIds: [string];
sourceQuery: {
resourceName: string;
_queryFilter: string;
_fields: string;
};
targetQuery: {
resourceName: string;
queryFilter: string;
_fields: string;
};
};
started: string;
ended: string;
duration: number;
sourceProcessedByNode: object;
};

export type ReconStatusType = IdObjectSkeletonInterface & {
state: 'ACTIVE' | string;
action: 'cancel' | string;
status: 'INITIATED' | string;
};

export async function getRecons({
state,
}: {
state: State;
}): Promise<ReconType[]> {
const urlString = util.format(
reconUrlTemplate,
getHostBaseUrl(state.getHost())
);
const { data } = await generateIdmApi({
requestOverride: apiConfig,
state,
}).get(urlString);
return data;
}

export async function getRecon({
reconId,
state,
}: {
reconId: string;
state: State;
}): Promise<ReconType> {
const urlString = util.format(
reconByIdUrlTemplate,
getHostBaseUrl(state.getHost()),
reconId
);
const { data } = await generateIdmApi({
requestOverride: apiConfig,
state,
}).get(urlString);
return data;
}

export async function startRecon({
mappingName,
state,
}: {
mappingName: string;
state: State;
}): Promise<ReconStatusType> {
const urlString = util.format(
startReconUrlTemplate,
getHostBaseUrl(state.getHost()),
mappingName
);
const { data } = await generateIdmApi({
requestOverride: apiConfig,
state,
}).post(urlString);
return data;
}

export async function startReconById({
mappingName,
objectId,
state,
}: {
mappingName: string;
objectId: string;
state: State;
}): Promise<ReconStatusType> {
const urlString = util.format(
startReconByIdUrlTemplate,
getHostBaseUrl(state.getHost()),
mappingName,
objectId
);
const { data } = await generateIdmApi({
requestOverride: apiConfig,
state,
}).post(urlString);
return data;
}

export async function cancelRecon({
reconId,
state,
}: {
reconId: string;
state: State;
}): Promise<ReconStatusType> {
const urlString = util.format(
cancelReconUrlTemplate,
getHostBaseUrl(state.getHost()),
reconId
);
const { data } = await generateIdmApi({
requestOverride: apiConfig,
state,
}).post(urlString);
return data;
}
3 changes: 3 additions & 0 deletions src/lib/FrodoLib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import OrganizationOps, { Organization } from '../ops/OrganizationOps';
import PolicyOps, { Policy } from '../ops/PolicyOps';
import PolicySetOps, { PolicySet } from '../ops/PolicySetOps';
import RealmOps, { Realm } from '../ops/RealmOps';
import ReconOps, { Recon } from '../ops/ReconOps';
import ResourceTypeOps, { ResourceType } from '../ops/ResourceTypeOps';
import Saml2Ops, { Saml2 } from '../ops/Saml2Ops';
import ScriptOps, { Script } from '../ops/ScriptOps';
Expand Down Expand Up @@ -95,6 +96,7 @@ export type Frodo = {
managed: ManagedObject;
mapping: Mapping;
organization: Organization;
recon: Recon;
system: IdmSystem;
};

Expand Down Expand Up @@ -230,6 +232,7 @@ const FrodoLib = (config: StateInterface = {}): Frodo => {
managed: ManagedObjectOps(state),
mapping: MappingOps(state),
organization: OrganizationOps(state),
recon: ReconOps(state),
system: IdmSystemOps(state),
},

Expand Down
2 changes: 1 addition & 1 deletion src/ops/CirclesOfTrustOps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ export async function importCirclesOfTrust({
hasEntityId = true;
}
}
if (entityProviders.length || hasEntityId) {
if (entityProviders.length === 0 || hasEntityId) {
try {
response.push(await createCircleOfTrust({ cotId, cotData, state }));
} catch (createError) {
Expand Down
Loading