Skip to content

Commit

Permalink
feat(finding-url): rendered the finding url for other products (#223)
Browse files Browse the repository at this point in the history
* feat(finding-url): rendered the finding url for other products

* fix(format): formatted code

* fic(url): supported inspector url

* fix(check): checked the arn split
  • Loading branch information
maira-samtek authored Jul 23, 2024
1 parent da07afd commit 185c3ae
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/libs/security-hub-lib.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export interface Resource {
Type: string;
}
export interface SecurityHubFinding {
id?: string;
title?: string;
region?: string;
accountAlias?: string;
Expand Down Expand Up @@ -135,6 +136,7 @@ export class SecurityHub {
): SecurityHubFinding {
if (!finding) return {};
return {
id: finding.Id,
title: finding.Title,
region: finding.Region,
accountAlias: this.accountAlias,
Expand Down
35 changes: 34 additions & 1 deletion src/macpro-security-hub-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,35 @@ export class SecurityHubJiraSync {
Table += `------------------------------------------------------------------------------------------------`;
return Table;
}
createSecurityHubFindingUrlThroughFilters(findingId: string) {
let region, accountId;

if (findingId.startsWith("arn:")) {
// Extract region and account ID from the ARN
const arnParts = findingId.split(":");
if (arnParts.length >= 5) {
region = arnParts[3];
accountId = arnParts[4];
} else {
return "Invalid URL";
}
} else {
// Extract region and account ID from the non-ARN format
const parts = findingId.split("/");
if (parts.length >= 3) {
region = parts[1];
accountId = parts[2];
} else {
return "Invalid URL";
}
}

const baseUrl = `https://${region}.console.aws.amazon.com/securityhub/home?region=${region}`;
const searchParam = `Id%3D%255Coperator%255C%253AEQUALS%255C%253A${findingId}`;
const url = `${baseUrl}#/findings?search=${searchParam}`;

return url;
}
createIssueBody(finding: SecurityHubFinding) {
const {
remediation: {
Expand All @@ -185,6 +213,7 @@ export class SecurityHubJiraSync {
Text: remediationText = "",
} = {},
} = {},
id = "",
title = "",
description = "",
accountAlias = "",
Expand Down Expand Up @@ -225,7 +254,11 @@ export class SecurityHubJiraSync {
${severity}
h2. SecurityHubFindingUrl:
${this.createSecurityHubFindingUrl(standardsControlArn)}
${
standardsControlArn
? this.createSecurityHubFindingUrl(standardsControlArn)
: this.createSecurityHubFindingUrlThroughFilters(id)
}
h2. Resources:
Following are the resources those were non-compliant at the time of the issue creation
Expand Down

0 comments on commit 185c3ae

Please sign in to comment.