Replace distro type (#742)

* remove strong distro type

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* bump json schema to v3 (breaking distro shape)

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* fix linting

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* allow for v2 decoding of distro idLikes field in v3 json decoder

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* fix casing in simple linux release name

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>

* use discovered name as pretty name in simple linux release

Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
Alex Goodman
2022-01-12 12:13:42 -05:00
committed by GitHub
parent dfefd2ea4e
commit 706f291679
74 changed files with 2452 additions and 1136 deletions
+3 -3
View File
@@ -6,8 +6,8 @@ import (
"github.com/anchore/syft/internal/bus"
"github.com/anchore/syft/internal/log"
"github.com/anchore/syft/syft/artifact"
"github.com/anchore/syft/syft/distro"
"github.com/anchore/syft/syft/event"
"github.com/anchore/syft/syft/linux"
"github.com/anchore/syft/syft/pkg"
"github.com/anchore/syft/syft/pkg/cataloger/common/cpe"
"github.com/anchore/syft/syft/source"
@@ -41,7 +41,7 @@ func newMonitor() (*progress.Manual, *progress.Manual) {
// In order to efficiently retrieve contents from a underlying container image the content fetch requests are
// done in bulk. Specifically, all files of interest are collected from each catalogers and accumulated into a single
// request.
func Catalog(resolver source.FileResolver, theDistro *distro.Distro, catalogers ...Cataloger) (*pkg.Catalog, []artifact.Relationship, error) {
func Catalog(resolver source.FileResolver, release *linux.Release, catalogers ...Cataloger) (*pkg.Catalog, []artifact.Relationship, error) {
catalog := pkg.NewCatalog()
var allRelationships []artifact.Relationship
@@ -68,7 +68,7 @@ func Catalog(resolver source.FileResolver, theDistro *distro.Distro, catalogers
p.CPEs = cpe.Generate(p)
// generate PURL (note: this is excluded from package ID, so is safe to mutate)
p.PURL = generatePackageURL(p, theDistro)
p.PURL = generatePackageURL(p, release)
// create file-to-package relationships for files owned by the package
owningRelationships, err := packageFileOwnershipRelationships(p, resolver)
+4 -4
View File
@@ -5,18 +5,18 @@ import (
"strings"
"github.com/anchore/packageurl-go"
"github.com/anchore/syft/syft/distro"
"github.com/anchore/syft/syft/linux"
"github.com/anchore/syft/syft/pkg"
)
// generatePackageURL returns a package-URL representation of the given package (see https://github.com/package-url/purl-spec)
func generatePackageURL(p pkg.Package, d *distro.Distro) string {
func generatePackageURL(p pkg.Package, release *linux.Release) string {
// default to pURLs on the metadata
if p.Metadata != nil {
if i, ok := p.Metadata.(interface{ PackageURL() string }); ok {
return i.PackageURL()
} else if i, ok := p.Metadata.(interface{ PackageURL(*distro.Distro) string }); ok {
return i.PackageURL(d)
} else if i, ok := p.Metadata.(interface{ PackageURL(*linux.Release) string }); ok {
return i.PackageURL(release)
}
}
+10 -12
View File
@@ -3,7 +3,7 @@ package cataloger
import (
"testing"
"github.com/anchore/syft/syft/distro"
"github.com/anchore/syft/syft/linux"
"github.com/anchore/syft/syft/pkg"
"github.com/sergi/go-diff/diffmatchpatch"
)
@@ -12,7 +12,7 @@ func TestPackageURL(t *testing.T) {
tests := []struct {
name string
pkg pkg.Package
distro *distro.Distro
distro *linux.Release
expected string
}{
{
@@ -75,8 +75,8 @@ func TestPackageURL(t *testing.T) {
},
{
name: "deb with arch",
distro: &distro.Distro{
Type: distro.Ubuntu,
distro: &linux.Release{
ID: "ubuntu",
},
pkg: pkg.Package{
Name: "bad-name",
@@ -92,8 +92,8 @@ func TestPackageURL(t *testing.T) {
},
{
name: "deb with epoch",
distro: &distro.Distro{
Type: distro.CentOS,
distro: &linux.Release{
ID: "centos",
},
pkg: pkg.Package{
Name: "bad-name",
@@ -111,8 +111,8 @@ func TestPackageURL(t *testing.T) {
},
{
name: "deb with nil epoch",
distro: &distro.Distro{
Type: distro.CentOS,
distro: &linux.Release{
ID: "centos",
},
pkg: pkg.Package{
Name: "bad-name",
@@ -129,10 +129,8 @@ func TestPackageURL(t *testing.T) {
expected: "pkg:rpm/centos/name@0.1.0-3?arch=amd64",
},
{
name: "deb with unknown distro",
distro: &distro.Distro{
Type: distro.UnknownDistroType,
},
name: "deb with unknown distro",
distro: nil,
pkg: pkg.Package{
Name: "name",
Version: "v0.1.0",