Skip to content

Commit

Permalink
Implement report conversion function; #136
Browse files Browse the repository at this point in the history
  • Loading branch information
robertauer committed Nov 21, 2024
1 parent c30624e commit a65c6e2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
25 changes: 22 additions & 3 deletions src/com/cloudogu/ces/cesbuildlib/Trivy.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ class Trivy implements Serializable {
private Docker docker
private String trivyVersion
private String trivyDirectory = ".trivy"
private String trivyReportFilenameWithoutExtension = trivyDirectory+"/trivyReport"

Trivy(script, Docker docker = new Docker(script), String trivyVersion = "0.57.1") {
this.script = script
Expand Down Expand Up @@ -63,8 +64,26 @@ class Trivy implements Serializable {
*
* @param format The format of the output file (@see TrivyScanFormat)
*/
void saveFormattedTrivyReport(String format = TrivyScanFormat.HTML) {
// TODO: DO NOT scan again! Take the trivyReportFile and convert its content
// See https://aquasecurity.github.io/trivy/v0.52/docs/references/configuration/cli/trivy_convert/
void saveFormattedTrivyReport(String format = TrivyScanFormat.HTML, String trivyReportFilename = "${script.env.WORKSPACE}/.trivy/trivyReport.json") {
String formatExtension
switch (format) {
case TrivyScanFormat.HTML:
formatExtension = "html"
// TODO: html is no standard convert format. Use a template!
case TrivyScanFormat.JSON:
// Result file is already in JSON format
return
case TrivyScanFormat.TABLE:
formatExtension = "table"
default:
// TODO: Do nothing? Throw exception? idk
break
}
docker.image("aquasec/trivy:${trivyVersion}")
.inside("-v ${script.env.WORKSPACE}/.trivy/.cache:/root/.cache/") {
script.sh(script: "trivy convert --format ${format} --output ${trivyReportFilenameWithoutExtension}.${formatExtension} ${trivyReportFilename}")
}

script.archiveArtifacts artifacts: "${trivyReportFilenameWithoutExtension}.${format}", allowEmptyArchive: true
}
}
4 changes: 2 additions & 2 deletions src/com/cloudogu/ces/cesbuildlib/TrivyScanFormat.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class TrivyScanFormat {
static String JSON = "json"

/**
* Output as plain text file.
* Output as table.
*/
static String PLAIN = "plain"
static String TABLE = "table"
}

0 comments on commit a65c6e2

Please sign in to comment.