Skip to content

Commit

Permalink
fix(report): hide empty table when all secrets/license/misconfigs are…
Browse files Browse the repository at this point in the history
… ignored (#7171)

Co-authored-by: knqyf263 <[email protected]>
  • Loading branch information
DmitriyLewen and knqyf263 authored Jul 25, 2024
1 parent 7fa5e7d commit c3036de
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 6 deletions.
46 changes: 40 additions & 6 deletions pkg/report/table/licensing.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,12 @@ func NewPkgLicenseRenderer(result types.Result, isTerminal bool, severities []db
}

func (r pkgLicenseRenderer) Render() string {
// Trivy doesn't currently support showing suppressed licenses
// So just skip this result
if len(r.result.Licenses) == 0 {
return ""
}

r.setHeaders()
r.setRows()

Expand All @@ -54,7 +60,12 @@ func (r pkgLicenseRenderer) Render() string {
}

func (r pkgLicenseRenderer) setHeaders() {
header := []string{"Package", "License", "Classification", "Severity"}
header := []string{
"Package",
"License",
"Classification",
"Severity",
}
r.tableWriter.SetHeaders(header...)
}

Expand All @@ -63,11 +74,17 @@ func (r pkgLicenseRenderer) setRows() {
var row []string
if r.isTerminal {
row = []string{
l.PkgName, l.Name, colorizeLicenseCategory(l.Category), ColorizeSeverity(l.Severity, l.Severity),
l.PkgName,
l.Name,
colorizeLicenseCategory(l.Category),
ColorizeSeverity(l.Severity, l.Severity),
}
} else {
row = []string{
l.PkgName, l.Name, string(l.Category), l.Severity,
l.PkgName,
l.Name,
string(l.Category),
l.Severity,
}
}
r.tableWriter.AddRow(row...)
Expand Down Expand Up @@ -109,6 +126,12 @@ func NewFileLicenseRenderer(result types.Result, isTerminal bool, severities []d
}

func (r fileLicenseRenderer) Render() string {
// Trivy doesn't currently support showing suppressed licenses
// So just skip this result
if len(r.result.Licenses) == 0 {
return ""
}

r.setHeaders()
r.setRows()

Expand All @@ -124,7 +147,12 @@ func (r fileLicenseRenderer) Render() string {
}

func (r fileLicenseRenderer) setHeaders() {
header := []string{"Classification", "Severity", "License", "File Location"}
header := []string{
"Classification",
"Severity",
"License",
"File Location",
}
r.tableWriter.SetHeaders(header...)
}

Expand All @@ -148,11 +176,17 @@ func (r fileLicenseRenderer) setRows() {
var row []string
if r.isTerminal {
row = []string{
colorizeLicenseCategory(l.Category), ColorizeSeverity(l.Severity, l.Severity), l.Name, l.FilePath,
colorizeLicenseCategory(l.Category),
ColorizeSeverity(l.Severity, l.Severity),
l.Name,
l.FilePath,
}
} else {
row = []string{
string(l.Category), l.Severity, l.Name, l.FilePath,
string(l.Category),
l.Severity,
l.Name,
l.FilePath,
}
}
r.tableWriter.AddRow(row...)
Expand Down
5 changes: 5 additions & 0 deletions pkg/report/table/misconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ func NewMisconfigRenderer(result types.Result, severities []dbTypes.Severity, tr
}

func (r *misconfigRenderer) Render() string {
// Trivy doesn't currently support showing suppressed misconfigs
// So just skip this result
if len(r.result.Misconfigurations) == 0 {
return ""
}
target := fmt.Sprintf("%s (%s)", r.result.Target, r.result.Type)
RenderTarget(r.w, target, r.ansi)

Expand Down
5 changes: 5 additions & 0 deletions pkg/report/table/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ func NewSecretRenderer(target string, secrets []types.DetectedSecret, ansi bool,
}

func (r *secretRenderer) Render() string {
// Trivy doesn't currently support showing suppressed secrets
// So just skip this result
if len(r.secrets) == 0 {
return ""
}
target := r.target + " (secrets)"
RenderTarget(r.w, target, r.ansi)

Expand Down

0 comments on commit c3036de

Please sign in to comment.