Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(report): hide empty table when all secrets/license/misconfigs are ignored #7171

Merged
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
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 ""
}
simar7 marked this conversation as resolved.
Show resolved Hide resolved
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