mirror of
https://github.com/anchore/syft.git
synced 2026-11-03 07:56:36 +01:00
Populate Files and Relationship fields for spdx-json output (#507)
* update spdx22 Document model to include relationships field Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com> * update document and relationship to match current JSON spec https://github.com/spdx/spdx-spec/blob/development/v2.2.1/schemas/spdx-schema.json https://github.com/spdx/spdx-spec/pull/528 https://github.com/spdx/spdx-spec/pull/528#issuecomment-904180177 Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com> * update File struct based on SPDX schema Required fields: [ "SPDXID", "fileName", "copyrightText", "licenseConcluded" ] Signed-off-by: Christopher Angelo Phillips <christopher.phillips@anchore.com>
This commit is contained in:
@@ -11,7 +11,7 @@ import (
|
||||
|
||||
const ApkDbGlob = "**/lib/apk/db/installed"
|
||||
|
||||
var _ fileOwner = (*ApkMetadata)(nil)
|
||||
var _ FileOwner = (*ApkMetadata)(nil)
|
||||
|
||||
// ApkMetadata represents all captured data for a Alpine DB package entry.
|
||||
// See the following sources for more information:
|
||||
@@ -63,7 +63,7 @@ func (m ApkMetadata) PackageURL() string {
|
||||
return pURL.ToString()
|
||||
}
|
||||
|
||||
func (m ApkMetadata) ownedFiles() (result []string) {
|
||||
func (m ApkMetadata) OwnedFiles() (result []string) {
|
||||
s := strset.New()
|
||||
for _, f := range m.Files {
|
||||
if f.Path != "" {
|
||||
|
||||
@@ -73,7 +73,7 @@ func TestApkMetadata_pURL(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestApkMetadata_fileOwner(t *testing.T) {
|
||||
func TestApkMetadata_FileOwner(t *testing.T) {
|
||||
tests := []struct {
|
||||
metadata ApkMetadata
|
||||
expected []string
|
||||
@@ -107,7 +107,7 @@ func TestApkMetadata_fileOwner(t *testing.T) {
|
||||
t.Run(strings.Join(test.expected, ","), func(t *testing.T) {
|
||||
var i interface{}
|
||||
i = test.metadata
|
||||
actual := i.(fileOwner).ownedFiles()
|
||||
actual := i.(FileOwner).OwnedFiles()
|
||||
for _, d := range deep.Equal(test.expected, actual) {
|
||||
t.Errorf("diff: %+v", d)
|
||||
}
|
||||
|
||||
@@ -12,7 +12,7 @@ import (
|
||||
|
||||
const DpkgDbGlob = "**/var/lib/dpkg/{status,status.d/**}"
|
||||
|
||||
var _ fileOwner = (*DpkgMetadata)(nil)
|
||||
var _ FileOwner = (*DpkgMetadata)(nil)
|
||||
|
||||
// DpkgMetadata represents all captured data for a Debian package DB entry; available fields are described
|
||||
// at http://manpages.ubuntu.com/manpages/xenial/man1/dpkg-query.1.html in the --showformat section.
|
||||
@@ -55,7 +55,7 @@ func (m DpkgMetadata) PackageURL(d *distro.Distro) string {
|
||||
return pURL.ToString()
|
||||
}
|
||||
|
||||
func (m DpkgMetadata) ownedFiles() (result []string) {
|
||||
func (m DpkgMetadata) OwnedFiles() (result []string) {
|
||||
s := strset.New()
|
||||
for _, f := range m.Files {
|
||||
if f.Path != "" {
|
||||
|
||||
@@ -54,7 +54,7 @@ func TestDpkgMetadata_pURL(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestDpkgMetadata_fileOwner(t *testing.T) {
|
||||
func TestDpkgMetadata_FileOwner(t *testing.T) {
|
||||
tests := []struct {
|
||||
metadata DpkgMetadata
|
||||
expected []string
|
||||
@@ -88,7 +88,7 @@ func TestDpkgMetadata_fileOwner(t *testing.T) {
|
||||
t.Run(strings.Join(test.expected, ","), func(t *testing.T) {
|
||||
var i interface{}
|
||||
i = test.metadata
|
||||
actual := i.(fileOwner).ownedFiles()
|
||||
actual := i.(FileOwner).OwnedFiles()
|
||||
for _, d := range deep.Equal(test.expected, actual) {
|
||||
t.Errorf("diff: %+v", d)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,9 @@
|
||||
package pkg
|
||||
|
||||
type fileOwner interface {
|
||||
ownedFiles() []string
|
||||
// FileOwner is the interface that wraps OwnedFiles method.
|
||||
//
|
||||
// OwnedFiles returns a list of files that a piece of
|
||||
// package Metadata indicates are owned by the package.
|
||||
type FileOwner interface {
|
||||
OwnedFiles() []string
|
||||
}
|
||||
|
||||
@@ -55,11 +55,11 @@ func findOwnershipByFilesRelationships(catalog *Catalog) map[ID]map[ID]*strset.S
|
||||
}
|
||||
|
||||
// check to see if this is a file owner
|
||||
pkgFileOwner, ok := candidateOwnerPkg.Metadata.(fileOwner)
|
||||
pkgFileOwner, ok := candidateOwnerPkg.Metadata.(FileOwner)
|
||||
if !ok {
|
||||
continue
|
||||
}
|
||||
for _, ownedFilePath := range pkgFileOwner.ownedFiles() {
|
||||
for _, ownedFilePath := range pkgFileOwner.OwnedFiles() {
|
||||
if matchesAny(ownedFilePath, globsForbiddenFromBeingOwned) {
|
||||
// we skip over known exceptions to file ownership, such as the RPM package owning
|
||||
// the RPM DB path, otherwise the RPM package would "own" all RPMs, which is not intended
|
||||
|
||||
@@ -6,7 +6,7 @@ import (
|
||||
"github.com/scylladb/go-set/strset"
|
||||
)
|
||||
|
||||
var _ fileOwner = (*PythonPackageMetadata)(nil)
|
||||
var _ FileOwner = (*PythonPackageMetadata)(nil)
|
||||
|
||||
// PythonFileDigest represents the file metadata for a single file attributed to a python package.
|
||||
type PythonFileDigest struct {
|
||||
@@ -34,7 +34,7 @@ type PythonPackageMetadata struct {
|
||||
TopLevelPackages []string `json:"topLevelPackages,omitempty"`
|
||||
}
|
||||
|
||||
func (m PythonPackageMetadata) ownedFiles() (result []string) {
|
||||
func (m PythonPackageMetadata) OwnedFiles() (result []string) {
|
||||
s := strset.New()
|
||||
for _, f := range m.Files {
|
||||
if f.Path != "" {
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
"github.com/go-test/deep"
|
||||
)
|
||||
|
||||
func TestPythonMetadata_fileOwner(t *testing.T) {
|
||||
func TestPythonMetadata_FileOwner(t *testing.T) {
|
||||
tests := []struct {
|
||||
metadata PythonPackageMetadata
|
||||
expected []string
|
||||
@@ -41,7 +41,7 @@ func TestPythonMetadata_fileOwner(t *testing.T) {
|
||||
t.Run(strings.Join(test.expected, ","), func(t *testing.T) {
|
||||
var i interface{}
|
||||
i = test.metadata
|
||||
actual := i.(fileOwner).ownedFiles()
|
||||
actual := i.(FileOwner).OwnedFiles()
|
||||
for _, d := range deep.Equal(test.expected, actual) {
|
||||
t.Errorf("diff: %+v", d)
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@ import (
|
||||
|
||||
const RpmDbGlob = "**/var/lib/rpm/Packages"
|
||||
|
||||
var _ fileOwner = (*RpmdbMetadata)(nil)
|
||||
var _ FileOwner = (*RpmdbMetadata)(nil)
|
||||
|
||||
// RpmdbMetadata represents all captured data for a RPM DB package entry.
|
||||
type RpmdbMetadata struct {
|
||||
@@ -79,7 +79,7 @@ func (m RpmdbMetadata) PackageURL(d *distro.Distro) string {
|
||||
return pURL.ToString()
|
||||
}
|
||||
|
||||
func (m RpmdbMetadata) ownedFiles() (result []string) {
|
||||
func (m RpmdbMetadata) OwnedFiles() (result []string) {
|
||||
s := strset.New()
|
||||
for _, f := range m.Files {
|
||||
if f.Path != "" {
|
||||
|
||||
@@ -56,7 +56,7 @@ func TestRpmMetadata_pURL(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRpmMetadata_fileOwner(t *testing.T) {
|
||||
func TestRpmMetadata_FileOwner(t *testing.T) {
|
||||
tests := []struct {
|
||||
metadata RpmdbMetadata
|
||||
expected []string
|
||||
@@ -90,7 +90,7 @@ func TestRpmMetadata_fileOwner(t *testing.T) {
|
||||
t.Run(strings.Join(test.expected, ","), func(t *testing.T) {
|
||||
var i interface{}
|
||||
i = test.metadata
|
||||
actual := i.(fileOwner).ownedFiles()
|
||||
actual := i.(FileOwner).OwnedFiles()
|
||||
for _, d := range deep.Equal(test.expected, actual) {
|
||||
t.Errorf("diff: %+v", d)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user