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

Commit

Permalink
Merge pull request #20 from JupiterOne/INT-11156-9
Browse files Browse the repository at this point in the history
INT-11156: add logger to application relationships step
  • Loading branch information
gastonyelmini authored Jul 3, 2024
2 parents 9af7f23 + 6800406 commit c9c367e
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
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,
);
}

0 comments on commit c9c367e

Please sign in to comment.