-
Notifications
You must be signed in to change notification settings - Fork 1
/
table.go
62 lines (52 loc) · 1.44 KB
/
table.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package report
import (
"io"
"sync"
"golang.org/x/xerrors"
dbTypes "github.com/aquasecurity/trivy-db/pkg/types"
pkgReport "github.com/zhanglimao/trivy/pkg/report/table"
)
type TableWriter struct {
Report string
Output io.Writer
Severities []dbTypes.Severity
ColumnHeading []string
}
const (
NamespaceColumn = "Namespace"
ResourceColumn = "Resource"
VulnerabilitiesColumn = "Vulnerabilities"
MisconfigurationsColumn = "Misconfigurations"
SecretsColumn = "Secrets"
RbacAssessmentColumn = "RBAC Assessment"
InfraAssessmentColumn = "Kubernetes Infra Assessment"
)
func WorkloadColumns() []string {
return []string{VulnerabilitiesColumn, MisconfigurationsColumn, SecretsColumn}
}
func RoleColumns() []string {
return []string{RbacAssessmentColumn}
}
func InfraColumns() []string {
return []string{InfraAssessmentColumn}
}
func (tw TableWriter) Write(report Report) error {
switch tw.Report {
case allReport:
t := pkgReport.Writer{Output: tw.Output, Severities: tw.Severities, ShowMessageOnce: &sync.Once{}}
for _, r := range report.Resources {
if r.Report.Results.Failed() {
err := t.Write(r.Report)
if err != nil {
return err
}
}
}
case summaryReport:
writer := NewSummaryWriter(tw.Output, tw.Severities, tw.ColumnHeading)
return writer.Write(report)
default:
return xerrors.Errorf(`report %q not supported. Use "summary" or "all"`, tw.Report)
}
return nil
}