mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-23 07:29:00 -08:00
feat: k8s resource scanning (#2118)
This commit is contained in:
@@ -10,11 +10,23 @@ import (
|
||||
|
||||
type JSONWriter struct {
|
||||
Output io.Writer
|
||||
Report string
|
||||
}
|
||||
|
||||
// Write writes the results in JSON format
|
||||
func (jw JSONWriter) Write(report Report) error {
|
||||
output, err := json.MarshalIndent(report, "", " ")
|
||||
var output []byte
|
||||
var err error
|
||||
|
||||
switch jw.Report {
|
||||
case allReport:
|
||||
output, err = json.MarshalIndent(report, "", " ")
|
||||
case summaryReport:
|
||||
output, err = json.MarshalIndent(report.consolidate(), "", " ")
|
||||
default:
|
||||
err = fmt.Errorf("report %s not supported", jw.Report)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to marshal json: %w", err)
|
||||
}
|
||||
@@ -22,5 +34,6 @@ func (jw JSONWriter) Write(report Report) error {
|
||||
if _, err = fmt.Fprintln(jw.Output, string(output)); err != nil {
|
||||
return xerrors.Errorf("failed to write json: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user