mirror of
https://github.com/anchore/syft.git
synced 2026-10-31 14:36:33 +01:00
detect license ID from full text when incidentally provided as a value (#3876)
--------- Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com> Signed-off-by: Alex Goodman <wagoodman@users.noreply.github.com> Co-authored-by: Alex Goodman <wagoodman@users.noreply.github.com>
This commit is contained in:
co-authored by
Alex Goodman
parent
b4d717fb30
commit
f77d503892
@@ -107,6 +107,11 @@ func finalizePkgCatalogerResults(cfg CatalogingFactoryConfig, resolver file.Path
|
||||
}
|
||||
}
|
||||
|
||||
// we want to know if the user wants to preserve license content or not in the final SBOM
|
||||
// note: this looks incorrect, but pkg.License.Content is NOT used to compute the Package ID
|
||||
// this does NOT change the reproducibility of the Package ID
|
||||
applyLicenseContentRules(&p, cfg.LicenseConfig)
|
||||
|
||||
pkgs[i] = p
|
||||
}
|
||||
return pkgs, relationships
|
||||
@@ -262,3 +267,29 @@ func packageFileOwnershipRelationships(p pkg.Package, resolver file.PathResolver
|
||||
}
|
||||
return relationships, nil
|
||||
}
|
||||
|
||||
func applyLicenseContentRules(p *pkg.Package, cfg cataloging.LicenseConfig) {
|
||||
if p.Licenses.Empty() {
|
||||
return
|
||||
}
|
||||
|
||||
licenses := p.Licenses.ToSlice()
|
||||
for i := range licenses {
|
||||
l := &licenses[i]
|
||||
switch cfg.IncludeContent {
|
||||
case cataloging.LicenseContentIncludeUnknown:
|
||||
// we don't have an SPDX expression, which means we didn't find an SPDX license
|
||||
// include the unknown licenses content in the final SBOM
|
||||
if l.SPDXExpression != "" {
|
||||
licenses[i].Contents = ""
|
||||
}
|
||||
case cataloging.LicenseContentExcludeAll:
|
||||
// clear it all out
|
||||
licenses[i].Contents = ""
|
||||
case cataloging.LicenseContentIncludeAll:
|
||||
// always include the content
|
||||
}
|
||||
}
|
||||
|
||||
p.Licenses = pkg.NewLicenseSet(licenses...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user