mirror of
https://github.com/aquasecurity/trivy.git
synced 2025-12-21 23:00:42 -08:00
BREAKING: migrate to a new JSON schema (#782)
* feat: introduce a new JSON schema * test: update * chore(mod): update fanal * refactor: add a comment * test(report): fix * refactor(writer): add omitempty * refactor: replace url * test(scanner): fix
This commit is contained in:
@@ -4,8 +4,11 @@ import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"github.com/aquasecurity/trivy/pkg/log"
|
||||
)
|
||||
|
||||
// JSONWriter implements result Writer
|
||||
@@ -14,8 +17,16 @@ type JSONWriter struct {
|
||||
}
|
||||
|
||||
// Write writes the results in JSON format
|
||||
func (jw JSONWriter) Write(results Results) error {
|
||||
output, err := json.MarshalIndent(results, "", " ")
|
||||
func (jw JSONWriter) Write(report Report) error {
|
||||
var v interface{} = report
|
||||
if os.Getenv("TRIVY_NEW_JSON_SCHEMA") == "" {
|
||||
// After migrating to the new JSON schema, TRIVY_NEW_JSON_SCHEMA will be removed.
|
||||
log.Logger.Warnf("DEPRECATED: the current JSON schema is deprecated, check %s for more information.",
|
||||
"https://github.com/aquasecurity/trivy/discussions/1050")
|
||||
v = report.Results
|
||||
}
|
||||
|
||||
output, err := json.MarshalIndent(v, "", " ")
|
||||
if err != nil {
|
||||
return xerrors.Errorf("failed to marshal json: %w", err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user