mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 23:16:30 +01:00
1577 spdxlicense generate (#1691)
Update the license_list.go to have more permissible inputs for greater SPDXID matching. EX: GPL3 gpl3 gpl-3 and GPL-3 can all map to GPL-3.0-only By moving all strings to lower and removing the "-" we're able to return valid SPDX license ID for a greater diversity of input strings. --------- Signed-off-by: Christopher Phillips <christopher.phillips@anchore.com>
This commit is contained in:
@@ -10,14 +10,21 @@ import (
|
||||
func encodeLicenses(p pkg.Package) *cyclonedx.Licenses {
|
||||
lc := cyclonedx.Licenses{}
|
||||
for _, licenseName := range p.Licenses {
|
||||
if value, other, exists := spdxlicense.ID(licenseName); exists {
|
||||
if value, exists := spdxlicense.ID(licenseName); exists {
|
||||
lc = append(lc, cyclonedx.LicenseChoice{
|
||||
License: &cyclonedx.License{
|
||||
ID: value,
|
||||
Name: other,
|
||||
ID: value,
|
||||
},
|
||||
})
|
||||
continue
|
||||
}
|
||||
|
||||
// not found so append the licenseName as is
|
||||
lc = append(lc, cyclonedx.LicenseChoice{
|
||||
License: &cyclonedx.License{
|
||||
Name: licenseName,
|
||||
},
|
||||
})
|
||||
}
|
||||
if len(lc) > 0 {
|
||||
return &lc
|
||||
|
||||
@@ -39,12 +39,12 @@ func License(p pkg.Package) string {
|
||||
|
||||
func parseLicenses(raw []string) (parsedLicenses []string) {
|
||||
for _, l := range raw {
|
||||
if value, other, exists := spdxlicense.ID(l); exists {
|
||||
parsed := value
|
||||
if other != "" {
|
||||
parsed = spdxlicense.LicenseRefPrefix + other
|
||||
}
|
||||
parsedLicenses = append(parsedLicenses, parsed)
|
||||
if value, exists := spdxlicense.ID(l); exists {
|
||||
parsedLicenses = append(parsedLicenses, value)
|
||||
} else {
|
||||
// we did not find a valid SPDX license ID so treat as separate license
|
||||
otherLicense := spdxlicense.LicenseRefPrefix + l
|
||||
parsedLicenses = append(parsedLicenses, otherLicense)
|
||||
}
|
||||
}
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user