mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
add artifact.Identifiable by Identity() method
Signed-off-by: Alex Goodman <alex.goodman@anchore.com>
This commit is contained in:
parent
b08a11e46d
commit
69d2b1ba3c
@ -93,8 +93,8 @@ func toRelationshipModel(relationships []artifact.Relationship) []model.Relation
|
||||
result := make([]model.Relationship, len(relationships))
|
||||
for i, r := range relationships {
|
||||
result[i] = model.Relationship{
|
||||
Parent: string(r.From),
|
||||
Child: string(r.To),
|
||||
Parent: string(r.From.Identity()),
|
||||
Child: string(r.To.Identity()),
|
||||
Type: string(r.Type),
|
||||
Metadata: r.Data,
|
||||
}
|
||||
|
||||
@ -2,3 +2,7 @@ package artifact
|
||||
|
||||
// ID represents a unique value for each package added to a package catalog.
|
||||
type ID string
|
||||
|
||||
type Identifiable interface {
|
||||
Identity() ID
|
||||
}
|
||||
|
||||
@ -8,8 +8,8 @@ const (
|
||||
type RelationshipType string
|
||||
|
||||
type Relationship struct {
|
||||
From ID `json:"from"`
|
||||
To ID `json:"to"`
|
||||
From Identifiable `json:"from"`
|
||||
To Identifiable `json:"to"`
|
||||
Type RelationshipType `json:"type"`
|
||||
Data interface{} `json:"data,omitempty"`
|
||||
}
|
||||
|
||||
@ -28,8 +28,8 @@ func ownershipByFilesRelationships(catalog *Catalog) []artifact.Relationship {
|
||||
for parent, children := range relationships {
|
||||
for child, files := range children {
|
||||
edges = append(edges, artifact.Relationship{
|
||||
From: parent,
|
||||
To: child,
|
||||
From: catalog.byID[parent],
|
||||
To: catalog.byID[child],
|
||||
Type: artifact.OwnershipByFileOverlapRelationship,
|
||||
Data: ownershipByFilesMetadata{
|
||||
Files: files.List(),
|
||||
|
||||
@ -10,7 +10,16 @@ import (
|
||||
"github.com/anchore/syft/syft/source"
|
||||
)
|
||||
|
||||
type node struct {
|
||||
id string
|
||||
}
|
||||
|
||||
func (n node) Identity() artifact.ID {
|
||||
return artifact.ID(n.id)
|
||||
}
|
||||
|
||||
func TestOwnershipByFilesRelationship(t *testing.T) {
|
||||
|
||||
tests := []struct {
|
||||
name string
|
||||
pkgs []Package
|
||||
@ -58,8 +67,8 @@ func TestOwnershipByFilesRelationship(t *testing.T) {
|
||||
},
|
||||
expectedRelations: []artifact.Relationship{
|
||||
{
|
||||
From: "parent",
|
||||
To: "child",
|
||||
From: node{"parent"},
|
||||
To: node{"child"},
|
||||
Type: artifact.OwnershipByFileOverlapRelationship,
|
||||
Data: ownershipByFilesMetadata{
|
||||
Files: []string{
|
||||
@ -111,8 +120,8 @@ func TestOwnershipByFilesRelationship(t *testing.T) {
|
||||
},
|
||||
expectedRelations: []artifact.Relationship{
|
||||
{
|
||||
From: "parent",
|
||||
To: "child",
|
||||
From: node{"parent"},
|
||||
To: node{"child"},
|
||||
Type: artifact.OwnershipByFileOverlapRelationship,
|
||||
Data: ownershipByFilesMetadata{
|
||||
Files: []string{
|
||||
|
||||
@ -30,6 +30,11 @@ type Package struct {
|
||||
Metadata interface{} // additional data found while parsing the package source
|
||||
}
|
||||
|
||||
func (p Package) Identity() artifact.ID {
|
||||
// TODO: tie this into the fingerprint system on rebase
|
||||
return p.ID
|
||||
}
|
||||
|
||||
// Stringer to represent a package.
|
||||
func (p Package) String() string {
|
||||
return fmt.Sprintf("Pkg(type=%s, name=%s, version=%s)", p.Type, p.Name, p.Version)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user