Skip to content

Commit

Permalink
chore: naming without stutter
Browse files Browse the repository at this point in the history
Signed-off-by: Keith Zantow <[email protected]>
  • Loading branch information
kzantow committed Feb 23, 2024
1 parent 6bc1241 commit a723b8e
Show file tree
Hide file tree
Showing 30 changed files with 81 additions and 79 deletions.
2 changes: 1 addition & 1 deletion syft/create_sbom_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions syft/create_sbom_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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...
},
Expand Down
4 changes: 2 additions & 2 deletions syft/format/common/cyclonedxhelpers/to_format_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions syft/format/common/spdxhelpers/to_format_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions syft/format/common/spdxhelpers/to_format_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
Expand Down Expand Up @@ -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{
{
Expand Down
8 changes: 4 additions & 4 deletions syft/format/common/spdxhelpers/to_syft_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -232,15 +232,15 @@ 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{
Metadata: stereoscopesource.ImageMetadata{},
}
case helpers.InputDirectory:
return source.Description{
Metadata: directorysource.DirectoryMetadata{},
Metadata: directorysource.Metadata{},
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions syft/format/common/spdxhelpers/to_syft_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,15 +202,15 @@ 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",
expected: stereoscopesource.ImageMetadata{},
},
{
namespace: "https://anchore.com/syft/dir/d42b01d0-7325-409b-b03f-74082935c4d3",
expected: directorysource.DirectoryMetadata{},
expected: directorysource.Metadata{},
},
{
namespace: "https://another-host/blob/123",
Expand Down Expand Up @@ -479,7 +479,7 @@ func Test_convertToAndFromFormat(t *testing.T) {
source: source.Description{
ID: "DocumentRoot-Directory-.",
Name: ".",
Metadata: directorysource.DirectoryMetadata{
Metadata: directorysource.Metadata{
Path: ".",
},
},
Expand All @@ -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",
},
},
Expand All @@ -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{
{
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions syft/format/github/internal/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions syft/format/github/internal/model/model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
}
Expand Down
2 changes: 1 addition & 1 deletion syft/format/internal/cyclonedxutil/helpers/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
4 changes: 2 additions & 2 deletions syft/format/internal/spdxutil/helpers/document_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions syft/format/internal/spdxutil/helpers/document_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,22 +37,22 @@ 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",
},
{
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",
},
Expand Down
4 changes: 2 additions & 2 deletions syft/format/internal/spdxutil/helpers/document_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
},
},
Expand All @@ -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",
},
},
Expand Down
2 changes: 1 addition & 1 deletion syft/format/spdxtagvalue/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion syft/format/syftjson/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
{
Expand Down
4 changes: 2 additions & 2 deletions syft/format/syftjson/model/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func extractPreSchemaV9Metadata(t string, target []byte) (interface{}, error) {
cleanTarget = string(target)
}

return directorysource.DirectoryMetadata{
return directorysource.Metadata{
Path: cleanTarget,
}, nil

Expand All @@ -101,7 +101,7 @@ func extractPreSchemaV9Metadata(t string, target []byte) (interface{}, error) {
cleanTarget = string(target)
}

return filesource.FileMetadata{
return filesource.Metadata{
Path: cleanTarget,
}, nil

Expand Down
10 changes: 5 additions & 5 deletions syft/format/syftjson/model/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down Expand Up @@ -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{
{
Expand Down Expand Up @@ -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",
},
},
Expand All @@ -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",
},
},
Expand Down Expand Up @@ -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",
},
},
Expand Down
Loading

0 comments on commit a723b8e

Please sign in to comment.