diff --git a/syft/create_sbom_config.go b/syft/create_sbom_config.go index d1a9662289c..fabf829d7f9 100644 --- a/syft/create_sbom_config.go +++ b/syft/create_sbom_config.go @@ -350,7 +350,7 @@ func findDefaultTag(src source.Description) (string, error) { switch m := src.Metadata.(type) { case stereoscopesource.ImageMetadata: return pkgcataloging.ImageTag, nil - case filesource.FileMetadata, directorysource.DirectoryMetadata: + case filesource.Metadata, directorysource.Metadata: return pkgcataloging.DirectoryTag, nil default: return "", fmt.Errorf("unable to determine default cataloger tag for source type=%T", m) diff --git a/syft/create_sbom_config_test.go b/syft/create_sbom_config_test.go index a7acdd38f19..aaf3128d39e 100644 --- a/syft/create_sbom_config_test.go +++ b/syft/create_sbom_config_test.go @@ -69,11 +69,11 @@ func TestCreateSBOMConfig_makeTaskGroups(t *testing.T) { } dirSrc := source.Description{ - Metadata: directorysource.DirectoryMetadata{}, + Metadata: directorysource.Metadata{}, } fileSrc := source.Description{ - Metadata: filesource.FileMetadata{}, + Metadata: filesource.Metadata{}, } tests := []struct { @@ -447,14 +447,14 @@ func Test_findDefaultTag(t *testing.T) { { name: "directory", src: source.Description{ - Metadata: directorysource.DirectoryMetadata{}, + Metadata: directorysource.Metadata{}, }, want: pkgcataloging.DirectoryTag, }, { name: "file", src: source.Description{ - Metadata: filesource.FileMetadata{}, + Metadata: filesource.Metadata{}, }, want: pkgcataloging.DirectoryTag, // not a mistake... }, diff --git a/syft/format/common/cyclonedxhelpers/to_format_model.go b/syft/format/common/cyclonedxhelpers/to_format_model.go index ace0eefaf7f..dd73fb372d9 100644 --- a/syft/format/common/cyclonedxhelpers/to_format_model.go +++ b/syft/format/common/cyclonedxhelpers/to_format_model.go @@ -240,7 +240,7 @@ func toBomDescriptorComponent(srcMetadata source.Description) *cyclonedx.Compone Name: name, Version: version, } - case directorysource.DirectoryMetadata: + case directorysource.Metadata: if name == "" { name = metadata.Path } @@ -255,7 +255,7 @@ func toBomDescriptorComponent(srcMetadata source.Description) *cyclonedx.Compone Name: name, Version: version, } - case filesource.FileMetadata: + case filesource.Metadata: if name == "" { name = metadata.Path } diff --git a/syft/format/common/spdxhelpers/to_format_model.go b/syft/format/common/spdxhelpers/to_format_model.go index 6aca1279593..2cab906487f 100644 --- a/syft/format/common/spdxhelpers/to_format_model.go +++ b/syft/format/common/spdxhelpers/to_format_model.go @@ -214,11 +214,11 @@ func toRootPackage(s source.Description) *spdx.Package { } } - case directorysource.DirectoryMetadata: + case directorysource.Metadata: prefix = prefixDirectory purpose = spdxPrimaryPurposeFile - case filesource.FileMetadata: + case filesource.Metadata: prefix = prefixFile purpose = spdxPrimaryPurposeFile diff --git a/syft/format/common/spdxhelpers/to_format_model_test.go b/syft/format/common/spdxhelpers/to_format_model_test.go index 948ab212100..cdecf8f680b 100644 --- a/syft/format/common/spdxhelpers/to_format_model_test.go +++ b/syft/format/common/spdxhelpers/to_format_model_test.go @@ -109,7 +109,7 @@ func Test_toFormatModel(t *testing.T) { in: sbom.SBOM{ Source: source.Description{ Name: "some/directory", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "some/directory", }, }, @@ -173,7 +173,7 @@ func Test_toFormatModel(t *testing.T) { Source: source.Description{ Name: "path/to/some.file", Version: "sha256:d34db33f", - Metadata: filesource.FileMetadata{ + Metadata: filesource.Metadata{ Path: "path/to/some.file", Digests: []file.Digest{ { diff --git a/syft/format/common/spdxhelpers/to_syft_model.go b/syft/format/common/spdxhelpers/to_syft_model.go index 939ee6a55d0..a49b66af03e 100644 --- a/syft/format/common/spdxhelpers/to_syft_model.go +++ b/syft/format/common/spdxhelpers/to_syft_model.go @@ -190,7 +190,7 @@ func fileSource(p *spdx.Package) source.Description { func fileSourceMetadata(p *spdx.Package) (any, string) { version := p.PackageVersion - m := filesource.FileMetadata{ + m := filesource.Metadata{ Path: p.PackageName, } // if this is a Syft SBOM, we might have output a digest as the version @@ -209,7 +209,7 @@ func fileSourceMetadata(p *spdx.Package) (any, string) { } func directorySourceMetadata(p *spdx.Package) (any, string) { - return directorysource.DirectoryMetadata{ + return directorysource.Metadata{ Path: p.PackageName, Base: "", }, p.PackageVersion @@ -232,7 +232,7 @@ func extractSourceFromNamespace(ns string) source.Description { switch p { case helpers.InputFile: return source.Description{ - Metadata: filesource.FileMetadata{}, + Metadata: filesource.Metadata{}, } case helpers.InputImage: return source.Description{ @@ -240,7 +240,7 @@ func extractSourceFromNamespace(ns string) source.Description { } case helpers.InputDirectory: return source.Description{ - Metadata: directorysource.DirectoryMetadata{}, + Metadata: directorysource.Metadata{}, } } } diff --git a/syft/format/common/spdxhelpers/to_syft_model_test.go b/syft/format/common/spdxhelpers/to_syft_model_test.go index 84e0bb9f946..c10ad0f1d8c 100644 --- a/syft/format/common/spdxhelpers/to_syft_model_test.go +++ b/syft/format/common/spdxhelpers/to_syft_model_test.go @@ -202,7 +202,7 @@ func TestExtractSourceFromNamespaces(t *testing.T) { }{ { namespace: "https://anchore.com/syft/file/d42b01d0-7325-409b-b03f-74082935c4d3", - expected: filesource.FileMetadata{}, + expected: filesource.Metadata{}, }, { namespace: "https://anchore.com/syft/image/d42b01d0-7325-409b-b03f-74082935c4d3", @@ -210,7 +210,7 @@ func TestExtractSourceFromNamespaces(t *testing.T) { }, { namespace: "https://anchore.com/syft/dir/d42b01d0-7325-409b-b03f-74082935c4d3", - expected: directorysource.DirectoryMetadata{}, + expected: directorysource.Metadata{}, }, { namespace: "https://another-host/blob/123", @@ -479,7 +479,7 @@ func Test_convertToAndFromFormat(t *testing.T) { source: source.Description{ ID: "DocumentRoot-Directory-.", Name: ".", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: ".", }, }, @@ -491,7 +491,7 @@ func Test_convertToAndFromFormat(t *testing.T) { source: source.Description{ ID: "DocumentRoot-Directory-my-app", Name: "my-app", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "my-app", }, }, @@ -502,7 +502,7 @@ func Test_convertToAndFromFormat(t *testing.T) { name: "file source", source: source.Description{ ID: "DocumentRoot-File-my-app.exe", - Metadata: filesource.FileMetadata{ + Metadata: filesource.Metadata{ Path: "my-app.exe", Digests: []file.Digest{ { @@ -538,7 +538,7 @@ func Test_convertToAndFromFormat(t *testing.T) { cmpopts.IgnoreUnexported(pkg.Collection{}), cmpopts.IgnoreUnexported(pkg.Package{}), cmpopts.IgnoreUnexported(pkg.LicenseSet{}), - cmpopts.IgnoreFields(sbom.Artifacts{}, "FileMetadata", "FileDigests"), + cmpopts.IgnoreFields(sbom.Artifacts{}, "Metadata", "FileDigests"), ); diff != "" { t.Fatalf("packages do not match:\n%s", diff) } diff --git a/syft/format/github/internal/model/model.go b/syft/format/github/internal/model/model.go index 59101352691..fb9141e2db1 100644 --- a/syft/format/github/internal/model/model.go +++ b/syft/format/github/internal/model/model.go @@ -122,13 +122,13 @@ func toPath(s source.Description, p pkg.Package) string { case stereoscopesource.ImageMetadata: image := strings.ReplaceAll(metadata.UserInput, ":/", "//") return fmt.Sprintf("%s:/%s", image, packagePath) - case filesource.FileMetadata: + case filesource.Metadata: path := trimRelative(metadata.Path) if isArchive(metadata.Path) { return fmt.Sprintf("%s:/%s", path, packagePath) } return path - case directorysource.DirectoryMetadata: + case directorysource.Metadata: path := trimRelative(metadata.Path) if path != "" { return fmt.Sprintf("%s/%s", path, packagePath) diff --git a/syft/format/github/internal/model/model_test.go b/syft/format/github/internal/model/model_test.go index 7e6846461cc..4f85bf6e060 100644 --- a/syft/format/github/internal/model/model_test.go +++ b/syft/format/github/internal/model/model_test.go @@ -153,27 +153,27 @@ func Test_toGithubModel(t *testing.T) { }, { name: "current directory", - metadata: directorysource.DirectoryMetadata{Path: "."}, + metadata: directorysource.Metadata{Path: "."}, testPath: "etc", }, { name: "relative directory", - metadata: directorysource.DirectoryMetadata{Path: "./artifacts"}, + metadata: directorysource.Metadata{Path: "./artifacts"}, testPath: "artifacts/etc", }, { name: "absolute directory", - metadata: directorysource.DirectoryMetadata{Path: "/artifacts"}, + metadata: directorysource.Metadata{Path: "/artifacts"}, testPath: "/artifacts/etc", }, { name: "file", - metadata: filesource.FileMetadata{Path: "./executable"}, + metadata: filesource.Metadata{Path: "./executable"}, testPath: "executable", }, { name: "archive", - metadata: filesource.FileMetadata{Path: "./archive.tar.gz"}, + metadata: filesource.Metadata{Path: "./archive.tar.gz"}, testPath: "archive.tar.gz:/etc", }, } diff --git a/syft/format/internal/cyclonedxutil/helpers/decoder.go b/syft/format/internal/cyclonedxutil/helpers/decoder.go index b0efcf6618e..c9a72aeb00c 100644 --- a/syft/format/internal/cyclonedxutil/helpers/decoder.go +++ b/syft/format/internal/cyclonedxutil/helpers/decoder.go @@ -237,7 +237,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: filesource.FileMetadata{Path: c.Name}, + Metadata: filesource.Metadata{Path: c.Name}, } } return source.Description{} diff --git a/syft/format/internal/spdxutil/helpers/document_name.go b/syft/format/internal/spdxutil/helpers/document_name.go index 94898fdbd50..3529814d662 100644 --- a/syft/format/internal/spdxutil/helpers/document_name.go +++ b/syft/format/internal/spdxutil/helpers/document_name.go @@ -15,9 +15,9 @@ func DocumentName(src source.Description) string { switch metadata := src.Metadata.(type) { case stereoscopesource.ImageMetadata: return metadata.UserInput - case directorysource.DirectoryMetadata: + case directorysource.Metadata: return metadata.Path - case filesource.FileMetadata: + case filesource.Metadata: return metadata.Path default: return "unknown" diff --git a/syft/format/internal/spdxutil/helpers/document_name_test.go b/syft/format/internal/spdxutil/helpers/document_name_test.go index 54ce4f96866..a8553a005e4 100644 --- a/syft/format/internal/spdxutil/helpers/document_name_test.go +++ b/syft/format/internal/spdxutil/helpers/document_name_test.go @@ -37,14 +37,14 @@ func Test_DocumentName(t *testing.T) { { name: "directory", srcMetadata: source.Description{ - Metadata: directorysource.DirectoryMetadata{Path: "some/path/to/place"}, + Metadata: directorysource.Metadata{Path: "some/path/to/place"}, }, expected: "some/path/to/place", }, { name: "file", srcMetadata: source.Description{ - Metadata: filesource.FileMetadata{Path: "some/path/to/place"}, + Metadata: filesource.Metadata{Path: "some/path/to/place"}, }, expected: "some/path/to/place", }, @@ -52,7 +52,7 @@ func Test_DocumentName(t *testing.T) { name: "named", srcMetadata: source.Description{ Name: "some/name", - Metadata: filesource.FileMetadata{Path: "some/path/to/place"}, + Metadata: filesource.Metadata{Path: "some/path/to/place"}, }, expected: "some/name", }, diff --git a/syft/format/internal/spdxutil/helpers/document_namespace.go b/syft/format/internal/spdxutil/helpers/document_namespace.go index 204e58d0713..5f22806c34c 100644 --- a/syft/format/internal/spdxutil/helpers/document_namespace.go +++ b/syft/format/internal/spdxutil/helpers/document_namespace.go @@ -32,9 +32,9 @@ func DocumentNamespace(name string, src source.Description, desc sbom.Descriptor switch src.Metadata.(type) { case stereoscopesource.ImageMetadata: input = InputImage - case directorysource.DirectoryMetadata: + case directorysource.Metadata: input = InputDirectory - case filesource.FileMetadata: + case filesource.Metadata: input = InputFile } diff --git a/syft/format/internal/spdxutil/helpers/document_namespace_test.go b/syft/format/internal/spdxutil/helpers/document_namespace_test.go index 52989507810..dcc847c7076 100644 --- a/syft/format/internal/spdxutil/helpers/document_namespace_test.go +++ b/syft/format/internal/spdxutil/helpers/document_namespace_test.go @@ -40,7 +40,7 @@ func Test_documentNamespace(t *testing.T) { name: "directory", inputName: "my-name", src: source.Description{ - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "some/path/to/place", }, }, @@ -50,7 +50,7 @@ func Test_documentNamespace(t *testing.T) { name: "file", inputName: "my-name", src: source.Description{ - Metadata: filesource.FileMetadata{ + Metadata: filesource.Metadata{ Path: "some/path/to/place", }, }, diff --git a/syft/format/spdxtagvalue/encoder_test.go b/syft/format/spdxtagvalue/encoder_test.go index 6c277cd2d63..fcdf96f7eae 100644 --- a/syft/format/spdxtagvalue/encoder_test.go +++ b/syft/format/spdxtagvalue/encoder_test.go @@ -73,7 +73,7 @@ func TestSPDXJSONSPDXIDs(t *testing.T) { Relationships: nil, Source: source.Description{ Name: "foobar/baz", // in this case, foobar is used as the spdx document name - Metadata: directorysource.DirectoryMetadata{}, + Metadata: directorysource.Metadata{}, }, Descriptor: sbom.Descriptor{ Name: "syft", diff --git a/syft/format/syftjson/decoder_test.go b/syft/format/syftjson/decoder_test.go index fd57e91f4cf..4d8171f611e 100644 --- a/syft/format/syftjson/decoder_test.go +++ b/syft/format/syftjson/decoder_test.go @@ -264,7 +264,7 @@ func Test_encodeDecodeFileMetadata(t *testing.T) { ID: "some-id", Name: "some-name", Version: "some-version", - Metadata: filesource.FileMetadata{ + Metadata: filesource.Metadata{ Path: "/some-file-source-path", Digests: []file.Digest{ { diff --git a/syft/format/syftjson/model/source.go b/syft/format/syftjson/model/source.go index 8178675ec9e..6a5dc86b7e9 100644 --- a/syft/format/syftjson/model/source.go +++ b/syft/format/syftjson/model/source.go @@ -91,7 +91,7 @@ func extractPreSchemaV9Metadata(t string, target []byte) (interface{}, error) { cleanTarget = string(target) } - return directorysource.DirectoryMetadata{ + return directorysource.Metadata{ Path: cleanTarget, }, nil @@ -101,7 +101,7 @@ func extractPreSchemaV9Metadata(t string, target []byte) (interface{}, error) { cleanTarget = string(target) } - return filesource.FileMetadata{ + return filesource.Metadata{ Path: cleanTarget, }, nil diff --git a/syft/format/syftjson/model/source_test.go b/syft/format/syftjson/model/source_test.go index 24264c5007b..58a69f857fd 100644 --- a/syft/format/syftjson/model/source_test.go +++ b/syft/format/syftjson/model/source_test.go @@ -34,7 +34,7 @@ func TestSource_UnmarshalJSON(t *testing.T) { expected: &Source{ ID: "foobar", Type: "directory", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "/var/lib/foo", //Base: "/nope", // note: should be ignored entirely }, @@ -126,7 +126,7 @@ func TestSource_UnmarshalJSON(t *testing.T) { expected: &Source{ ID: "foobar", Type: "file", - Metadata: filesource.FileMetadata{ + Metadata: filesource.Metadata{ Path: "/var/lib/foo/go.mod", Digests: []file.Digest{ { @@ -190,7 +190,7 @@ func TestSource_UnmarshalJSON_PreSchemaV9(t *testing.T) { expectedSource: &Source{ ID: "foobar", Type: "directory", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "/var/lib/foo", }, }, @@ -206,7 +206,7 @@ func TestSource_UnmarshalJSON_PreSchemaV9(t *testing.T) { expectedSource: &Source{ ID: "foobar", Type: "directory", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "/var/lib/foo", }, }, @@ -290,7 +290,7 @@ func TestSource_UnmarshalJSON_PreSchemaV9(t *testing.T) { expectedSource: &Source{ ID: "foobar", Type: "file", - Metadata: filesource.FileMetadata{ + Metadata: filesource.Metadata{ Path: "/var/lib/foo/go.mod", }, }, diff --git a/syft/format/syftjson/to_format_model_test.go b/syft/format/syftjson/to_format_model_test.go index faf6bbf761c..6ac37d596ad 100644 --- a/syft/format/syftjson/to_format_model_test.go +++ b/syft/format/syftjson/to_format_model_test.go @@ -29,7 +29,7 @@ func Test_toSourceModel_IgnoreBase(t *testing.T) { name: "directory", src: source.Description{ ID: "test-id", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "some/path", Base: "some/base", }, @@ -62,7 +62,7 @@ func Test_toSourceModel(t *testing.T) { ID: "test-id", Name: "some-name", Version: "some-version", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "some/path", Base: "some/base", }, @@ -72,7 +72,7 @@ func Test_toSourceModel(t *testing.T) { Name: "some-name", Version: "some-version", Type: "directory", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "some/path", Base: "some/base", }, @@ -84,7 +84,7 @@ func Test_toSourceModel(t *testing.T) { ID: "test-id", Name: "some-name", Version: "some-version", - Metadata: filesource.FileMetadata{ + Metadata: filesource.Metadata{ Path: "some/path", Digests: []file.Digest{{Algorithm: "sha256", Value: "some-digest"}}, MIMEType: "text/plain", @@ -95,7 +95,7 @@ func Test_toSourceModel(t *testing.T) { Name: "some-name", Version: "some-version", Type: "file", - Metadata: filesource.FileMetadata{ + Metadata: filesource.Metadata{ Path: "some/path", Digests: []file.Digest{{Algorithm: "sha256", Value: "some-digest"}}, MIMEType: "text/plain", @@ -136,7 +136,7 @@ func Test_toSourceModel(t *testing.T) { name: "directory - no name/version", src: source.Description{ ID: "test-id", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "some/path", Base: "some/base", }, @@ -144,7 +144,7 @@ func Test_toSourceModel(t *testing.T) { expected: model.Source{ ID: "test-id", Type: "directory", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "some/path", Base: "some/base", }, @@ -154,7 +154,7 @@ func Test_toSourceModel(t *testing.T) { name: "file - no name/version", src: source.Description{ ID: "test-id", - Metadata: filesource.FileMetadata{ + Metadata: filesource.Metadata{ Path: "some/path", Digests: []file.Digest{{Algorithm: "sha256", Value: "some-digest"}}, MIMEType: "text/plain", @@ -163,7 +163,7 @@ func Test_toSourceModel(t *testing.T) { expected: model.Source{ ID: "test-id", Type: "file", - Metadata: filesource.FileMetadata{ + Metadata: filesource.Metadata{ Path: "some/path", Digests: []file.Digest{{Algorithm: "sha256", Value: "some-digest"}}, MIMEType: "text/plain", diff --git a/syft/format/syftjson/to_syft_model_test.go b/syft/format/syftjson/to_syft_model_test.go index 3c6f81f3aaa..982e2778a41 100644 --- a/syft/format/syftjson/to_syft_model_test.go +++ b/syft/format/syftjson/to_syft_model_test.go @@ -38,7 +38,7 @@ func Test_toSyftSourceData(t *testing.T) { Name: "some-name", Version: "some-version", Type: "directory", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "some/path", Base: "some/base", }, @@ -47,7 +47,7 @@ func Test_toSyftSourceData(t *testing.T) { ID: "the-id", Name: "some-name", Version: "some-version", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "some/path", Base: "some/base", }, @@ -60,7 +60,7 @@ func Test_toSyftSourceData(t *testing.T) { Name: "some-name", Version: "some-version", Type: "file", - Metadata: filesource.FileMetadata{ + Metadata: filesource.Metadata{ Path: "some/path", Digests: []file.Digest{{Algorithm: "sha256", Value: "some-digest"}}, MIMEType: "text/plain", @@ -70,7 +70,7 @@ func Test_toSyftSourceData(t *testing.T) { ID: "the-id", Name: "some-name", Version: "some-version", - Metadata: filesource.FileMetadata{ + Metadata: filesource.Metadata{ Path: "some/path", Digests: []file.Digest{{Algorithm: "sha256", Value: "some-digest"}}, MIMEType: "text/plain", @@ -110,14 +110,14 @@ func Test_toSyftSourceData(t *testing.T) { src: model.Source{ ID: "the-id", Type: "directory", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "some/path", Base: "some/base", }, }, expected: &source.Description{ ID: "the-id", - Metadata: directorysource.DirectoryMetadata{ + Metadata: directorysource.Metadata{ Path: "some/path", Base: "some/base", }, @@ -128,7 +128,7 @@ func Test_toSyftSourceData(t *testing.T) { src: model.Source{ ID: "the-id", Type: "file", - Metadata: filesource.FileMetadata{ + Metadata: filesource.Metadata{ Path: "some/path", Digests: []file.Digest{{Algorithm: "sha256", Value: "some-digest"}}, MIMEType: "text/plain", @@ -136,7 +136,7 @@ func Test_toSyftSourceData(t *testing.T) { }, expected: &source.Description{ ID: "the-id", - Metadata: filesource.FileMetadata{ + Metadata: filesource.Metadata{ Path: "some/path", Digests: []file.Digest{{Algorithm: "sha256", Value: "some-digest"}}, MIMEType: "text/plain", @@ -181,7 +181,7 @@ func Test_idsHaveChanged(t *testing.T) { s := toSyftModel(model.Document{ Source: model.Source{ Type: "file", - Metadata: filesource.FileMetadata{Path: "some/path"}, + Metadata: filesource.Metadata{Path: "some/path"}, }, Artifacts: []model.Package{ { diff --git a/syft/format/text/encoder.go b/syft/format/text/encoder.go index aee6c769059..cf9bb144a2d 100644 --- a/syft/format/text/encoder.go +++ b/syft/format/text/encoder.go @@ -40,9 +40,9 @@ func (e encoder) Encode(writer io.Writer, s sbom.SBOM) error { w.Init(writer, 0, 8, 0, '\t', tabwriter.AlignRight) switch metadata := s.Source.Metadata.(type) { - case directorysource.DirectoryMetadata: + case directorysource.Metadata: fmt.Fprintf(w, "[Path: %s]\n", metadata.Path) - case filesource.FileMetadata: + case filesource.Metadata: fmt.Fprintf(w, "[Path: %s]\n", metadata.Path) case stereoscopesource.ImageMetadata: fmt.Fprintln(w, "[Image]") diff --git a/syft/internal/sourcemetadata/discover_type_names.go b/syft/internal/sourcemetadata/discover_type_names.go index 473ad7f1d8f..f589a18ad59 100644 --- a/syft/internal/sourcemetadata/discover_type_names.go +++ b/syft/internal/sourcemetadata/discover_type_names.go @@ -12,6 +12,7 @@ import ( "slices" "strings" + "github.com/bmatcuk/doublestar/v4" "golang.org/x/mod/modfile" "github.com/anchore/syft/internal" @@ -45,7 +46,7 @@ func DiscoverTypes() ([]*TypeInfo, error) { if srcImportBase == "" { return nil, fmt.Errorf("unable to determine go module name from: %s", modFilePath) } - files, err := filepath.Glob(filepath.Join(root, "syft/source/**/*.go")) + files, err := doublestar.FilepathGlob(filepath.Join(root, "syft/source/**/*.go")) if err != nil { return nil, err } diff --git a/syft/internal/sourcemetadata/generate/main.go b/syft/internal/sourcemetadata/generate/main.go index cd2fe054a0a..2a2e57ad0f6 100644 --- a/syft/internal/sourcemetadata/generate/main.go +++ b/syft/internal/sourcemetadata/generate/main.go @@ -27,6 +27,7 @@ func main() { f := jen.NewFile("sourcemetadata") f.HeaderComment("DO NOT EDIT: generated by syft/internal/sourcemetadata/generate/main.go") for _, typ := range types { + // prevent jen from adding an unnecessary import alias: f.ImportName(typ.FileInfo.PkgPath, path.Base(typ.FileInfo.PkgPath)) } f.Comment("AllTypes returns a list of all source metadata types that syft supports (that are represented in the source.Description.Metadata field).") diff --git a/syft/internal/sourcemetadata/generated.go b/syft/internal/sourcemetadata/generated.go index 24f4203c850..a4d770ad817 100644 --- a/syft/internal/sourcemetadata/generated.go +++ b/syft/internal/sourcemetadata/generated.go @@ -10,5 +10,5 @@ import ( // AllTypes returns a list of all source metadata types that syft supports (that are represented in the source.Description.Metadata field). func AllTypes() []any { - return []any{directorysource.DirectoryMetadata{}, filesource.FileMetadata{}, stereoscopesource.ImageMetadata{}} + return []any{directorysource.Metadata{}, filesource.Metadata{}, stereoscopesource.ImageMetadata{}} } diff --git a/syft/internal/sourcemetadata/names.go b/syft/internal/sourcemetadata/names.go index dfada20926e..36fd5af0bc4 100644 --- a/syft/internal/sourcemetadata/names.go +++ b/syft/internal/sourcemetadata/names.go @@ -10,9 +10,9 @@ import ( ) var jsonNameFromType = map[reflect.Type][]string{ - reflect.TypeOf(directorysource.DirectoryMetadata{}): {"directory", "dir"}, - reflect.TypeOf(filesource.FileMetadata{}): {"file"}, - reflect.TypeOf(stereoscopesource.ImageMetadata{}): {"image"}, + reflect.TypeOf(directorysource.Metadata{}): {"directory", "dir"}, + reflect.TypeOf(filesource.Metadata{}): {"file"}, + reflect.TypeOf(stereoscopesource.ImageMetadata{}): {"image"}, } func AllTypeNames() []string { diff --git a/syft/source/directorysource/directory_source.go b/syft/source/directorysource/directory_source.go index cce49bad323..112b7e749c3 100644 --- a/syft/source/directorysource/directory_source.go +++ b/syft/source/directorysource/directory_source.go @@ -27,7 +27,7 @@ type Config struct { Alias source.Alias } -type DirectoryMetadata struct { +type Metadata struct { Path string `json:"path" yaml:"path"` Base string `json:"-" yaml:"-"` // though this is important, for display purposes it leaks too much information (abs paths) } @@ -130,7 +130,7 @@ func (s directorySource) Describe() source.Description { ID: string(s.id), Name: name, Version: version, - Metadata: DirectoryMetadata{ + Metadata: Metadata{ Path: s.config.Path, Base: s.config.Base, }, diff --git a/syft/source/directorysource/directory_source_test.go b/syft/source/directorysource/directory_source_test.go index ab58a9673c5..c78ff1fa95f 100644 --- a/syft/source/directorysource/directory_source_test.go +++ b/syft/source/directorysource/directory_source_test.go @@ -69,7 +69,7 @@ func TestNewFromDirectory(t *testing.T) { t.Cleanup(func() { require.NoError(t, src.Close()) }) - assert.Equal(t, test.input, src.Describe().Metadata.(DirectoryMetadata).Path) + assert.Equal(t, test.input, src.Describe().Metadata.(Metadata).Path) res, err := src.FileResolver(source.SquashedScope) require.NoError(t, err) diff --git a/syft/source/filesource/file_source.go b/syft/source/filesource/file_source.go index 86f08d40842..98c1c310adc 100644 --- a/syft/source/filesource/file_source.go +++ b/syft/source/filesource/file_source.go @@ -129,7 +129,7 @@ func (s fileSource) Describe() source.Description { ID: string(s.id), Name: name, Version: version, - Metadata: FileMetadata{ + Metadata: Metadata{ Path: s.config.Path, Digests: s.digests, MIMEType: s.mimeType, diff --git a/syft/source/filesource/file_source_metadata.go b/syft/source/filesource/file_source_metadata.go index 587cb5e283d..2ef2d253189 100644 --- a/syft/source/filesource/file_source_metadata.go +++ b/syft/source/filesource/file_source_metadata.go @@ -2,7 +2,7 @@ package filesource import "github.com/anchore/syft/syft/file" -type FileMetadata struct { +type Metadata struct { Path string `json:"path" yaml:"path"` Digests []file.Digest `json:"digests,omitempty" yaml:"digests,omitempty"` MIMEType string `json:"mimeType" yaml:"mimeType"` diff --git a/syft/source/filesource/file_source_test.go b/syft/source/filesource/file_source_test.go index 96839c2c417..85df25dd086 100644 --- a/syft/source/filesource/file_source_test.go +++ b/syft/source/filesource/file_source_test.go @@ -79,7 +79,7 @@ func TestNewFromFile(t *testing.T) { require.NoError(t, src.Close()) }) - assert.Equal(t, test.input, src.Describe().Metadata.(FileMetadata).Path) + assert.Equal(t, test.input, src.Describe().Metadata.(Metadata).Path) res, err := src.FileResolver(source.SquashedScope) require.NoError(t, err) @@ -134,7 +134,7 @@ func TestNewFromFile_WithArchive(t *testing.T) { require.NoError(t, src.Close()) }) - assert.Equal(t, archivePath, src.Describe().Metadata.(FileMetadata).Path) + assert.Equal(t, archivePath, src.Describe().Metadata.(Metadata).Path) res, err := src.FileResolver(source.SquashedScope) require.NoError(t, err)