mirror of
https://github.com/anchore/syft.git
synced 2026-11-04 08:26:38 +01:00
fix: add support for licenses not found on list (#1540)
Signed-off-by: Avi Deitcher <avi@deitcher.net>
This commit is contained in:
@@ -124,6 +124,7 @@ func ToFormatModel(s sbom.SBOM) *spdx.Document {
|
||||
Packages: toPackages(s.Artifacts.PackageCatalog, s),
|
||||
Files: toFiles(s),
|
||||
Relationships: relationships,
|
||||
OtherLicenses: toOtherLicenses(s.Artifacts.PackageCatalog),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -511,6 +512,28 @@ func toFileTypes(metadata *source.FileMetadata) (ty []string) {
|
||||
return ty
|
||||
}
|
||||
|
||||
func toOtherLicenses(catalog *pkg.Catalog) []*spdx.OtherLicense {
|
||||
licenses := map[string]bool{}
|
||||
for _, pkg := range catalog.Sorted() {
|
||||
for _, license := range parseLicenses(pkg.Licenses) {
|
||||
if strings.HasPrefix(license, spdxlicense.LicenseRefPrefix) {
|
||||
licenses[license] = true
|
||||
}
|
||||
}
|
||||
}
|
||||
var result []*spdx.OtherLicense
|
||||
for license := range licenses {
|
||||
// separate the actual ID from the prefix
|
||||
name := strings.TrimPrefix(license, spdxlicense.LicenseRefPrefix)
|
||||
result = append(result, &spdx.OtherLicense{
|
||||
LicenseIdentifier: license,
|
||||
LicenseName: name,
|
||||
ExtractedText: NONE, // we probably should have some extracted text here, but this is good enough for now
|
||||
})
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
// TODO: handle SPDX excludes file case
|
||||
// f file is an "excludes" file, skip it /* exclude SPDX analysis file(s) */
|
||||
// see: https://spdx.github.io/spdx-spec/v2.3/package-information/#79-package-verification-code-field
|
||||
|
||||
Reference in New Issue
Block a user