mirror of
https://github.com/LukeHagar/idn-admin-console.git
synced 2025-12-09 12:37:47 +00:00
Refactor SDK source queries
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
import { HandleError } from '$lib/Errors.js';
|
|
||||||
import { createConfiguration } from '$lib/sailpoint/sdk';
|
import { createConfiguration } from '$lib/sailpoint/sdk';
|
||||||
import { getToken } from '$lib/utils/oauth';
|
import { getToken } from '$lib/utils/oauth';
|
||||||
import { json } from '@sveltejs/kit';
|
import { json } from '@sveltejs/kit';
|
||||||
@@ -6,7 +5,6 @@ import { ManagedClustersBetaApi } from 'sailpoint-api-client';
|
|||||||
|
|
||||||
/** @type {import('./$types').RequestHandler} */
|
/** @type {import('./$types').RequestHandler} */
|
||||||
export async function GET({ cookies, params }) {
|
export async function GET({ cookies, params }) {
|
||||||
try {
|
|
||||||
// Generic SDK setup
|
// Generic SDK setup
|
||||||
const session = JSON.parse(cookies.get('session')!);
|
const session = JSON.parse(cookies.get('session')!);
|
||||||
const idnSession = await getToken(cookies);
|
const idnSession = await getToken(cookies);
|
||||||
@@ -19,7 +17,4 @@ export async function GET({ cookies, params }) {
|
|||||||
const val = await api.getManagedCluster({ id: params.clusterID });
|
const val = await api.getManagedCluster({ id: params.clusterID });
|
||||||
// console.log(val);
|
// console.log(val);
|
||||||
return json(val.data);
|
return json(val.data);
|
||||||
} catch (err) {
|
|
||||||
HandleError('issue arose during SDK source query', err);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +0,0 @@
|
|||||||
import { HandleError } from '$lib/Errors.js';
|
|
||||||
import { createConfiguration } from '$lib/sailpoint/sdk';
|
|
||||||
import { getToken } from '$lib/utils/oauth';
|
|
||||||
import { json } from '@sveltejs/kit';
|
|
||||||
import { IdentitiesBetaApi } from 'sailpoint-api-client';
|
|
||||||
|
|
||||||
/** @type {import('./$types').RequestHandler} */
|
|
||||||
export async function GET({ cookies, params }) {
|
|
||||||
try {
|
|
||||||
const session = JSON.parse(cookies.get('session')!);
|
|
||||||
const idnSession = await getToken(cookies);
|
|
||||||
|
|
||||||
const config = createConfiguration(session.baseUrl, idnSession.access_token);
|
|
||||||
const api = new IdentitiesBetaApi(config);
|
|
||||||
|
|
||||||
const val = await api.getIdentity({ id: params.identityID });
|
|
||||||
// console.log(val);
|
|
||||||
return json(val.data);
|
|
||||||
} catch (err) {
|
|
||||||
HandleError('issue arose during SDK source query', err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
import { HandleError } from '$lib/Errors.js';
|
|
||||||
import { createConfiguration } from '$lib/sailpoint/sdk';
|
|
||||||
import { getToken } from '$lib/utils/oauth';
|
|
||||||
import { json } from '@sveltejs/kit';
|
|
||||||
import { Paginator, SearchApi, type Search } from 'sailpoint-api-client';
|
|
||||||
|
|
||||||
/** @type {import('./$types').RequestHandler} */
|
|
||||||
export async function POST({ request, cookies }) {
|
|
||||||
try {
|
|
||||||
const session = JSON.parse(cookies.get('session')!);
|
|
||||||
const idnSession = await getToken(cookies);
|
|
||||||
const searchJson = await request.json();
|
|
||||||
|
|
||||||
const config = createConfiguration(session.baseUrl, idnSession.access_token);
|
|
||||||
const api = new SearchApi(config);
|
|
||||||
const search: Search = searchJson;
|
|
||||||
const val = (await Paginator.paginateSearchApi(api, search, 100, 20000)).data;
|
|
||||||
//console.log(val)
|
|
||||||
return json(val);
|
|
||||||
} catch (err) {
|
|
||||||
HandleError('issue arose during SDK search query', err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,26 +0,0 @@
|
|||||||
import { HandleError } from '$lib/Errors.js';
|
|
||||||
import { createConfiguration } from '$lib/sailpoint/sdk';
|
|
||||||
import { getToken } from '$lib/utils/oauth';
|
|
||||||
import { json } from '@sveltejs/kit';
|
|
||||||
import { Paginator, SearchApi, type Search } from 'sailpoint-api-client';
|
|
||||||
|
|
||||||
/** @type {import('./$types').RequestHandler} */
|
|
||||||
export async function POST({ request, cookies, params }) {
|
|
||||||
try {
|
|
||||||
const session = JSON.parse(cookies.get('session')!);
|
|
||||||
const idnSession = await getToken(cookies);
|
|
||||||
const searchJson = await request.json();
|
|
||||||
|
|
||||||
const limit = Number(params.limit || 20000);
|
|
||||||
const increment = limit < 250 ? limit : 250;
|
|
||||||
|
|
||||||
const config = createConfiguration(session.baseUrl, idnSession.access_token);
|
|
||||||
const api = new SearchApi(config);
|
|
||||||
const search: Search = searchJson;
|
|
||||||
const val = (await Paginator.paginateSearchApi(api, search, increment, limit)).data;
|
|
||||||
//console.log(val)
|
|
||||||
return json(val);
|
|
||||||
} catch (err) {
|
|
||||||
HandleError('issue arose during SDK search query', err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
import { HandleError } from '$lib/Errors.js';
|
|
||||||
import { createConfiguration } from '$lib/sailpoint/sdk';
|
|
||||||
import { getToken } from '$lib/utils/oauth';
|
|
||||||
import { json } from '@sveltejs/kit';
|
|
||||||
import { SourcesApi } from 'sailpoint-api-client';
|
|
||||||
|
|
||||||
/** @type {import('./$types').RequestHandler} */
|
|
||||||
export async function GET({ cookies, params }) {
|
|
||||||
try {
|
|
||||||
const session = JSON.parse(cookies.get('session')!);
|
|
||||||
const idnSession = await getToken(cookies);
|
|
||||||
|
|
||||||
const config = createConfiguration(session.baseUrl, idnSession.access_token);
|
|
||||||
const api = new SourcesApi(config);
|
|
||||||
|
|
||||||
const val = await api.getSource({ id: params.sourceID });
|
|
||||||
// console.log(val);
|
|
||||||
return json(val.data);
|
|
||||||
} catch (err) {
|
|
||||||
HandleError('issue arose during SDK source query', err);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
import type { Data, FetchResponse, SourceEvents } from '$lib/Types.js';
|
|
||||||
import { json } from '@sveltejs/kit';
|
|
||||||
import type { EventDocument, Search, SearchDocument } from 'sailpoint-api-client';
|
|
||||||
|
|
||||||
export const GET = async ({ fetch, params }) => {
|
|
||||||
const source = await (await fetch(`/api/sailpoint/source/${params.sourceID}`)).json();
|
|
||||||
|
|
||||||
const eventNames: string[] = [
|
|
||||||
'Aggregate Source Account Passed',
|
|
||||||
'Aggregate Source Account Started',
|
|
||||||
'Aggregate Source Entitlement Passed',
|
|
||||||
'Aggregate Source Entitlement Started',
|
|
||||||
];
|
|
||||||
|
|
||||||
const promises = [];
|
|
||||||
const allEvents: EventDocument[] = [];
|
|
||||||
|
|
||||||
for (const event of eventNames) {
|
|
||||||
const search: Search = {
|
|
||||||
indices: ['events'],
|
|
||||||
query: {
|
|
||||||
query: `target.name: "${source.name}" AND name:"${event}"`,
|
|
||||||
},
|
|
||||||
sort: ['created'],
|
|
||||||
};
|
|
||||||
|
|
||||||
promises.push(
|
|
||||||
fetch('/api/sailpoint/search/1', {
|
|
||||||
method: 'POST',
|
|
||||||
body: JSON.stringify(search),
|
|
||||||
})
|
|
||||||
.then((response: FetchResponse<SearchDocument>) => response.json())
|
|
||||||
.then((data: Data<SearchDocument>) => {
|
|
||||||
return data;
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
await Promise.allSettled(promises).then((results) => {
|
|
||||||
for (const event of results) {
|
|
||||||
if (event.status == 'fulfilled' && event.value.length > 0) {
|
|
||||||
allEvents.push(event.value[0]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
const sourceEvents: SourceEvents = {
|
|
||||||
name: source.name,
|
|
||||||
accounts: { started: undefined, passed: undefined },
|
|
||||||
entitlements: { started: undefined, passed: undefined },
|
|
||||||
};
|
|
||||||
|
|
||||||
for (const event of allEvents) {
|
|
||||||
if (event.attributes!.sourceName === source.name) {
|
|
||||||
switch (event.technicalName) {
|
|
||||||
case 'SOURCE_ACCOUNT_AGGREGATE_STARTED':
|
|
||||||
if (!sourceEvents.accounts.started) {
|
|
||||||
sourceEvents.accounts.started = event || undefined;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'SOURCE_ACCOUNT_AGGREGATE_PASSED':
|
|
||||||
if (!sourceEvents.accounts.passed) {
|
|
||||||
sourceEvents.accounts.passed = event || undefined;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'SOURCE_ENTITLEMENT_AGGREGATE_STARTED':
|
|
||||||
if (!sourceEvents.entitlements.started) {
|
|
||||||
sourceEvents.entitlements.started = event || undefined;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case 'SOURCE_ENTITLEMENT_AGGREGATE_PASSED':
|
|
||||||
if (!sourceEvents.entitlements.passed) {
|
|
||||||
sourceEvents.entitlements.passed = event || undefined;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return json({ source, sourceEvents });
|
|
||||||
};
|
|
||||||
Reference in New Issue
Block a user