mirror of
https://github.com/anchore/syft.git
synced 2026-11-04 08:26:38 +01:00
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>
54 lines
1.0 KiB
Go
54 lines
1.0 KiB
Go
package cyclonedxhelpers
|
|
|
|
import (
|
|
"github.com/CycloneDX/cyclonedx-go"
|
|
|
|
"github.com/anchore/syft/internal/spdxlicense"
|
|
"github.com/anchore/syft/syft/pkg"
|
|
)
|
|
|
|
func encodeLicenses(p pkg.Package) *cyclonedx.Licenses {
|
|
lc := cyclonedx.Licenses{}
|
|
for _, licenseName := range p.Licenses {
|
|
if value, exists := spdxlicense.ID(licenseName); exists {
|
|
lc = append(lc, cyclonedx.LicenseChoice{
|
|
License: &cyclonedx.License{
|
|
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
|
|
}
|
|
return nil
|
|
}
|
|
|
|
func decodeLicenses(c *cyclonedx.Component) (out []string) {
|
|
if c.Licenses != nil {
|
|
for _, l := range *c.Licenses {
|
|
if l.License != nil {
|
|
var lic string
|
|
switch {
|
|
case l.License.ID != "":
|
|
lic = l.License.ID
|
|
case l.License.Name != "":
|
|
lic = l.License.Name
|
|
default:
|
|
continue
|
|
}
|
|
out = append(out, lic)
|
|
}
|
|
}
|
|
}
|
|
return
|
|
}
|