Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

INT-11156: add logger to application relationships step #20

Merged
merged 2 commits into from
Jul 3, 2024
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
7 changes: 7 additions & 0 deletions src/configuration-manager/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
buildLocalUserList,
} from './queries';
import pMap from 'p-map';
import { IntegrationLogger } from '@jupiterone/integration-sdk-core';

type ResourceIteratee<T> = (each: T) => Promise<void> | void;

Expand Down Expand Up @@ -96,6 +97,7 @@ class MicrosoftConfigurationManagerClient {
async listApplicationDeviceTargets<T>(
iteratee: ResourceIteratee<T>,
pageSize: number = 600,
logger: IntegrationLogger,
) {
let offset = 0;
let hasMoreRecords = true;
Expand All @@ -111,6 +113,9 @@ class MicrosoftConfigurationManagerClient {
);

const records = result.recordset;

logger.info(`Proccesed ${records.length} records from query`);

if (records.length > 0) {
await pMap(
records,
Expand Down Expand Up @@ -266,10 +271,12 @@ class MicrosoftConfigurationManagerClient {

private async wrapWithRequestFailedHandler<TResponse>(
fn: () => Promise<TResponse>,
logger?: IntegrationLogger,
) {
try {
return await fn();
} catch (err) {
logger?.error(`Received error from SQL query: ${err}`);
throw this.onRequestFailed(err);
}
}
Expand Down
30 changes: 16 additions & 14 deletions src/steps/applications/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,22 @@ export async function buildApplicationRelationships({
logger,
);

await client.listApplicationDeviceTargets(async (application: any) => {
const appID = createApplicationKey(application.CIGUID?.toString());
const deviceID = createDeviceKey(application.ResourceID?.toString());
const applicationEntity = await jobState.findEntity(appID);
const deviceEntity = await jobState.findEntity(deviceID);
if (applicationEntity && deviceEntity) {
const deviceApplicationRelationship = createDeviceApplicationRelationship(
deviceEntity,
applicationEntity,
);
await client.listApplicationDeviceTargets(
async (application: any) => {
const appID = createApplicationKey(application.CIGUID?.toString());
const deviceID = createDeviceKey(application.ResourceID?.toString());
const applicationEntity = await jobState.findEntity(appID);
const deviceEntity = await jobState.findEntity(deviceID);
if (applicationEntity && deviceEntity) {
const deviceApplicationRelationship =
createDeviceApplicationRelationship(deviceEntity, applicationEntity);

if (!jobState.hasKey(deviceApplicationRelationship._key)) {
await jobState.addRelationship(deviceApplicationRelationship);
if (!jobState.hasKey(deviceApplicationRelationship._key)) {
await jobState.addRelationship(deviceApplicationRelationship);
}
}
}
});
},
600,
logger,
);
}
Loading