feat: add --from flag, refactor source providers (#2610)

Signed-off-by: Keith Zantow <kzantow@gmail.com>
This commit is contained in:
Keith Zantow
2024-02-27 16:44:37 -05:00
committed by GitHub
parent 928511ea0f
commit a978966cad
72 changed files with 1035 additions and 1080 deletions
@@ -222,7 +222,7 @@ func extractComponents(meta *cyclonedx.Metadata) source.Description {
ID: "",
// TODO: can we decode alias name-version somehow? (it isn't be encoded in the first place yet)
Metadata: source.StereoscopeImageSourceMetadata{
Metadata: source.ImageMetadata{
UserInput: c.Name,
ID: c.BOMRef,
ManifestDigest: c.Version,
@@ -235,7 +235,7 @@ func extractComponents(meta *cyclonedx.Metadata) source.Description {
// TODO: this is lossy... we can't know if this is a file or a directory
return source.Description{
ID: "",
Metadata: source.FileSourceMetadata{Path: c.Name},
Metadata: source.FileMetadata{Path: c.Name},
}
}
return source.Description{}
@@ -10,11 +10,11 @@ func DocumentName(src source.Description) string {
}
switch metadata := src.Metadata.(type) {
case source.StereoscopeImageSourceMetadata:
case source.ImageMetadata:
return metadata.UserInput
case source.DirectorySourceMetadata:
case source.DirectoryMetadata:
return metadata.Path
case source.FileSourceMetadata:
case source.FileMetadata:
return metadata.Path
default:
return "unknown"
@@ -23,7 +23,7 @@ func Test_DocumentName(t *testing.T) {
{
name: "image",
srcMetadata: source.Description{
Metadata: source.StereoscopeImageSourceMetadata{
Metadata: source.ImageMetadata{
UserInput: "image-repo/name:tag",
ID: "id",
ManifestDigest: "digest",
@@ -34,14 +34,14 @@ func Test_DocumentName(t *testing.T) {
{
name: "directory",
srcMetadata: source.Description{
Metadata: source.DirectorySourceMetadata{Path: "some/path/to/place"},
Metadata: source.DirectoryMetadata{Path: "some/path/to/place"},
},
expected: "some/path/to/place",
},
{
name: "file",
srcMetadata: source.Description{
Metadata: source.FileSourceMetadata{Path: "some/path/to/place"},
Metadata: source.FileMetadata{Path: "some/path/to/place"},
},
expected: "some/path/to/place",
},
@@ -49,7 +49,7 @@ func Test_DocumentName(t *testing.T) {
name: "named",
srcMetadata: source.Description{
Name: "some/name",
Metadata: source.FileSourceMetadata{Path: "some/path/to/place"},
Metadata: source.FileMetadata{Path: "some/path/to/place"},
},
expected: "some/name",
},
@@ -27,11 +27,11 @@ func DocumentNamespace(name string, src source.Description, desc sbom.Descriptor
name = cleanName(name)
input := "unknown-source-type"
switch src.Metadata.(type) {
case source.StereoscopeImageSourceMetadata:
case source.ImageMetadata:
input = InputImage
case source.DirectorySourceMetadata:
case source.DirectoryMetadata:
input = InputDirectory
case source.FileSourceMetadata:
case source.FileMetadata:
input = InputFile
}
@@ -25,7 +25,7 @@ func Test_documentNamespace(t *testing.T) {
name: "image",
inputName: "my-name",
src: source.Description{
Metadata: source.StereoscopeImageSourceMetadata{
Metadata: source.ImageMetadata{
UserInput: "image-repo/name:tag",
ID: "id",
ManifestDigest: "digest",
@@ -37,7 +37,7 @@ func Test_documentNamespace(t *testing.T) {
name: "directory",
inputName: "my-name",
src: source.Description{
Metadata: source.DirectorySourceMetadata{
Metadata: source.DirectoryMetadata{
Path: "some/path/to/place",
},
},
@@ -47,7 +47,7 @@ func Test_documentNamespace(t *testing.T) {
name: "file",
inputName: "my-name",
src: source.Description{
Metadata: source.FileSourceMetadata{
Metadata: source.FileMetadata{
Path: "some/path/to/place",
},
},
@@ -12,7 +12,7 @@ import (
"github.com/anchore/syft/syft/linux"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/sbom"
"github.com/anchore/syft/syft/source"
"github.com/anchore/syft/syft/source/directorysource"
)
func DirectoryInput(t testing.TB, dir string) sbom.SBOM {
@@ -22,8 +22,8 @@ func DirectoryInput(t testing.TB, dir string) sbom.SBOM {
require.NoError(t, os.MkdirAll(path, 0755))
src, err := source.NewFromDirectory(
source.DirectoryConfig{
src, err := directorysource.New(
directorysource.Config{
Path: path,
Base: dir,
},
@@ -63,8 +63,8 @@ func DirectoryInputWithAuthorField(t testing.TB) sbom.SBOM {
require.NoError(t, os.MkdirAll(path, 0755))
src, err := source.NewFromDirectory(
source.DirectoryConfig{
src, err := directorysource.New(
directorysource.Config{
Path: path,
Base: dir,
},
+4 -4
View File
@@ -5,7 +5,6 @@ import (
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/anchore/stereoscope/pkg/filetree"
@@ -16,7 +15,7 @@ import (
"github.com/anchore/syft/syft/linux"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/sbom"
"github.com/anchore/syft/syft/source"
"github.com/anchore/syft/syft/source/stereoscopesource"
)
func ImageInput(t testing.TB, testImage string, options ...ImageOption) sbom.SBOM {
@@ -42,8 +41,9 @@ func ImageInput(t testing.TB, testImage string, options ...ImageOption) sbom.SBO
// this is a hard coded value that is not given by the fixture helper and must be provided manually
img.Metadata.ManifestDigest = "sha256:2731251dc34951c0e50fcc643b4c5f74922dad1a5d98f302b504cf46cd5d9368"
src, err := source.NewFromStereoscopeImageObject(img, "user-image-input", nil)
assert.NoError(t, err)
src := stereoscopesource.New(img, stereoscopesource.ImageConfig{
Reference: "user-image-input",
})
return sbom.SBOM{
Artifacts: sbom.Artifacts{