mirror of
https://github.com/anchore/syft.git
synced 2026-02-13 19:16:43 +01:00
Normalize syft-json output (#1194)
This commit is contained in:
parent
586d3fe77f
commit
1c7b7c5f8a
@ -215,6 +215,15 @@ func toRelationshipModel(relationships []artifact.Relationship) []model.Relation
|
|||||||
Metadata: r.Data,
|
Metadata: r.Data,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sort.Slice(result, func(i, j int) bool {
|
||||||
|
if iParent, jParent := result[i].Parent, result[j].Parent; iParent != jParent {
|
||||||
|
return iParent < jParent
|
||||||
|
}
|
||||||
|
if iChild, jChild := result[i].Child, result[j].Child; iChild != jChild {
|
||||||
|
return iChild < jChild
|
||||||
|
}
|
||||||
|
return result[i].Type < result[j].Type
|
||||||
|
})
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -203,6 +203,10 @@ func (c *Catalog) Sorted(types ...Type) (pkgs []Package) {
|
|||||||
iLocations := pkgs[i].Locations.ToSlice()
|
iLocations := pkgs[i].Locations.ToSlice()
|
||||||
jLocations := pkgs[j].Locations.ToSlice()
|
jLocations := pkgs[j].Locations.ToSlice()
|
||||||
if pkgs[i].Type == pkgs[j].Type && len(iLocations) > 0 && len(jLocations) > 0 {
|
if pkgs[i].Type == pkgs[j].Type && len(iLocations) > 0 && len(jLocations) > 0 {
|
||||||
|
if iLocations[0].String() == jLocations[0].String() {
|
||||||
|
// compare IDs as a final fallback
|
||||||
|
return pkgs[i].ID() < pkgs[j].ID()
|
||||||
|
}
|
||||||
return iLocations[0].String() < jLocations[0].String()
|
return iLocations[0].String() < jLocations[0].String()
|
||||||
}
|
}
|
||||||
return pkgs[i].Type < pkgs[j].Type
|
return pkgs[i].Type < pkgs[j].Type
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
package pkg
|
package pkg
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"sort"
|
||||||
|
|
||||||
"github.com/anchore/syft/internal/log"
|
"github.com/anchore/syft/internal/log"
|
||||||
"github.com/anchore/syft/syft/artifact"
|
"github.com/anchore/syft/syft/artifact"
|
||||||
"github.com/bmatcuk/doublestar/v4"
|
"github.com/bmatcuk/doublestar/v4"
|
||||||
@ -34,12 +36,14 @@ func RelationshipsByFileOwnership(catalog *Catalog) []artifact.Relationship {
|
|||||||
var edges []artifact.Relationship
|
var edges []artifact.Relationship
|
||||||
for parentID, children := range relationships {
|
for parentID, children := range relationships {
|
||||||
for childID, files := range children {
|
for childID, files := range children {
|
||||||
|
fs := files.List()
|
||||||
|
sort.Strings(fs)
|
||||||
edges = append(edges, artifact.Relationship{
|
edges = append(edges, artifact.Relationship{
|
||||||
From: catalog.byID[parentID],
|
From: catalog.byID[parentID],
|
||||||
To: catalog.byID[childID],
|
To: catalog.byID[childID],
|
||||||
Type: artifact.OwnershipByFileOverlapRelationship,
|
Type: artifact.OwnershipByFileOverlapRelationship,
|
||||||
Data: ownershipByFilesMetadata{
|
Data: ownershipByFilesMetadata{
|
||||||
Files: files.List(),
|
Files: fs,
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user