mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
Merge pull request #250 from anchore/issue-169
Add distro information to JSON presenter
This commit is contained in:
commit
b3098f3423
@ -1,6 +1,7 @@
|
|||||||
package json
|
package json
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/anchore/syft/syft/distro"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
"github.com/anchore/syft/syft/scope"
|
"github.com/anchore/syft/syft/scope"
|
||||||
)
|
)
|
||||||
@ -8,9 +9,16 @@ import (
|
|||||||
type Document struct {
|
type Document struct {
|
||||||
Artifacts []Artifact `json:"artifacts"`
|
Artifacts []Artifact `json:"artifacts"`
|
||||||
Source Source `json:"source"`
|
Source Source `json:"source"`
|
||||||
|
Distro Distribution `json:"distro"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDocument(catalog *pkg.Catalog, s scope.Scope) (Document, error) {
|
// 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{
|
doc := Document{
|
||||||
Artifacts: make([]Artifact, 0),
|
Artifacts: make([]Artifact, 0),
|
||||||
}
|
}
|
||||||
@ -20,6 +28,14 @@ func NewDocument(catalog *pkg.Catalog, s scope.Scope) (Document, error) {
|
|||||||
return Document{}, nil
|
return Document{}, nil
|
||||||
}
|
}
|
||||||
doc.Source = src
|
doc.Source = src
|
||||||
|
distroName := d.Name()
|
||||||
|
if distroName == "UnknownDistroType" {
|
||||||
|
distroName = ""
|
||||||
|
}
|
||||||
|
doc.Distro = Distribution{
|
||||||
|
Name: distroName,
|
||||||
|
Version: d.FullVersion(),
|
||||||
|
}
|
||||||
|
|
||||||
for _, p := range catalog.Sorted() {
|
for _, p := range catalog.Sorted() {
|
||||||
art, err := NewArtifact(p, s)
|
art, err := NewArtifact(p, s)
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package json
|
package json
|
||||||
|
|
||||||
import "github.com/anchore/syft/syft/scope"
|
import (
|
||||||
|
"github.com/anchore/syft/syft/scope"
|
||||||
|
)
|
||||||
|
|
||||||
type Image struct {
|
type Image struct {
|
||||||
Layers []Layer `json:"layers"`
|
Layers []Layer `json:"layers"`
|
||||||
|
|||||||
@ -4,6 +4,7 @@ import (
|
|||||||
"encoding/json"
|
"encoding/json"
|
||||||
"io"
|
"io"
|
||||||
|
|
||||||
|
"github.com/anchore/syft/syft/distro"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
"github.com/anchore/syft/syft/scope"
|
"github.com/anchore/syft/syft/scope"
|
||||||
)
|
)
|
||||||
@ -11,17 +12,19 @@ import (
|
|||||||
type Presenter struct {
|
type Presenter struct {
|
||||||
catalog *pkg.Catalog
|
catalog *pkg.Catalog
|
||||||
scope scope.Scope
|
scope scope.Scope
|
||||||
|
distro distro.Distro
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewPresenter(catalog *pkg.Catalog, s scope.Scope) *Presenter {
|
func NewPresenter(catalog *pkg.Catalog, s scope.Scope, d distro.Distro) *Presenter {
|
||||||
return &Presenter{
|
return &Presenter{
|
||||||
catalog: catalog,
|
catalog: catalog,
|
||||||
scope: s,
|
scope: s,
|
||||||
|
distro: d,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (pres *Presenter) Present(output io.Writer) error {
|
func (pres *Presenter) Present(output io.Writer) error {
|
||||||
doc, err := NewDocument(pres.catalog, pres.scope)
|
doc, err := NewDocument(pres.catalog, pres.scope, pres.distro)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import (
|
|||||||
"github.com/anchore/go-testutils"
|
"github.com/anchore/go-testutils"
|
||||||
"github.com/anchore/stereoscope/pkg/file"
|
"github.com/anchore/stereoscope/pkg/file"
|
||||||
"github.com/anchore/stereoscope/pkg/imagetest"
|
"github.com/anchore/stereoscope/pkg/imagetest"
|
||||||
|
"github.com/anchore/syft/syft/distro"
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
"github.com/anchore/syft/syft/scope"
|
"github.com/anchore/syft/syft/scope"
|
||||||
"github.com/sergi/go-diff/diffmatchpatch"
|
"github.com/sergi/go-diff/diffmatchpatch"
|
||||||
@ -39,12 +40,12 @@ func TestJsonDirsPresenter(t *testing.T) {
|
|||||||
{Path: "/some/path/pkg1"},
|
{Path: "/some/path/pkg1"},
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
d := distro.NewUnknownDistro()
|
||||||
s, err := scope.NewScopeFromDir("/some/path")
|
s, err := scope.NewScopeFromDir("/some/path")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatal(err)
|
t.Fatal(err)
|
||||||
}
|
}
|
||||||
pres := NewPresenter(catalog, s)
|
pres := NewPresenter(catalog, s, d)
|
||||||
|
|
||||||
// run presenter
|
// run presenter
|
||||||
err = pres.Present(&buffer)
|
err = pres.Present(&buffer)
|
||||||
@ -100,7 +101,8 @@ func TestJsonImgsPresenter(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
s, err := scope.NewScopeFromImage(img, scope.AllLayersScope)
|
s, err := scope.NewScopeFromImage(img, scope.AllLayersScope)
|
||||||
pres := NewPresenter(catalog, s)
|
d := distro.NewUnknownDistro()
|
||||||
|
pres := NewPresenter(catalog, s, d)
|
||||||
|
|
||||||
// run presenter
|
// run presenter
|
||||||
err = pres.Present(&buffer)
|
err = pres.Present(&buffer)
|
||||||
|
|||||||
@ -26,5 +26,9 @@
|
|||||||
"source": {
|
"source": {
|
||||||
"type": "directory",
|
"type": "directory",
|
||||||
"target": "/some/path"
|
"target": "/some/path"
|
||||||
|
},
|
||||||
|
"distro": {
|
||||||
|
"name": "",
|
||||||
|
"version": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -35,26 +35,30 @@
|
|||||||
"layers": [
|
"layers": [
|
||||||
{
|
{
|
||||||
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
||||||
"digest": "sha256:e158b57d6f5a96ef5fd22f2fe76c70b5ba6ff5b2619f9d83125b2aad0492ac7b",
|
"digest": "sha256:78783bfc74fef84f899b4977561ad1172f87753f82cc2157b06bf097e56dfbce",
|
||||||
"size": 22
|
"size": 22
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
||||||
"digest": "sha256:da21056e7bf4308ecea0c0836848a7fe92f38fdcf35bc09ee6d98e7ab7beeebf",
|
"digest": "sha256:54ec7f643dafbf9f27032a5e60afe06248c0e99b50aed54bb0fe28ea4825ccaf",
|
||||||
"size": 16
|
"size": 16
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
||||||
"digest": "sha256:f0e18aa6032c24659a9c741fc36ca56f589782ea132061ccf6f52b952403da94",
|
"digest": "sha256:ec4775a139c45b1ddf9ea8e1cb43385e92e5c0bf6ec2e3f4192372785b18c106",
|
||||||
"size": 27
|
"size": 27
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"size": 65,
|
"size": 65,
|
||||||
"digest": "sha256:2731251dc34951c0e50fcc643b4c5f74922dad1a5d98f302b504cf46cd5d9368",
|
"digest": "sha256:fedd7bcc0b90f071501b662d8e7c9ac7548b88daba6b3deedfdf33f22ed8d95b",
|
||||||
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
|
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
|
||||||
"tags": [
|
"tags": [
|
||||||
"stereoscope-fixture-image-simple:04e16e44161c8888a1a963720fd0443cbf7eef8101434c431de8725cd98cc9f7"
|
"stereoscope-fixture-image-simple:04e16e44161c8888a1a963720fd0443cbf7eef8101434c431de8725cd98cc9f7"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
"distro": {
|
||||||
|
"name": "",
|
||||||
|
"version": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
@ -28,7 +28,7 @@ type Presenter interface {
|
|||||||
func GetPresenter(option Option, s scope.Scope, catalog *pkg.Catalog, d *distro.Distro) Presenter {
|
func GetPresenter(option Option, s scope.Scope, catalog *pkg.Catalog, d *distro.Distro) Presenter {
|
||||||
switch option {
|
switch option {
|
||||||
case JSONPresenter:
|
case JSONPresenter:
|
||||||
return json.NewPresenter(catalog, s)
|
return json.NewPresenter(catalog, s, *d)
|
||||||
case TextPresenter:
|
case TextPresenter:
|
||||||
return text.NewPresenter(catalog, s)
|
return text.NewPresenter(catalog, s)
|
||||||
case TablePresenter:
|
case TablePresenter:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user