-
Notifications
You must be signed in to change notification settings - Fork 237
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Display vulnerabilities summary table per target (#2568)
Closes #2487 Signed-off-by: Cintia Sanchez Garcia <[email protected]>
- Loading branch information
1 parent
d9e20de
commit 945fe47
Showing
4 changed files
with
157 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,3 +27,7 @@ | |
.badge:hover { | ||
text-decoration: none; | ||
} | ||
|
||
.summaryTable > :not(caption) > * > * { | ||
padding: 0.25rem 0.75rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import { filter, isEmpty, isNull, isUndefined } from 'lodash'; | ||
|
||
import { FixableVulnerabilitiesInReport, SecurityReport, SecurityReportResult, Vulnerability } from '../types'; | ||
import formatSecurityReport from './formatSecurityReport'; | ||
import sumObjectValues from './sumObjectValues'; | ||
|
||
const prepareFixableSummary = ( | ||
fixableVulnerabilities: SecurityReport | null | undefined | ||
): FixableVulnerabilitiesInReport => { | ||
let fixReport: FixableVulnerabilitiesInReport = { report: {}, summary: {}, total: 0 }; | ||
if (fixableVulnerabilities) { | ||
let allVulnerabilities: Vulnerability[] = []; | ||
Object.keys(fixableVulnerabilities).forEach((image: string) => { | ||
let vulnerabilitiesList: Vulnerability[] = []; | ||
fixableVulnerabilities[image].Results.forEach((targetReport: SecurityReportResult) => { | ||
if (targetReport.Vulnerabilities) { | ||
vulnerabilitiesList = [...vulnerabilitiesList, ...targetReport.Vulnerabilities]; | ||
allVulnerabilities = [...allVulnerabilities, ...targetReport.Vulnerabilities]; | ||
} | ||
}); | ||
const { summary } = formatSecurityReport(vulnerabilitiesList); | ||
const total = sumObjectValues(summary); | ||
fixReport.report[image] = { | ||
summary: summary, | ||
total: total, | ||
}; | ||
}); | ||
fixReport.summary = formatSecurityReport(allVulnerabilities).summary; | ||
fixReport.total = sumObjectValues(formatSecurityReport(allVulnerabilities).summary); | ||
} | ||
return fixReport; | ||
}; | ||
|
||
const filterFixableVulnerabilities = (currentReport: SecurityReport | null): SecurityReport | null => { | ||
if (isNull(currentReport)) return null; | ||
|
||
let tmpReport: SecurityReport = {}; | ||
Object.keys(currentReport).forEach((img: string) => { | ||
currentReport[img].Results.forEach((target: SecurityReportResult) => { | ||
let vulnerabilities: null | Vulnerability[] = []; | ||
const filteredVulnerabilities = filter( | ||
target.Vulnerabilities, | ||
(v: Vulnerability) => !isUndefined(v.FixedVersion) | ||
); | ||
vulnerabilities = isEmpty(target.Vulnerabilities) ? [] : filteredVulnerabilities; | ||
if (!isNull(vulnerabilities)) { | ||
if (isUndefined(tmpReport[img])) { | ||
tmpReport[img] = { Results: [{ ...target, Vulnerabilities: vulnerabilities }] }; | ||
} else { | ||
tmpReport[img].Results.push({ ...target, Vulnerabilities: vulnerabilities }); | ||
} | ||
} | ||
}); | ||
}); | ||
return tmpReport; | ||
}; | ||
|
||
export { filterFixableVulnerabilities, prepareFixableSummary }; |