Skip to content

Commit

Permalink
rename sbom.PackageCatalog to sbom.Packages (#1773)
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
  • Loading branch information
wagoodman authored May 1, 2023
1 parent 10c3cc2 commit 5f3d4d2
Show file tree
Hide file tree
Showing 34 changed files with 56 additions and 56 deletions.
2 changes: 1 addition & 1 deletion cmd/syft/cli/eventloop/tasks.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func generateCatalogPackagesTask(app *config.Application) (Task, error) {
task := func(results *sbom.Artifacts, src *source.Source) ([]artifact.Relationship, error) {
packageCatalog, relationships, theDistro, err := syft.CatalogPackages(src, app.ToCatalogerConfig())

results.PackageCatalog = packageCatalog
results.Packages = packageCatalog
results.LinuxDistribution = theDistro

return relationships, err
Expand Down
4 changes: 2 additions & 2 deletions syft/formats/common/cyclonedxhelpers/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func ToSyftModel(bom *cyclonedx.BOM) (*sbom.SBOM, error) {

s := &sbom.SBOM{
Artifacts: sbom.Artifacts{
PackageCatalog: pkg.NewCollection(),
Packages: pkg.NewCollection(),
LinuxDistribution: linuxReleaseFromComponents(*bom.Components),
},
Source: extractComponents(bom.Metadata),
Expand Down Expand Up @@ -95,7 +95,7 @@ func collectPackages(component *cyclonedx.Component, s *sbom.SBOM, idMap map[str
}
// TODO there must be a better way than needing to call this manually:
p.SetID()
s.Artifacts.PackageCatalog.Add(*p)
s.Artifacts.Packages.Add(*p)
}

if component.Components != nil {
Expand Down
4 changes: 2 additions & 2 deletions syft/formats/common/cyclonedxhelpers/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ func Test_decode(t *testing.T) {
assert.Equal(t, e.ver, sbom.Artifacts.LinuxDistribution.VersionID)
}
if e.pkg != "" {
for p := range sbom.Artifacts.PackageCatalog.Enumerate() {
for p := range sbom.Artifacts.Packages.Enumerate() {
if e.pkg != p.Name {
continue
}
Expand Down Expand Up @@ -238,7 +238,7 @@ func Test_decode(t *testing.T) {
if e.relation != "" {
foundRelation := false
for _, r := range sbom.Relationships {
p := sbom.Artifacts.PackageCatalog.Package(r.To.ID())
p := sbom.Artifacts.Packages.Package(r.To.ID())
if e.relation == p.Name {
foundRelation = true
break
Expand Down
2 changes: 1 addition & 1 deletion syft/formats/common/cyclonedxhelpers/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func ToFormatModel(s sbom.SBOM) *cyclonedx.BOM {
cdxBOM.SerialNumber = uuid.New().URN()
cdxBOM.Metadata = toBomDescriptor(internal.ApplicationName, s.Descriptor.Version, s.Source)

packages := s.Artifacts.PackageCatalog.Sorted()
packages := s.Artifacts.Packages.Sorted()
components := make([]cyclonedx.Component, len(packages))
for i, p := range packages {
components[i] = encodeComponent(p)
Expand Down
4 changes: 2 additions & 2 deletions syft/formats/common/spdxhelpers/to_format_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,10 +123,10 @@ func ToFormatModel(s sbom.SBOM) *spdx.Document {
// Cardinality: optional, one
CreatorComment: "",
},
Packages: toPackages(s.Artifacts.PackageCatalog, s),
Packages: toPackages(s.Artifacts.Packages, s),
Files: toFiles(s),
Relationships: relationships,
OtherLicenses: toOtherLicenses(s.Artifacts.PackageCatalog),
OtherLicenses: toOtherLicenses(s.Artifacts.Packages),
}
}

Expand Down
4 changes: 2 additions & 2 deletions syft/formats/common/spdxhelpers/to_syft_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ToSyftModel(doc *spdx.Document) (*sbom.SBOM, error) {
s := &sbom.SBOM{
Source: src,
Artifacts: sbom.Artifacts{
PackageCatalog: pkg.NewCollection(),
Packages: pkg.NewCollection(),
FileMetadata: map[source.Coordinates]source.FileMetadata{},
FileDigests: map[source.Coordinates][]file.Digest{},
LinuxDistribution: findLinuxReleaseByPURL(doc),
Expand Down Expand Up @@ -110,7 +110,7 @@ func collectSyftPackages(s *sbom.SBOM, spdxIDMap map[string]interface{}, doc *sp
for _, p := range doc.Packages {
syftPkg := toSyftPackage(p)
spdxIDMap[string(p.PackageSPDXIdentifier)] = syftPkg
s.Artifacts.PackageCatalog.Add(*syftPkg)
s.Artifacts.Packages.Add(*syftPkg)
}
}

Expand Down
2 changes: 1 addition & 1 deletion syft/formats/common/spdxhelpers/to_syft_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func TestToSyftModel(t *testing.T) {

assert.NotNil(t, sbom)

pkgs := sbom.Artifacts.PackageCatalog.Sorted()
pkgs := sbom.Artifacts.Packages.Sorted()

assert.Len(t, pkgs, 2)

Expand Down
2 changes: 1 addition & 1 deletion syft/formats/cyclonedxjson/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Test_decodeJSON(t *testing.T) {
split = strings.SplitN(pkg, ":", 2)
name = split[0]
version = split[1]
for p := range bom.Artifacts.PackageCatalog.Enumerate() {
for p := range bom.Artifacts.Packages.Enumerate() {
if p.Name == name {
assert.Equal(t, version, p.Version)
continue pkgs
Expand Down
2 changes: 1 addition & 1 deletion syft/formats/cyclonedxxml/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func Test_decodeXML(t *testing.T) {
split = strings.SplitN(pkg, ":", 2)
name = split[0]
version = split[1]
for p := range bom.Artifacts.PackageCatalog.Enumerate() {
for p := range bom.Artifacts.Packages.Enumerate() {
if p.Name == name {
assert.Equal(t, version, p.Version)
continue pkgs
Expand Down
2 changes: 1 addition & 1 deletion syft/formats/github/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ func toPath(s source.Metadata, p pkg.Package) string {
func toGithubManifests(s *sbom.SBOM) Manifests {
manifests := map[string]*Manifest{}

for _, p := range s.Artifacts.PackageCatalog.Sorted() {
for _, p := range s.Artifacts.Packages.Sorted() {
path := toPath(s.Source, p)
manifest, ok := manifests[path]
if !ok {
Expand Down
4 changes: 2 additions & 2 deletions syft/formats/github/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func Test_toGithubModel(t *testing.T) {
VersionID: "18.04",
IDLike: []string{"debian"},
},
PackageCatalog: pkg.NewCollection(),
Packages: pkg.NewCollection(),
},
}
for _, p := range []pkg.Package{
Expand Down Expand Up @@ -71,7 +71,7 @@ func Test_toGithubModel(t *testing.T) {
nil,
"",
).ToString()
s.Artifacts.PackageCatalog.Add(p)
s.Artifacts.Packages.Add(p)
}

actual := toGithubModel(&s)
Expand Down
8 changes: 4 additions & 4 deletions syft/formats/internal/testutils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func ImageInput(t testing.TB, testImage string, options ...ImageOption) sbom.SBO

return sbom.SBOM{
Artifacts: sbom.Artifacts{
PackageCatalog: catalog,
Packages: catalog,
LinuxDistribution: &linux.Release{
PrettyName: "debian",
Name: "debian",
Expand Down Expand Up @@ -200,7 +200,7 @@ func DirectoryInput(t testing.TB) sbom.SBOM {

return sbom.SBOM{
Artifacts: sbom.Artifacts{
PackageCatalog: catalog,
Packages: catalog,
LinuxDistribution: &linux.Release{
PrettyName: "debian",
Name: "debian",
Expand Down Expand Up @@ -231,7 +231,7 @@ func DirectoryInputWithAuthorField(t testing.TB) sbom.SBOM {

return sbom.SBOM{
Artifacts: sbom.Artifacts{
PackageCatalog: catalog,
Packages: catalog,
LinuxDistribution: &linux.Release{
PrettyName: "debian",
Name: "debian",
Expand Down Expand Up @@ -359,7 +359,7 @@ func newDirectoryCatalogWithAuthorField() *pkg.Collection {

//nolint:gosec
func AddSampleFileRelationships(s *sbom.SBOM) {
catalog := s.Artifacts.PackageCatalog.Sorted()
catalog := s.Artifacts.Packages.Sorted()
s.Artifacts.FileMetadata = map[source.Coordinates]source.FileMetadata{}

files := []string{"/f1", "/f2", "/d1/f3", "/d2/f4", "/z1/f5", "/a1/f6"}
Expand Down
4 changes: 2 additions & 2 deletions syft/formats/spdxjson/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ func TestSPDXJSONDecoder(t *testing.T) {
}

if test.packages != nil {
assert.Equal(t, sbom.Artifacts.PackageCatalog.PackageCount(), len(test.packages))
assert.Equal(t, sbom.Artifacts.Packages.PackageCount(), len(test.packages))

packages:
for _, pkgName := range test.packages {
for _, p := range sbom.Artifacts.PackageCatalog.Sorted() {
for _, p := range sbom.Artifacts.Packages.Sorted() {
if p.Name == pkgName {
continue packages
}
Expand Down
2 changes: 1 addition & 1 deletion syft/formats/spdxtagvalue/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestSPDXJSONSPDXIDs(t *testing.T) {
Format(),
sbom.SBOM{
Artifacts: sbom.Artifacts{
PackageCatalog: pkg.NewCollection(pkgs...),
Packages: pkg.NewCollection(pkgs...),
},
Relationships: nil,
Source: source.Metadata{
Expand Down
4 changes: 2 additions & 2 deletions syft/formats/syftjson/decoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ func TestEncodeDecodeCycle(t *testing.T) {
t.Errorf("metadata difference: %+v", d)
}

actualPackages := actualSBOM.Artifacts.PackageCatalog.Sorted()
for idx, p := range originalSBOM.Artifacts.PackageCatalog.Sorted() {
actualPackages := actualSBOM.Artifacts.Packages.Sorted()
for idx, p := range originalSBOM.Artifacts.Packages.Sorted() {
if !assert.Equal(t, p.Name, actualPackages[idx].Name) {
t.Errorf("different package at idx=%d: %s vs %s", idx, p.Name, actualPackages[idx].Name)
continue
Expand Down
2 changes: 1 addition & 1 deletion syft/formats/syftjson/encoder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestEncodeFullJSONDocument(t *testing.T) {

s := sbom.SBOM{
Artifacts: sbom.Artifacts{
PackageCatalog: catalog,
Packages: catalog,
FileMetadata: map[source.Coordinates]source.FileMetadata{
source.NewLocation("/a/place").Coordinates: {
Mode: 0775,
Expand Down
2 changes: 1 addition & 1 deletion syft/formats/syftjson/to_format_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func ToFormatModel(s sbom.SBOM) model.Document {
}

return model.Document{
Artifacts: toPackageModels(s.Artifacts.PackageCatalog),
Artifacts: toPackageModels(s.Artifacts.Packages),
ArtifactRelationships: toRelationshipModel(s.Relationships),
Files: toFile(s),
Secrets: toSecrets(s.Artifacts.Secrets),
Expand Down
2 changes: 1 addition & 1 deletion syft/formats/syftjson/to_syft_model.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func toSyftModel(doc model.Document) (*sbom.SBOM, error) {

return &sbom.SBOM{
Artifacts: sbom.Artifacts{
PackageCatalog: catalog,
Packages: catalog,
FileMetadata: fileArtifacts.FileMetadata,
FileDigests: fileArtifacts.FileDigests,
LinuxDistribution: toSyftLinuxRelease(doc.Distro),
Expand Down
4 changes: 2 additions & 2 deletions syft/formats/syftjson/to_syft_model_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ func Test_idsHaveChanged(t *testing.T) {

r := s.Relationships[0]

from := s.Artifacts.PackageCatalog.Package(r.From.ID())
from := s.Artifacts.Packages.Package(r.From.ID())
assert.NotNil(t, from)
assert.Equal(t, "pkg-1", from.Name)

to := s.Artifacts.PackageCatalog.Package(r.To.ID())
to := s.Artifacts.Packages.Package(r.To.ID())
assert.NotNil(t, to)
assert.Equal(t, "pkg-2", to.Name)
}
Expand Down
2 changes: 1 addition & 1 deletion syft/formats/table/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func encoder(output io.Writer, s sbom.SBOM) error {
var rows [][]string

columns := []string{"Name", "Version", "Type"}
for _, p := range s.Artifacts.PackageCatalog.Sorted() {
for _, p := range s.Artifacts.Packages.Sorted() {
row := []string{
p.Name,
p.Version,
Expand Down
2 changes: 1 addition & 1 deletion syft/formats/text/encoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func encoder(output io.Writer, s sbom.SBOM) error {

// populate artifacts...
rows := 0
for _, p := range s.Artifacts.PackageCatalog.Sorted() {
for _, p := range s.Artifacts.Packages.Sorted() {
fmt.Fprintf(w, "[%s]\n", p.Name)
fmt.Fprintln(w, " Version:\t", p.Version)
fmt.Fprintln(w, " Type:\t", string(p.Type))
Expand Down
2 changes: 1 addition & 1 deletion syft/pkg/cataloger/sbom/cataloger.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func parseSBOM(_ source.FileResolver, _ *generic.Environment, reader source.Loca

var pkgs []pkg.Package
var relationships []artifact.Relationship
for _, p := range s.Artifacts.PackageCatalog.Sorted() {
for _, p := range s.Artifacts.Packages.Sorted() {
// replace all locations on the package with the location of the SBOM file.
// Why not keep the original list of locations? Since the "locations" field is meant to capture
// where there is evidence of this file, and the catalogers have not run against any file other than,
Expand Down
2 changes: 1 addition & 1 deletion syft/sbom/sbom.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type SBOM struct {
}

type Artifacts struct {
PackageCatalog *pkg.Collection
Packages *pkg.Collection
FileMetadata map[source.Coordinates]source.FileMetadata
FileDigests map[source.Coordinates][]file.Digest
FileContents map[source.Coordinates]string
Expand Down
4 changes: 2 additions & 2 deletions test/integration/all_layers_squashed_comparison_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ func Test_AllLayersIncludesSquashed(t *testing.T) {
allLayers, _ := catalogFixtureImage(t, "image-suse-all-layers", source.AllLayersScope, nil)
squashed, _ := catalogFixtureImage(t, "image-suse-all-layers", source.SquashedScope, nil)

lenAllLayers := len(allLayers.Artifacts.PackageCatalog.Sorted())
lenSquashed := len(squashed.Artifacts.PackageCatalog.Sorted())
lenAllLayers := len(allLayers.Artifacts.Packages.Sorted())
lenSquashed := len(squashed.Artifacts.Packages.Sorted())

if lenAllLayers < lenSquashed {
t.Errorf("squashed has more packages than all-layers: %d > %d", lenSquashed, lenAllLayers)
Expand Down
14 changes: 7 additions & 7 deletions test/integration/catalog_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ func TestPkgCoverageImage(t *testing.T) {
t.Run(c.name, func(t *testing.T) {
pkgCount := 0

for a := range sbom.Artifacts.PackageCatalog.Enumerate(c.pkgType) {
for a := range sbom.Artifacts.Packages.Enumerate(c.pkgType) {
if a.Language.String() != "" {
observedLanguages.Add(a.Language.String())
}
Expand All @@ -127,7 +127,7 @@ func TestPkgCoverageImage(t *testing.T) {

if pkgCount != len(c.pkgInfo)+c.duplicates {
t.Logf("Discovered packages of type %+v", c.pkgType)
for a := range sbom.Artifacts.PackageCatalog.Enumerate(c.pkgType) {
for a := range sbom.Artifacts.Packages.Enumerate(c.pkgType) {
t.Log(" ", a)
}
t.Fatalf("unexpected package count: %d!=%d", pkgCount, len(c.pkgInfo))
Expand Down Expand Up @@ -176,7 +176,7 @@ func TestPkgCoverageDirectory(t *testing.T) {
t.Run(test.name, func(t *testing.T) {
actualPkgCount := 0

for actualPkg := range sbom.Artifacts.PackageCatalog.Enumerate(test.pkgType) {
for actualPkg := range sbom.Artifacts.Packages.Enumerate(test.pkgType) {
observedLanguages.Add(actualPkg.Language.String())
observedPkgs.Add(string(actualPkg.Type))

Expand Down Expand Up @@ -207,7 +207,7 @@ func TestPkgCoverageDirectory(t *testing.T) {
}

if actualPkgCount != len(test.pkgInfo)+test.duplicates {
for actualPkg := range sbom.Artifacts.PackageCatalog.Enumerate(test.pkgType) {
for actualPkg := range sbom.Artifacts.Packages.Enumerate(test.pkgType) {
t.Log(" ", actualPkg)
}
t.Fatalf("unexpected package count: %d!=%d", actualPkgCount, len(test.pkgInfo))
Expand Down Expand Up @@ -246,7 +246,7 @@ func TestPkgCoverageCatalogerConfiguration(t *testing.T) {
definedLanguages := internal.NewStringSet()
definedLanguages.Add("rust")

for actualPkg := range sbom.Artifacts.PackageCatalog.Enumerate() {
for actualPkg := range sbom.Artifacts.Packages.Enumerate() {
observedLanguages.Add(actualPkg.Language.String())
}

Expand All @@ -270,7 +270,7 @@ func TestPkgCoverageImage_HasEvidence(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {

for a := range sbom.Artifacts.PackageCatalog.Enumerate(c.pkgType) {
for a := range sbom.Artifacts.Packages.Enumerate(c.pkgType) {
assert.NotEmpty(t, a.Locations.ToSlice(), "package %q has no locations (type=%q)", a.Name, a.Type)
for _, l := range a.Locations.ToSlice() {
if _, exists := l.Annotations[pkg.EvidenceAnnotationKey]; !exists {
Expand Down Expand Up @@ -300,7 +300,7 @@ func TestPkgCoverageDirectory_HasEvidence(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {

for a := range sbom.Artifacts.PackageCatalog.Enumerate(c.pkgType) {
for a := range sbom.Artifacts.Packages.Enumerate(c.pkgType) {
assert.NotEmpty(t, a.Locations.ToSlice(), "package %q has no locations (type=%q)", a.Name, a.Type)
for _, l := range a.Locations.ToSlice() {
if _, exists := l.Annotations[pkg.EvidenceAnnotationKey]; !exists {
Expand Down
2 changes: 1 addition & 1 deletion test/integration/mariner_distroless_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestMarinerDistroless(t *testing.T) {

expectedPkgs := 12
actualPkgs := 0
for range sbom.Artifacts.PackageCatalog.Enumerate(pkg.RpmPkg) {
for range sbom.Artifacts.Packages.Enumerate(pkg.RpmPkg) {
actualPkgs += 1
}

Expand Down
4 changes: 2 additions & 2 deletions test/integration/node_packages_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func TestNpmPackageLockDirectory(t *testing.T) {

foundPackages := internal.NewStringSet()

for actualPkg := range sbom.Artifacts.PackageCatalog.Enumerate(pkg.NpmPkg) {
for actualPkg := range sbom.Artifacts.Packages.Enumerate(pkg.NpmPkg) {
for _, actualLocation := range actualPkg.Locations.ToSlice() {
if strings.Contains(actualLocation.RealPath, "node_modules") {
t.Errorf("found packages from package-lock.json in node_modules: %s", actualLocation)
Expand All @@ -36,7 +36,7 @@ func TestYarnPackageLockDirectory(t *testing.T) {
foundPackages := internal.NewStringSet()
expectedPackages := internal.NewStringSet("async@0.9.2", "async@3.2.3", "merge-objects@1.0.5", "should-type@1.3.0", "@4lolo/resize-observer-polyfill@1.5.2")

for actualPkg := range sbom.Artifacts.PackageCatalog.Enumerate(pkg.NpmPkg) {
for actualPkg := range sbom.Artifacts.Packages.Enumerate(pkg.NpmPkg) {
for _, actualLocation := range actualPkg.Locations.ToSlice() {
if strings.Contains(actualLocation.RealPath, "node_modules") {
t.Errorf("found packages from yarn.lock in node_modules: %s", actualLocation)
Expand Down
Loading

0 comments on commit 5f3d4d2

Please sign in to comment.