rename scope to source

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman
2020-11-17 12:37:11 -05:00
parent 495fb0a45f
commit 9668341a14
55 changed files with 340 additions and 334 deletions
+1 -1
View File
@@ -15,7 +15,7 @@ type Component struct {
Description string `xml:"description,omitempty"` // A description of the component
Licenses *[]License `xml:"licenses>license"` // A node describing zero or more license names, SPDX license IDs or expressions
PackageURL string `xml:"purl,omitempty"` // Specifies the package-url (PackageURL). The purl, if specified, must be valid and conform to the specification defined at: https://github.com/package-url/purl-spec
// TODO: scope, hashes, copyright, cpe, purl, swid, modified, pedigree, externalReferences
// TODO: source, hashes, copyright, cpe, purl, swid, modified, pedigree, externalReferences
// TODO: add user-defined parameters for syft-specific values (image layer index, cataloger, location path, etc.)
}
+9 -9
View File
@@ -11,21 +11,21 @@ import (
"github.com/anchore/syft/syft/distro"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/scope"
"github.com/anchore/syft/syft/source"
)
// Presenter writes a CycloneDX report from the given Catalog and Scope contents
// Presenter writes a CycloneDX report from the given Catalog and Source contents
type Presenter struct {
catalog *pkg.Catalog
scope scope.Scope
source source.Source
distro distro.Distro
}
// NewPresenter creates a CycloneDX presenter from the given Catalog and Scope objects.
func NewPresenter(catalog *pkg.Catalog, s scope.Scope, d distro.Distro) *Presenter {
// NewPresenter creates a CycloneDX presenter from the given Catalog and Source objects.
func NewPresenter(catalog *pkg.Catalog, s source.Source, d distro.Distro) *Presenter {
return &Presenter{
catalog: catalog,
scope: s,
source: s,
distro: d,
}
}
@@ -34,8 +34,8 @@ func NewPresenter(catalog *pkg.Catalog, s scope.Scope, d distro.Distro) *Present
func (pres *Presenter) Present(output io.Writer) error {
bom := NewDocumentFromCatalog(pres.catalog, pres.distro)
switch src := pres.scope.Source.(type) {
case scope.DirSource:
switch src := pres.source.Target.(type) {
case source.DirSource:
bom.BomDescriptor.Component = &BdComponent{
Component: Component{
Type: "file",
@@ -43,7 +43,7 @@ func (pres *Presenter) Present(output io.Writer) error {
Version: "",
},
}
case scope.ImageSource:
case source.ImageSource:
var imageID string
var versionStr string
if len(src.Img.Metadata.Tags) > 0 {
+3 -3
View File
@@ -12,7 +12,7 @@ import (
"github.com/anchore/go-testutils"
"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/scope"
"github.com/anchore/syft/syft/source"
"github.com/sergi/go-diff/diffmatchpatch"
)
@@ -57,7 +57,7 @@ func TestCycloneDxDirsPresenter(t *testing.T) {
},
})
s, err := scope.NewScopeFromDir("/some/path")
s, err := source.NewFromDirectory("/some/path")
if err != nil {
t.Fatal(err)
}
@@ -147,7 +147,7 @@ func TestCycloneDxImgsPresenter(t *testing.T) {
},
})
s, err := scope.NewScopeFromImage(img, scope.AllLayersScope)
s, err := source.NewFromImage(img, source.AllLayersScope)
if err != nil {
t.Fatal(err)
}
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"fmt"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/scope"
"github.com/anchore/syft/syft/source"
)
type Artifact struct {
@@ -33,7 +33,7 @@ type ArtifactMetadataUnpacker struct {
Metadata json.RawMessage `json:"metadata"`
}
func NewArtifact(p *pkg.Package, s scope.Scope) (Artifact, error) {
func NewArtifact(p *pkg.Package, s source.Source) (Artifact, error) {
locations, err := NewLocations(p, s)
if err != nil {
return Artifact{}, err
+3 -3
View File
@@ -7,7 +7,7 @@ import (
"github.com/anchore/syft/internal/version"
"github.com/anchore/syft/syft/distro"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/scope"
"github.com/anchore/syft/syft/source"
)
type Document struct {
@@ -22,7 +22,7 @@ type Descriptor struct {
Name string `json:"name"`
Version string `json:"version"`
ReportTimestamp string `json:"reportTimestamp"`
// TODO: we should include scope option here as well (or in source)
// TODO: we should include source option here as well (or in source)
}
// Distribution provides information about a detected Linux Distribution
@@ -32,7 +32,7 @@ type Distribution struct {
IDLike string `json:"idLike"`
}
func NewDocument(catalog *pkg.Catalog, s scope.Scope, d distro.Distro) (Document, error) {
func NewDocument(catalog *pkg.Catalog, s source.Source, d distro.Distro) (Document, error) {
src, err := NewSource(s)
if err != nil {
return Document{}, nil
+2 -2
View File
@@ -1,7 +1,7 @@
package json
import (
"github.com/anchore/syft/syft/scope"
"github.com/anchore/syft/syft/source"
)
type Image struct {
@@ -18,7 +18,7 @@ type Layer struct {
Size int64 `json:"size"`
}
func NewImage(src scope.ImageSource) *Image {
func NewImage(src source.ImageSource) *Image {
// populate artifacts...
tags := make([]string, len(src.Img.Metadata.Tags))
for idx, tag := range src.Img.Metadata.Tags {
+5 -5
View File
@@ -4,7 +4,7 @@ import (
"fmt"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/scope"
"github.com/anchore/syft/syft/source"
)
type Locations interface{}
@@ -14,9 +14,9 @@ type ImageLocation struct {
LayerIndex uint `json:"layerIndex"`
}
func NewLocations(p *pkg.Package, s scope.Scope) (Locations, error) {
switch src := s.Source.(type) {
case scope.ImageSource:
func NewLocations(p *pkg.Package, s source.Source) (Locations, error) {
switch src := s.Target.(type) {
case source.ImageSource:
locations := make([]ImageLocation, len(p.Source))
for idx := range p.Source {
entry, err := src.Img.FileCatalog.Get(p.Source[idx])
@@ -33,7 +33,7 @@ func NewLocations(p *pkg.Package, s scope.Scope) (Locations, error) {
}
return locations, nil
case scope.DirSource:
case source.DirSource:
locations := make([]string, len(p.Source))
for idx := range p.Source {
locations[idx] = string(p.Source[idx].Path)
+5 -5
View File
@@ -6,25 +6,25 @@ import (
"github.com/anchore/syft/syft/distro"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/scope"
"github.com/anchore/syft/syft/source"
)
type Presenter struct {
catalog *pkg.Catalog
scope scope.Scope
source source.Source
distro distro.Distro
}
func NewPresenter(catalog *pkg.Catalog, s scope.Scope, d distro.Distro) *Presenter {
func NewPresenter(catalog *pkg.Catalog, s source.Source, d distro.Distro) *Presenter {
return &Presenter{
catalog: catalog,
scope: s,
source: s,
distro: d,
}
}
func (pres *Presenter) Present(output io.Writer) error {
doc, err := NewDocument(pres.catalog, pres.scope, pres.distro)
doc, err := NewDocument(pres.catalog, pres.source, pres.distro)
if err != nil {
return err
}
+3 -3
View File
@@ -10,7 +10,7 @@ import (
"github.com/anchore/stereoscope/pkg/imagetest"
"github.com/anchore/syft/syft/distro"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/scope"
"github.com/anchore/syft/syft/source"
"github.com/sergi/go-diff/diffmatchpatch"
)
@@ -53,7 +53,7 @@ func TestJsonDirsPresenter(t *testing.T) {
},
})
d := distro.NewUnknownDistro()
s, err := scope.NewScopeFromDir("/some/path")
s, err := source.NewFromDirectory("/some/path")
if err != nil {
t.Fatal(err)
}
@@ -124,7 +124,7 @@ func TestJsonImgsPresenter(t *testing.T) {
},
})
s, err := scope.NewScopeFromImage(img, scope.AllLayersScope)
s, err := source.NewFromImage(img, source.AllLayersScope)
d := distro.NewUnknownDistro()
pres := NewPresenter(catalog, s, d)
+5 -5
View File
@@ -4,7 +4,7 @@ import (
"encoding/json"
"fmt"
"github.com/anchore/syft/syft/scope"
"github.com/anchore/syft/syft/source"
)
type Source struct {
@@ -17,14 +17,14 @@ type SourceUnpacker struct {
Target json.RawMessage `json:"target"`
}
func NewSource(s scope.Scope) (Source, error) {
switch src := s.Source.(type) {
case scope.ImageSource:
func NewSource(s source.Source) (Source, error) {
switch src := s.Target.(type) {
case source.ImageSource:
return Source{
Type: "image",
Target: NewImage(src),
}, nil
case scope.DirSource:
case source.DirSource:
return Source{
Type: "directory",
Target: src.Path,
+2 -2
View File
@@ -15,7 +15,7 @@ import (
"github.com/anchore/syft/syft/presenter/json"
"github.com/anchore/syft/syft/presenter/table"
"github.com/anchore/syft/syft/presenter/text"
"github.com/anchore/syft/syft/scope"
"github.com/anchore/syft/syft/source"
)
// Presenter defines the expected behavior for an object responsible for displaying arbitrary input and processed data
@@ -25,7 +25,7 @@ type Presenter interface {
}
// GetPresenter returns a presenter for images or directories
func GetPresenter(option Option, s scope.Scope, catalog *pkg.Catalog, d *distro.Distro) Presenter {
func GetPresenter(option Option, s source.Source, catalog *pkg.Catalog, d *distro.Distro) Presenter {
switch option {
case JSONPresenter:
return json.NewPresenter(catalog, s, *d)
+4 -4
View File
@@ -9,18 +9,18 @@ import (
"github.com/olekukonko/tablewriter"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/scope"
"github.com/anchore/syft/syft/source"
)
type Presenter struct {
catalog *pkg.Catalog
scope scope.Scope
source source.Source
}
func NewPresenter(catalog *pkg.Catalog, s scope.Scope) *Presenter {
func NewPresenter(catalog *pkg.Catalog, s source.Source) *Presenter {
return &Presenter{
catalog: catalog,
scope: s,
source: s,
}
}
+4 -3
View File
@@ -3,14 +3,15 @@ package table
import (
"bytes"
"flag"
"github.com/go-test/deep"
"testing"
"github.com/go-test/deep"
"github.com/anchore/go-testutils"
"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/stereoscope/pkg/imagetest"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/scope"
"github.com/anchore/syft/syft/source"
"github.com/sergi/go-diff/diffmatchpatch"
)
@@ -43,7 +44,7 @@ func TestTablePresenter(t *testing.T) {
Type: pkg.DebPkg,
})
s, err := scope.NewScopeFromImage(img, scope.AllLayersScope)
s, err := source.NewFromImage(img, source.AllLayersScope)
pres := NewPresenter(catalog, s)
// run presenter
+7 -7
View File
@@ -7,18 +7,18 @@ import (
"text/tabwriter"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/scope"
"github.com/anchore/syft/syft/source"
)
type Presenter struct {
catalog *pkg.Catalog
scope scope.Scope
source source.Source
}
func NewPresenter(catalog *pkg.Catalog, s scope.Scope) *Presenter {
func NewPresenter(catalog *pkg.Catalog, s source.Source) *Presenter {
return &Presenter{
catalog: catalog,
scope: s,
source: s,
}
}
@@ -28,10 +28,10 @@ func (pres *Presenter) Present(output io.Writer) error {
w := new(tabwriter.Writer)
w.Init(output, 0, 8, 0, '\t', tabwriter.AlignRight)
switch src := pres.scope.Source.(type) {
case scope.DirSource:
switch src := pres.source.Target.(type) {
case source.DirSource:
fmt.Fprintln(w, fmt.Sprintf("[Path: %s]", src.Path))
case scope.ImageSource:
case source.ImageSource:
fmt.Fprintln(w, "[Image]")
for idx, l := range src.Img.Layers {
+4 -4
View File
@@ -9,7 +9,7 @@ import (
"github.com/anchore/stereoscope/pkg/file"
"github.com/anchore/stereoscope/pkg/imagetest"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/scope"
"github.com/anchore/syft/syft/source"
"github.com/sergi/go-diff/diffmatchpatch"
)
@@ -32,9 +32,9 @@ func TestTextDirPresenter(t *testing.T) {
Type: pkg.DebPkg,
})
s, err := scope.NewScopeFromDir("/some/path")
s, err := source.NewFromDirectory("/some/path")
if err != nil {
t.Fatalf("unable to create scope: %+v", err)
t.Fatalf("unable to create source: %+v", err)
}
pres := NewPresenter(catalog, s)
@@ -98,7 +98,7 @@ func TestTextImgPresenter(t *testing.T) {
l.Metadata.Digest = "sha256:ad8ecdc058976c07e7e347cb89fa9ad86a294b5ceaae6d09713fb035f84115abf3c4a2388a4af3aa60f13b94f4c6846930bdf53"
}
s, err := scope.NewScopeFromImage(img, scope.AllLayersScope)
s, err := source.NewFromImage(img, source.AllLayersScope)
if err != nil {
t.Fatal(err)
}