Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 69 additions & 43 deletions schema/json/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,9 @@
}
]
},
"name": {
"type": "string"
},
"originPackage": {
"type": "string"
},
Expand Down Expand Up @@ -444,9 +447,15 @@
"source": {
"type": "string"
},
"sourceRpm": {
"type": "string"
},
"url": {
"type": "string"
},
"vendor": {
"type": "string"
},
"version": {
"type": "string"
}
Expand Down Expand Up @@ -474,61 +483,78 @@
},
"type": "array"
},
"directory": {
"type": "string"
},
"image": {
"source": {
"properties": {
"digest": {
"type": "string"
},
"layers": {
"items": {
"properties": {
"digest": {
"type": "string"
},
"mediaType": {
"type": "string"
},
"size": {
"type": "integer"
}
"target": {
"anyOf": [
{
"type": "string"
},
"required": [
"digest",
"mediaType",
"size"
],
"type": "object"
},
"type": "array"
{
"properties": {
"digest": {
"type": "string"
},
"layers": {
"items": {
"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"
},
"size": {
"type": "integer"
},
"tags": {
"items": {
"type": "string"
},
"type": "array"
}
},
"required": [
"digest",
"layers",
"mediaType",
"size",
"tags"
"target",
"type"
],
"type": "object"
}
},
"required": [
"artifacts"
"artifacts",
"source"
],
"type": "object"
}
2 changes: 1 addition & 1 deletion syft/lib.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:

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
3. Invoke a single presenter to show the contents of the catalog

Expand Down
17 changes: 5 additions & 12 deletions syft/presenter/json/document.go
Original file line number Diff line number Diff line change
@@ -1,32 +1,25 @@
package json

import (
"fmt"

"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/scope"
)

type Document struct {
Artifacts []Artifact `json:"artifacts"`
Image *Image `json:"image,omitempty"`
Directory *string `json:"directory,omitempty"`
Source Source `json:"source"`
}

func NewDocument(catalog *pkg.Catalog, s scope.Scope) (Document, error) {
doc := Document{
Artifacts: make([]Artifact, 0),
}

srcObj := s.Source()
switch src := srcObj.(type) {
case scope.ImageSource:
doc.Image = NewImage(src)
case scope.DirSource:
doc.Directory = &s.DirSrc.Path
default:
return Document{}, fmt.Errorf("unsupported source: %T", src)
src, err := NewSource(s)
if err != nil {
return Document{}, nil
}
doc.Source = src

for _, p := range catalog.Sorted() {
art, err := NewArtifact(p, s)
Expand Down
30 changes: 30 additions & 0 deletions syft/presenter/json/source.go
Original file line number Diff line number Diff line change
@@ -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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,8 @@
]
}
],
"directory": "/some/path"
"source": {
"type": "directory",
"target": "/some/path"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,29 +29,32 @@
]
}
],
"image": {
"layers": [
{
"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:f0e18aa6032c24659a9c741fc36ca56f589782ea132061ccf6f52b952403da94",
"size": 27
}
],
"size": 65,
"digest": "sha256:2731251dc34951c0e50fcc643b4c5f74922dad1a5d98f302b504cf46cd5d9368",
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"tags": [
"stereoscope-fixture-image-simple:04e16e44161c8888a1a963720fd0443cbf7eef8101434c431de8725cd98cc9f7"
]
"source": {
"type": "image",
"target": {
"layers": [
{
"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:f0e18aa6032c24659a9c741fc36ca56f589782ea132061ccf6f52b952403da94",
"size": 27
}
],
"size": 65,
"digest": "sha256:2731251dc34951c0e50fcc643b4c5f74922dad1a5d98f302b504cf46cd5d9368",
"mediaType": "application/vnd.docker.distribution.manifest.v2+json",
"tags": [
"stereoscope-fixture-image-simple:04e16e44161c8888a1a963720fd0443cbf7eef8101434c431de8725cd98cc9f7"
]
}
}
}
Binary file not shown.