syft/syft/presenter/json/document.go
Alfredo Deza 1e79986188 json: update the document to include distro information
Signed-off-by: Alfredo Deza <adeza@anchore.com>
2020-11-09 12:16:00 -05:00

50 lines
1.0 KiB
Go

package json
import (
"github.com/anchore/syft/syft/distro"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/scope"
)
type Document struct {
Artifacts []Artifact `json:"artifacts"`
Source Source `json:"source"`
Distro Distribution `json:"distro"`
}
// Distritbution provides information about a detected Linux Distribution
type Distribution struct {
Name string `json:"name"`
Version string `json:"version"`
}
func NewDocument(catalog *pkg.Catalog, s scope.Scope, d distro.Distro) (Document, error) {
doc := Document{
Artifacts: make([]Artifact, 0),
}
src, err := NewSource(s)
if err != nil {
return Document{}, nil
}
doc.Source = src
distroName := d.Name()
if distroName == "UnknownDistroType" {
distroName = ""
}
doc.Distro = Distribution{
Name: distroName,
Version: d.FullVersion(),
}
for _, p := range catalog.Sorted() {
art, err := NewArtifact(p, s)
if err != nil {
return Document{}, err
}
doc.Artifacts = append(doc.Artifacts, art)
}
return doc, nil
}