mirror of
https://github.com/anchore/syft.git
synced 2026-02-12 10:36:45 +01:00
Normalize the json image/dir source (#180)
* normalize the json image/dir source Signed-off-by: Alex Goodman <alex.goodman@anchore.com> * update json image presenter golden file Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
c46d004a3b
commit
49800b6747
@ -200,6 +200,9 @@
|
|||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
"name": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"originPackage": {
|
"originPackage": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
@ -444,9 +447,15 @@
|
|||||||
"source": {
|
"source": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"sourceRpm": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"url": {
|
"url": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"vendor": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"version": {
|
"version": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
}
|
}
|
||||||
@ -474,61 +483,78 @@
|
|||||||
},
|
},
|
||||||
"type": "array"
|
"type": "array"
|
||||||
},
|
},
|
||||||
"directory": {
|
"source": {
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"image": {
|
|
||||||
"properties": {
|
"properties": {
|
||||||
"digest": {
|
"target": {
|
||||||
"type": "string"
|
"anyOf": [
|
||||||
},
|
{
|
||||||
"layers": {
|
"type": "string"
|
||||||
"items": {
|
|
||||||
"properties": {
|
|
||||||
"digest": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"mediaType": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"size": {
|
|
||||||
"type": "integer"
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
"required": [
|
{
|
||||||
"digest",
|
"properties": {
|
||||||
"mediaType",
|
"digest": {
|
||||||
"size"
|
"type": "string"
|
||||||
],
|
},
|
||||||
"type": "object"
|
"layers": {
|
||||||
},
|
"items": {
|
||||||
"type": "array"
|
"properties": {
|
||||||
|
"digest": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"mediaType": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"size": {
|
||||||
|
"type": "integer"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"digest",
|
||||||
|
"mediaType",
|
||||||
|
"size"
|
||||||
|
],
|
||||||
|
"type": "object"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
},
|
||||||
|
"mediaType": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"size": {
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"tags": {
|
||||||
|
"items": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"required": [
|
||||||
|
"digest",
|
||||||
|
"layers",
|
||||||
|
"mediaType",
|
||||||
|
"size",
|
||||||
|
"tags"
|
||||||
|
],
|
||||||
|
"type": "object"
|
||||||
|
}
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"mediaType": {
|
"type": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
|
||||||
"size": {
|
|
||||||
"type": "integer"
|
|
||||||
},
|
|
||||||
"tags": {
|
|
||||||
"items": {
|
|
||||||
"type": "string"
|
|
||||||
},
|
|
||||||
"type": "array"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"digest",
|
"target",
|
||||||
"layers",
|
"type"
|
||||||
"mediaType",
|
|
||||||
"size",
|
|
||||||
"tags"
|
|
||||||
],
|
],
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"required": [
|
"required": [
|
||||||
"artifacts"
|
"artifacts",
|
||||||
|
"source"
|
||||||
],
|
],
|
||||||
"type": "object"
|
"type": "object"
|
||||||
}
|
}
|
||||||
@ -3,7 +3,7 @@ A "one-stop-shop" for helper utilities for all major functionality provided by c
|
|||||||
|
|
||||||
Here is what the main execution path for syft does:
|
Here is what the main execution path for syft does:
|
||||||
|
|
||||||
1. Parse a user image string to get a stereoscope image.Image object
|
1. Parse a user image string to get a stereoscope image.Source object
|
||||||
2. Invoke all catalogers to catalog the image, adding discovered packages to a single catalog object
|
2. Invoke all catalogers to catalog the image, adding discovered packages to a single catalog object
|
||||||
3. Invoke a single presenter to show the contents of the catalog
|
3. Invoke a single presenter to show the contents of the catalog
|
||||||
|
|
||||||
|
|||||||
@ -1,16 +1,13 @@
|
|||||||
package json
|
package json
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/anchore/syft/syft/pkg"
|
"github.com/anchore/syft/syft/pkg"
|
||||||
"github.com/anchore/syft/syft/scope"
|
"github.com/anchore/syft/syft/scope"
|
||||||
)
|
)
|
||||||
|
|
||||||
type Document struct {
|
type Document struct {
|
||||||
Artifacts []Artifact `json:"artifacts"`
|
Artifacts []Artifact `json:"artifacts"`
|
||||||
Image *Image `json:"image,omitempty"`
|
Source Source `json:"source"`
|
||||||
Directory *string `json:"directory,omitempty"`
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewDocument(catalog *pkg.Catalog, s scope.Scope) (Document, error) {
|
func NewDocument(catalog *pkg.Catalog, s scope.Scope) (Document, error) {
|
||||||
@ -18,15 +15,11 @@ func NewDocument(catalog *pkg.Catalog, s scope.Scope) (Document, error) {
|
|||||||
Artifacts: make([]Artifact, 0),
|
Artifacts: make([]Artifact, 0),
|
||||||
}
|
}
|
||||||
|
|
||||||
srcObj := s.Source()
|
src, err := NewSource(s)
|
||||||
switch src := srcObj.(type) {
|
if err != nil {
|
||||||
case scope.ImageSource:
|
return Document{}, nil
|
||||||
doc.Image = NewImage(src)
|
|
||||||
case scope.DirSource:
|
|
||||||
doc.Directory = &s.DirSrc.Path
|
|
||||||
default:
|
|
||||||
return Document{}, fmt.Errorf("unsupported source: %T", src)
|
|
||||||
}
|
}
|
||||||
|
doc.Source = src
|
||||||
|
|
||||||
for _, p := range catalog.Sorted() {
|
for _, p := range catalog.Sorted() {
|
||||||
art, err := NewArtifact(p, s)
|
art, err := NewArtifact(p, s)
|
||||||
|
|||||||
30
syft/presenter/json/source.go
Normal file
30
syft/presenter/json/source.go
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
package json
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
|
||||||
|
"github.com/anchore/syft/syft/scope"
|
||||||
|
)
|
||||||
|
|
||||||
|
type Source struct {
|
||||||
|
Type string `json:"type"`
|
||||||
|
Target interface{} `json:"target"`
|
||||||
|
}
|
||||||
|
|
||||||
|
func NewSource(s scope.Scope) (Source, error) {
|
||||||
|
srcObj := s.Source()
|
||||||
|
switch src := srcObj.(type) {
|
||||||
|
case scope.ImageSource:
|
||||||
|
return Source{
|
||||||
|
Type: "image",
|
||||||
|
Target: NewImage(src),
|
||||||
|
}, nil
|
||||||
|
case scope.DirSource:
|
||||||
|
return Source{
|
||||||
|
Type: "directory",
|
||||||
|
Target: s.DirSrc.Path,
|
||||||
|
}, nil
|
||||||
|
default:
|
||||||
|
return Source{}, fmt.Errorf("unsupported source: %T", src)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -23,5 +23,8 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"directory": "/some/path"
|
"source": {
|
||||||
|
"type": "directory",
|
||||||
|
"target": "/some/path"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,29 +29,32 @@
|
|||||||
]
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"image": {
|
"source": {
|
||||||
"layers": [
|
"type": "image",
|
||||||
{
|
"target": {
|
||||||
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
"layers": [
|
||||||
"digest": "sha256:e158b57d6f5a96ef5fd22f2fe76c70b5ba6ff5b2619f9d83125b2aad0492ac7b",
|
{
|
||||||
"size": 22
|
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
||||||
},
|
"digest": "sha256:e158b57d6f5a96ef5fd22f2fe76c70b5ba6ff5b2619f9d83125b2aad0492ac7b",
|
||||||
{
|
"size": 22
|
||||||
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
},
|
||||||
"digest": "sha256:da21056e7bf4308ecea0c0836848a7fe92f38fdcf35bc09ee6d98e7ab7beeebf",
|
{
|
||||||
"size": 16
|
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
||||||
},
|
"digest": "sha256:da21056e7bf4308ecea0c0836848a7fe92f38fdcf35bc09ee6d98e7ab7beeebf",
|
||||||
{
|
"size": 16
|
||||||
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
},
|
||||||
"digest": "sha256:f0e18aa6032c24659a9c741fc36ca56f589782ea132061ccf6f52b952403da94",
|
{
|
||||||
"size": 27
|
"mediaType": "application/vnd.docker.image.rootfs.diff.tar.gzip",
|
||||||
}
|
"digest": "sha256:f0e18aa6032c24659a9c741fc36ca56f589782ea132061ccf6f52b952403da94",
|
||||||
],
|
"size": 27
|
||||||
"size": 65,
|
}
|
||||||
"digest": "sha256:2731251dc34951c0e50fcc643b4c5f74922dad1a5d98f302b504cf46cd5d9368",
|
],
|
||||||
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
|
"size": 65,
|
||||||
"tags": [
|
"digest": "sha256:2731251dc34951c0e50fcc643b4c5f74922dad1a5d98f302b504cf46cd5d9368",
|
||||||
"stereoscope-fixture-image-simple:04e16e44161c8888a1a963720fd0443cbf7eef8101434c431de8725cd98cc9f7"
|
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
|
||||||
]
|
"tags": [
|
||||||
|
"stereoscope-fixture-image-simple:04e16e44161c8888a1a963720fd0443cbf7eef8101434c431de8725cd98cc9f7"
|
||||||
|
]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user