feat: k8s resource scanning (#2118)

This commit is contained in:
Jose Donizetti
2022-05-15 13:01:58 -03:00
committed by GitHub
parent f4ec4e7483
commit 3ef450d9a4
9 changed files with 207 additions and 47 deletions

View File

@@ -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
}