|
1 | 1 | import { SeverityCount } from '@Shared/types'
|
2 |
| -import { SeveritiesDTO } from './SecurityModal/types' |
3 |
| - |
4 |
| -export const getTotalSeverityCount = (severityCount: SeverityCount): number => { |
5 |
| - const totalCount = |
6 |
| - (severityCount.critical || 0) + |
7 |
| - (severityCount.high || 0) + |
8 |
| - (severityCount.medium || 0) + |
9 |
| - (severityCount.low || 0) + |
10 |
| - (severityCount.unknown || 0) |
11 |
| - return totalCount |
12 |
| -} |
13 |
| - |
14 |
| -export const getSeverityCountFromSummary = ( |
15 |
| - scanResultSeverities: Partial<Record<SeveritiesDTO, number>>, |
16 |
| -): SeverityCount => ({ |
17 |
| - critical: scanResultSeverities?.[SeveritiesDTO.CRITICAL] || 0, |
18 |
| - high: scanResultSeverities?.[SeveritiesDTO.HIGH] || 0, |
19 |
| - medium: scanResultSeverities?.[SeveritiesDTO.MEDIUM] || 0, |
20 |
| - low: scanResultSeverities?.[SeveritiesDTO.LOW] || 0, |
21 |
| - unknown: scanResultSeverities?.[SeveritiesDTO.UNKNOWN] || 0, |
22 |
| -}) |
| 2 | +import { SCAN_TOOL_ID_CLAIR, SCAN_TOOL_ID_TRIVY } from '@Shared/constants' |
| 3 | +import { ScanResultDTO, SeveritiesDTO } from './SecurityModal/types' |
23 | 4 |
|
24 | 5 | export const getCVEUrlFromCVEName = (cveName: string): string =>
|
25 | 6 | `https://cve.mitre.org/cgi-bin/cvename.cgi?name=${cveName}`
|
| 7 | + |
| 8 | +export const getScanToolAndSeverityCount = ( |
| 9 | + scanResult: ScanResultDTO, |
| 10 | +): { scanToolId: number; severityCount: SeverityCount; totalCount: number } => { |
| 11 | + const scanToolId = |
| 12 | + scanResult.imageScan?.vulnerability?.list?.[0].scanToolName === 'TRIVY' |
| 13 | + ? SCAN_TOOL_ID_TRIVY |
| 14 | + : SCAN_TOOL_ID_CLAIR |
| 15 | + |
| 16 | + const severities = scanResult.imageScan?.vulnerability?.summary?.severities |
| 17 | + |
| 18 | + const severityCount: SeverityCount = { |
| 19 | + critical: severities?.[SeveritiesDTO.CRITICAL] || 0, |
| 20 | + high: severities?.[SeveritiesDTO.HIGH] || 0, |
| 21 | + medium: severities?.[SeveritiesDTO.MEDIUM] || 0, |
| 22 | + low: severities?.[SeveritiesDTO.LOW] || 0, |
| 23 | + unknown: severities?.[SeveritiesDTO.UNKNOWN] || 0, |
| 24 | + } |
| 25 | + |
| 26 | + const totalCount = |
| 27 | + severityCount.critical + severityCount.high + severityCount.medium + severityCount.low + severityCount.unknown |
| 28 | + |
| 29 | + return { scanToolId, severityCount, totalCount } |
| 30 | +} |
0 commit comments