Skip to content

Commit

Permalink
feat(report): added path, platform, start and end times to HTML report (
Browse files Browse the repository at this point in the history
Checkmarx#3455)

Signed-off-by: Felipe Avelar <[email protected]>
  • Loading branch information
felipe-avelar authored May 28, 2021
1 parent 34b710e commit 9748012
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 6 deletions.
Binary file modified docs/img/html_report.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 5 additions & 2 deletions e2e/fixtures/E2E_CLI_032_RESULT.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
"MEDIUM": 3
},
"total_counter": 4,
"Start": "2021-05-01T09:00:00.0+01:00",
"End": "2021-05-01T09:00:00.0+01:00"
"start": "2021-05-01T09:00:00.0+01:00",
"end": "2021-05-01T09:00:00.0+01:00",
"paths": [
"fixtures/samples/terraform-single.tf"
]
}
7 changes: 5 additions & 2 deletions e2e/fixtures/E2E_CLI_033_RESULT.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
"MEDIUM": 3
},
"total_counter": 4,
"Start": "2021-05-01T09:00:00.0+01:00",
"End": "2021-05-01T09:00:00.0+01:00"
"start": "2021-05-01T09:00:00.0+01:00",
"end": "2021-05-01T09:00:00.0+01:00",
"paths": [
"fixtures/samples/terraform-single.tf"
]
}
5 changes: 3 additions & 2 deletions internal/console/scan.go
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ func scan(changedDefaultQueryPath bool) error {

elapsed := time.Since(scanStartTime)

summary := getSummary(t, results, scanStartTime, time.Now())
summary := getSummary(t, results, scanStartTime, time.Now(), path)

if err := resolveOutputs(&summary, files.Combine(), inspector.GetFailedQueries(), printer); err != nil {
log.Err(err)
Expand All @@ -613,7 +613,7 @@ func scan(changedDefaultQueryPath bool) error {
return nil
}

func getSummary(t *tracker.CITracker, results []model.Vulnerability, start, end time.Time) model.Summary {
func getSummary(t *tracker.CITracker, results []model.Vulnerability, start, end time.Time, scannedPaths []string) model.Summary {
counters := model.Counters{
ScannedFiles: t.FoundFiles,
ParsedFiles: t.ParsedFiles,
Expand All @@ -627,6 +627,7 @@ func getSummary(t *tracker.CITracker, results []model.Vulnerability, start, end
Start: start,
End: end,
}
summary.ScannedPaths = scannedPaths
return summary
}

Expand Down
1 change: 1 addition & 0 deletions pkg/model/summary.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ type Summary struct {
Queries VulnerableQuerySlice `json:"queries"`
SeveritySummary
Times
ScannedPaths []string `json:"paths"`
}

// CreateSummary creates a report for a single scan, based on its scanID
Expand Down
19 changes: 19 additions & 0 deletions pkg/report/html.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"path/filepath"
"strings"

"github.com/Checkmarx/kics/pkg/model"
"github.com/tdewolff/minify/v2"
minifyCSS "github.com/tdewolff/minify/v2/css"
minifyHtml "github.com/tdewolff/minify/v2/html"
Expand Down Expand Up @@ -66,6 +67,22 @@ func includeJS(name string) template.HTML {
return template.HTML("<script>" + jsMinified + "</script>") //nolint
}

func getPaths(paths []string) string {
return strings.Join(paths, ", ")
}

func getPlatforms(queries model.VulnerableQuerySlice) string {
platforms := make([]string, 0)
alreadyAdded := make(map[string]string)
for idx := range queries {
if _, ok := alreadyAdded[queries[idx].Platform]; !ok {
alreadyAdded[queries[idx].Platform] = ""
platforms = append(platforms, queries[idx].Platform)
}
}
return strings.Join(platforms, ", ")
}

// PrintHTMLReport creates a report file on HTML format
func PrintHTMLReport(path, filename string, body interface{}) error {
if !strings.HasSuffix(filename, ".html") {
Expand All @@ -75,6 +92,8 @@ func PrintHTMLReport(path, filename string, body interface{}) error {
templateFuncs["includeSVG"] = includeSVG
templateFuncs["includeCSS"] = includeCSS
templateFuncs["includeJS"] = includeJS
templateFuncs["getPaths"] = getPaths
templateFuncs["getPlatforms"] = getPlatforms

fullPath := filepath.Join(path, filename)
t := template.Must(template.New("report.tmpl").Funcs(templateFuncs).Parse(htmlTemplate))
Expand Down
13 changes: 13 additions & 0 deletions pkg/report/template/html/report.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,19 @@ body {
border: 1px solid #bebebe;
}

.run-info {
display: flex;
flex-wrap: wrap;
border: 1px solid #bebebe;
margin-top: 10px;
width: 50vw;
}

.run-info > span {
flex-basis: 50%;
text-align: center;
}

.counters {
display: flex;
flex-direction: row;
Expand Down
8 changes: 8 additions & 0 deletions pkg/report/template/html/report.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@
<body>
<div class="container">
<div class="report-header-footer"><span class="title">KICS <span>REPORT</span></span><span class="timestamp">{{ getCurrentTime }}</span><a href="https://www.kics.io/" target="_blank">KICS.IO</a></div>
<div class="run-info">
<span style="flex-basis:100%"><b>Scanned paths:</b> {{ getPaths .ScannedPaths }}</span>
<span style="flex-basis:100%"><b>Platforms:</b> {{ getPlatforms .Queries }}</span>
{{- with .Times -}}
<span><b>Start time:</b> {{ .Start.Format "15:04:05, Jan 02 2006" }}</span>
<span><b>End time:</b> {{ .End.Format "15:04:05, Jan 02 2006" }}</span>
{{- end}}
</div>
<h2 style="margin-top:41px" class="kics-orange">Vulnerabilities:</h2>
<div class="counters">
{{- with .SeveritySummary -}}
Expand Down

0 comments on commit 9748012

Please sign in to comment.