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:
Teppei Fukuda
2021-06-08 18:03:24 +03:00
committed by GitHub
parent 097b8d4881
commit e362843705
16 changed files with 171 additions and 85 deletions

View File

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