Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

APP-15195 - Format uuids so that they are uniform #245

Merged
merged 1 commit into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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