mirror of
https://github.com/anchore/syft.git
synced 2025-11-17 16:33:21 +01:00
* Improve CycloneDX format output ## Additions to CycloneDX output * CPEs * Authors * Publishers * External References (Website, Distribution, VCS) * Description Signed-off-by: Sambhav Kothari <skothari44@bloomberg.net>
66 lines
1.6 KiB
Go
66 lines
1.6 KiB
Go
package cyclonedxhelpers
|
|
|
|
import (
|
|
"fmt"
|
|
|
|
"github.com/CycloneDX/cyclonedx-go"
|
|
"github.com/anchore/syft/syft/pkg"
|
|
)
|
|
|
|
func ExternalReferences(p pkg.Package) *[]cyclonedx.ExternalReference {
|
|
refs := []cyclonedx.ExternalReference{}
|
|
if hasMetadata(p) {
|
|
switch metadata := p.Metadata.(type) {
|
|
case pkg.ApkMetadata:
|
|
if metadata.URL != "" {
|
|
refs = append(refs, cyclonedx.ExternalReference{
|
|
URL: metadata.URL,
|
|
Type: cyclonedx.ERTypeDistribution,
|
|
})
|
|
}
|
|
case pkg.CargoPackageMetadata:
|
|
if metadata.Source != "" {
|
|
refs = append(refs, cyclonedx.ExternalReference{
|
|
URL: metadata.Source,
|
|
Type: cyclonedx.ERTypeDistribution,
|
|
})
|
|
}
|
|
case pkg.NpmPackageJSONMetadata:
|
|
if metadata.URL != "" {
|
|
refs = append(refs, cyclonedx.ExternalReference{
|
|
URL: metadata.URL,
|
|
Type: cyclonedx.ERTypeDistribution,
|
|
})
|
|
}
|
|
if metadata.Homepage != "" {
|
|
refs = append(refs, cyclonedx.ExternalReference{
|
|
URL: metadata.Homepage,
|
|
Type: cyclonedx.ERTypeWebsite,
|
|
})
|
|
}
|
|
case pkg.GemMetadata:
|
|
if metadata.Homepage != "" {
|
|
refs = append(refs, cyclonedx.ExternalReference{
|
|
URL: metadata.Homepage,
|
|
Type: cyclonedx.ERTypeWebsite,
|
|
})
|
|
}
|
|
case pkg.PythonPackageMetadata:
|
|
if metadata.DirectURLOrigin != nil && metadata.DirectURLOrigin.URL != "" {
|
|
ref := cyclonedx.ExternalReference{
|
|
URL: metadata.DirectURLOrigin.URL,
|
|
Type: cyclonedx.ERTypeVCS,
|
|
}
|
|
if metadata.DirectURLOrigin.CommitID != "" {
|
|
ref.Comment = fmt.Sprintf("commit: %s", metadata.DirectURLOrigin.CommitID)
|
|
}
|
|
refs = append(refs, ref)
|
|
}
|
|
}
|
|
}
|
|
if len(refs) > 0 {
|
|
return &refs
|
|
}
|
|
return nil
|
|
}
|