mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-22 15:16:33 -08:00
* feat: cyclonedx kbom support Signed-off-by: chenk <hen.keinan@gmail.com> * feat: cyclonedx kbom support Signed-off-by: chenk <hen.keinan@gmail.com> * feat: kubernetes bill of materials Signed-off-by: chenk <hen.keinan@gmail.com> * feat: kubernetes bill of materials Signed-off-by: chenk <hen.keinan@gmail.com> * feat: kubernetes bill of materials Signed-off-by: chenk <hen.keinan@gmail.com> * feat: kubernetes bill of materials Signed-off-by: chenk <hen.keinan@gmail.com> * feat: kubernetes bill of materials Signed-off-by: chenk <hen.keinan@gmail.com> * feat: kubernetes bill of materials Signed-off-by: chenk <hen.keinan@gmail.com> * chore: update sum db Signed-off-by: chenk <hen.keinan@gmail.com> * chore: update sum db Signed-off-by: chenk <hen.keinan@gmail.com> * feat: kubernetes bill of materials Signed-off-by: chenk <hen.keinan@gmail.com> * feat: kubernetes bill of materials Signed-off-by: chenk <hen.keinan@gmail.com> * chore: update sumdb Signed-off-by: chenk <hen.keinan@gmail.com> * chore: update sumdb Signed-off-by: chenk <hen.keinan@gmail.com> * feat: kubernetes bill of materials Signed-off-by: chenk <hen.keinan@gmail.com> * feat: kubernetes bill of materials Signed-off-by: chenk <hen.keinan@gmail.com> --------- Signed-off-by: chenk <hen.keinan@gmail.com>
41 lines
851 B
Go
41 lines
851 B
Go
package report
|
|
|
|
import (
|
|
"encoding/json"
|
|
"fmt"
|
|
"io"
|
|
|
|
"golang.org/x/xerrors"
|
|
)
|
|
|
|
type JSONWriter struct {
|
|
Output io.Writer
|
|
Report string
|
|
}
|
|
|
|
// Write writes the results in JSON format
|
|
func (jw JSONWriter) Write(report Report) error {
|
|
var output []byte
|
|
var err error
|
|
|
|
switch jw.Report {
|
|
case AllReport:
|
|
output, err = json.MarshalIndent(report, "", " ")
|
|
if err != nil {
|
|
return xerrors.Errorf("failed to write json: %w", err)
|
|
}
|
|
case SummaryReport:
|
|
output, err = json.MarshalIndent(report.consolidate(), "", " ")
|
|
if err != nil {
|
|
return xerrors.Errorf("failed to write json: %w", err)
|
|
}
|
|
default:
|
|
return xerrors.Errorf(`report %q not supported. Use "summary" or "all"`, jw.Report)
|
|
}
|
|
if _, err = fmt.Fprintln(jw.Output, string(output)); err != nil {
|
|
return xerrors.Errorf("failed to write json: %w", err)
|
|
}
|
|
|
|
return nil
|
|
}
|