Skip to content

Commit

Permalink
fix findings duplicate key (#70)
Browse files Browse the repository at this point in the history
Co-authored-by: Ronald Arias <ronald.arias@contractor.jupiterone.com>
  • Loading branch information
RonaldEAM and RonaldEAM committed Sep 4, 2023
1 parent 22307f7 commit 07434d3
Showing 1 changed file with 28 additions and 23 deletions.
51 changes: 28 additions & 23 deletions src/steps/findings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,32 +32,37 @@ export async function fetchVulnerabilities({
}

for (const comp of vuln.computers) {
const findingEntity = await jobState.addEntity(
createFindingEntity(vuln, cve, comp),
);
await jobState.addRelationship(
createDirectRelationship({
from: findingEntity,
to: vulnEntity,
_class: Relationships.FINDING_IS_VULNERABILITY._class,
}),
);
const findingEntity = createFindingEntity(vuln, cve, comp);
if (!jobState.hasKey(findingEntity._key)) {
await jobState.addEntity(findingEntity);
}

const compEntity = await jobState.findEntity(
`cisco-amp-endpoint:${comp.connector_guid}`,
);
if (compEntity) {
await jobState.addRelationship(
createDirectRelationship({
from: compEntity,
to: findingEntity,
_class: Relationships.COMPUTER_IDENTIFIED_FINDING._class,
}),
);
} else {
const findingVulnRelationship = createDirectRelationship({
_class: Relationships.FINDING_IS_VULNERABILITY._class,
from: findingEntity,
to: vulnEntity,
});
if (!jobState.hasKey(findingVulnRelationship._key)) {
await jobState.addRelationship(findingVulnRelationship);
}

const compEntityKey = `cisco-amp-endpoint:${comp.connector_guid}`;
if (!jobState.hasKey(compEntityKey)) {
logger.error(
`Computer Entity with key, cisco-amp-endpoint:${comp.connector_guid}, is missing from jobState.`,
);
continue;
}

const compFindingRelationship = createDirectRelationship({
_class: Relationships.COMPUTER_IDENTIFIED_FINDING._class,
fromKey: compEntityKey,
fromType: Entities.COMPUTER._type,
toKey: findingEntity._key,
toType: Entities.FINDING._type,
});
if (!jobState.hasKey(compFindingRelationship._key)) {
await jobState.addRelationship(compFindingRelationship);
}
}
}
Expand All @@ -66,7 +71,7 @@ export async function fetchVulnerabilities({

export const fetchFindingsSteps = [
{
id: 'fetch-findings',
id: Steps.FINDINGS,
name: 'Fetch Cisco AMP findings',
entities: [Entities.FINDING, Entities.VULNERABILITY],
relationships: [
Expand Down

0 comments on commit 07434d3

Please sign in to comment.