Skip to content

Commit

Permalink
Merge pull request #245 from JupiterOne/APP-15195-handle-unformatted-…
Browse files Browse the repository at this point in the history
…uuids

APP-15195 - Format uuids so that they are uniform
  • Loading branch information
mknoedel committed May 14, 2024
2 parents 9e79bb7 + e89b217 commit dceddda
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions src/steps/agents/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,13 @@ export async function buildAgentRelationships(
await jobState.iterateEntities(
{ _type: Entities.ASSET._type },
async (assetEntity) => {
if (assetEntity.hasAgent && assetEntity.agentUuid) {
const agentId =
assetEntity.hasAgent && assetEntity.agentUuid
? formatToUUID(assetEntity.agentUuid as string)
: undefined;
if (agentId) {
const agentEntity = await jobState.findEntity(
generateEntityKey(
Entities.AGENT._type,
assetEntity.agentUuid as string,
),
generateEntityKey(Entities.AGENT._type, agentId),
);
if (agentEntity) {
await jobState.addRelationship(
Expand All @@ -90,7 +91,11 @@ export async function buildAgentRelationships(
);
} else {
logger.warn(
{ assetKey: assetEntity._key, agentUuid: assetEntity.agentUuid },
{
assetKey: assetEntity._key,
agentUuid: assetEntity.agentUuid,
formattedAgentId: agentId,
},
`Asset's host agent could not be found`,
);
}
Expand All @@ -99,6 +104,20 @@ export async function buildAgentRelationships(
);
}

function formatToUUID(input: string): string | undefined {
const cleanInput = input.replace(/-/g, ''); // Remove all hyphens
if (cleanInput.length === 32) {
// Check valid length
return `${cleanInput.slice(0, 8)}-${cleanInput.slice(
8,
12,
)}-${cleanInput.slice(12, 16)}-${cleanInput.slice(
16,
20,
)}-${cleanInput.slice(20)}`;
}
}

export const agentsSteps: Step<
IntegrationStepExecutionContext<IntegrationConfig>
>[] = [
Expand Down

0 comments on commit dceddda

Please sign in to comment.