Skip to content

Commit

Permalink
Simplify SLA logic
Browse files Browse the repository at this point in the history
  • Loading branch information
marsavar committed Jul 4, 2024
1 parent 9f1880a commit 0edf2b3
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions packages/cloudbuster/src/findings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,27 +4,21 @@ import type { Digest, Finding, SecurityHubSeverity } from './types';
/**
* Determines whether a Security Hub finding is within the SLA window
*/
function isWithinSlaTime(finding: aws_securityhub_findings): boolean {
if (!finding.first_observed_at) {
function isWithinSlaTime(
firstObservedAt: Date | null,
severity: SecurityHubSeverity | null,
): boolean {
if (!firstObservedAt || !severity) {
return false;
}

const today = new Date();
const timeDifference = today.getTime() - finding.first_observed_at.getTime();
const timeDifference = today.getTime() - firstObservedAt.getTime();
const dayDifference = timeDifference / (1000 * 60 * 60 * 24);

const isWithinTwoDays = Math.abs(dayDifference) <= 2;
const isWithinThirtyDays = Math.abs(dayDifference) <= 30;

let severity;
if (
finding.severity &&
typeof finding.severity === 'object' &&
'Label' in finding.severity
) {
severity = finding.severity['Label'];
}

return (
(severity === 'CRITICAL' && isWithinTwoDays) ||
(severity === 'HIGH' && isWithinThirtyDays)
Expand Down Expand Up @@ -86,7 +80,7 @@ function transformFinding(finding: aws_securityhub_findings): Finding {
priority,
remediationUrl: remediationUrl,
firstObservedAt: finding.first_observed_at,
isWithinSla: isWithinSlaTime(finding),
isWithinSla: isWithinSlaTime(finding.first_observed_at, severity),
};
}

Expand Down

0 comments on commit 0edf2b3

Please sign in to comment.