Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,37 +43,33 @@ private static void generateReport(FilePath reportsDir, ImageCheckResults result
FilePath imageResultDir = new FilePath(reportsDir, result.getImageName().replace(":", "."));
imageResultDir.mkdirs();

if (!result.getCves().isEmpty()) {
try (OutputStream outputStream = new FilePath(imageResultDir, CVES_FILENAME).write();
CSVPrinter printer = openCsv(outputStream, CVES_HEADER)) {
for (CVE cve : result.getCves()) {
printer.printRecord(nullIfEmpty(
cve.getPackageName(),
cve.getPackageVersion(),
cve.getId(),
cve.getSeverity(),
cve.isFixable(),
cve.getCvssScore(),
cve.getScoreType(),
cve.getLink()
));
}
try (OutputStream outputStream = new FilePath(imageResultDir, CVES_FILENAME).write();
CSVPrinter printer = openCsv(outputStream, CVES_HEADER)) {
for (CVE cve : result.getCves()) {
printer.printRecord(nullIfEmpty(
cve.getPackageName(),
cve.getPackageVersion(),
cve.getId(),
cve.getSeverity(),
cve.isFixable(),
cve.getCvssScore(),
cve.getScoreType(),
cve.getLink()
));
}
}

if (!result.getViolatedPolicies().isEmpty()) {
try (OutputStream outputStream = new FilePath(imageResultDir, POLICY_VIOLATIONS_FILENAME).write();
CSVPrinter printer = openCsv(outputStream, VIOLATED_POLICIES_HEADER)) {
for (PolicyViolation policy : result.getViolatedPolicies()) {
printer.printRecord(nullIfEmpty(
policy.getName(),
policy.getSeverity(),
policy.getDescription(),
policy.getViolations(),
prettyRemediation(policy.getRemediation()),
policy.isBuildEnforced() ? "X" : "-"
));
}
try (OutputStream outputStream = new FilePath(imageResultDir, POLICY_VIOLATIONS_FILENAME).write();
CSVPrinter printer = openCsv(outputStream, VIOLATED_POLICIES_HEADER)) {
for (PolicyViolation policy : result.getViolatedPolicies()) {
printer.printRecord(nullIfEmpty(
policy.getName(),
policy.getSeverity(),
policy.getDescription(),
policy.getViolations(),
prettyRemediation(policy.getRemediation()),
policy.isBuildEnforced() ? "X" : "-"
));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void testGenerateReportFroEmptyResultGeneratesNothing() throws IOException, Inte
}

@Test
void testGenerateReportFroEmptyCVSAndViolationsGeneratesEmptyDir() throws IOException, InterruptedException {
void testGenerateReportForEmptyCVSAndViolationsGeneratesEmptyFiles() throws IOException, InterruptedException {
FilePath reportsDir = new FilePath(folder.toFile());

ImmutableList<ImageCheckResults> results = ImmutableList.of(
Expand All @@ -66,7 +66,7 @@ void testGenerateReportFroEmptyCVSAndViolationsGeneratesEmptyDir() throws IOExce

List<String> actual = reportsDir.list().stream().map(FilePath::getName).collect(Collectors.toList());
assertEquals(ImmutableList.of("mis-spelled.lts"), actual);
assertTrue(reportsDir.child("mis-spelled.lts").list().isEmpty());
assertDirsAreEqual(Paths.get("src", "test", "resources", "report_with_no_issues"), folder);
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
COMPONENT,VERSION,CVE,FIXABLE,SEVERITY,CVSS SCORE,SCORE TYPE,LINK
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
POLICY,SEVERITY,DESCRIPTION,VIOLATION,REMEDIATION,ENFORCED