github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/compliance/report/table.go (about) 1 package report 2 3 import ( 4 "io" 5 "sync" 6 7 "golang.org/x/xerrors" 8 9 dbTypes "github.com/aquasecurity/trivy-db/pkg/types" 10 pkgReport "github.com/devseccon/trivy/pkg/report/table" 11 "github.com/devseccon/trivy/pkg/types" 12 ) 13 14 type TableWriter struct { 15 Report string 16 Output io.Writer 17 Severities []dbTypes.Severity 18 ColumnHeading []string 19 } 20 21 const ( 22 ControlIDColumn = "ID" 23 SeverityColumn = "Severity" 24 ControlNameColumn = "Control Name" 25 StatusColumn = "Status" 26 IssuesColumn = "Issues" 27 ) 28 29 func (tw TableWriter) Write(report *ComplianceReport) error { 30 switch tw.Report { 31 case allReport: 32 t := pkgReport.Writer{ 33 Output: tw.Output, 34 Severities: tw.Severities, 35 ShowMessageOnce: &sync.Once{}, 36 } 37 for _, cr := range report.Results { 38 r := types.Report{Results: cr.Results} 39 err := t.Write(r) 40 if err != nil { 41 return err 42 } 43 } 44 case summaryReport: 45 writer := NewSummaryWriter(tw.Output) 46 return writer.Write(report) 47 default: 48 return xerrors.Errorf(`report %q not supported. Use "summary" or "all"`, tw.Report) 49 } 50 51 return nil 52 }