mirror of
https://github.com/anchore/syft.git
synced 2025-11-18 08:53:15 +01:00
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
package sbom
|
|
|
|
import (
|
|
"github.com/anchore/syft/syft/artifact"
|
|
"github.com/anchore/syft/syft/distro"
|
|
"github.com/anchore/syft/syft/file"
|
|
"github.com/anchore/syft/syft/pkg"
|
|
"github.com/anchore/syft/syft/source"
|
|
)
|
|
|
|
type SBOM struct {
|
|
Artifacts Artifacts
|
|
Relationships []artifact.Relationship
|
|
Source source.Metadata
|
|
}
|
|
|
|
type Artifacts struct {
|
|
PackageCatalog *pkg.Catalog
|
|
FileMetadata map[source.Coordinates]source.FileMetadata
|
|
FileDigests map[source.Coordinates][]file.Digest
|
|
FileClassifications map[source.Coordinates][]file.Classification
|
|
FileContents map[source.Coordinates]string
|
|
Secrets map[source.Coordinates][]file.SearchResult
|
|
Distro *distro.Distro
|
|
}
|
|
|
|
func AllCoordinates(sbom SBOM) []source.Coordinates {
|
|
set := source.NewCoordinateSet()
|
|
for coordinates := range sbom.Artifacts.FileMetadata {
|
|
set.Add(coordinates)
|
|
}
|
|
for coordinates := range sbom.Artifacts.FileContents {
|
|
set.Add(coordinates)
|
|
}
|
|
for coordinates := range sbom.Artifacts.FileClassifications {
|
|
set.Add(coordinates)
|
|
}
|
|
for coordinates := range sbom.Artifacts.FileDigests {
|
|
set.Add(coordinates)
|
|
}
|
|
for _, relationship := range sbom.Relationships {
|
|
for _, coordinates := range extractCoordinates(relationship) {
|
|
set.Add(coordinates)
|
|
}
|
|
}
|
|
return set.ToSlice()
|
|
}
|
|
|
|
func extractCoordinates(relationship artifact.Relationship) (results []source.Coordinates) {
|
|
if coordinates, exists := relationship.From.(source.Coordinates); exists {
|
|
results = append(results, coordinates)
|
|
}
|
|
|
|
if coordinates, exists := relationship.To.(source.Coordinates); exists {
|
|
results = append(results, coordinates)
|
|
}
|
|
|
|
return results
|
|
}
|