mirror of
https://github.com/anchore/syft.git
synced 2026-10-31 06:26:30 +01:00
fix: update license content filtering default case to be 'none' for no content returned
--------- Signed-off-by: Christopher Phillips <32073428+spiffcs@users.noreply.github.com>
This commit is contained in:
@@ -4,18 +4,13 @@ import (
|
||||
"fmt"
|
||||
|
||||
"github.com/anchore/clio"
|
||||
"github.com/anchore/syft/internal"
|
||||
"github.com/anchore/syft/syft/cataloging"
|
||||
)
|
||||
|
||||
type licenseConfig struct {
|
||||
Content cataloging.LicenseContent `yaml:"content" json:"content" mapstructure:"content"`
|
||||
// Deprecated: please use include-license-content instead
|
||||
IncludeUnknownLicenseContent *bool `yaml:"-" json:"-" mapstructure:"include-unknown-license-content"`
|
||||
|
||||
Coverage float64 `yaml:"coverage" json:"coverage" mapstructure:"coverage"`
|
||||
// Deprecated: please use coverage instead
|
||||
LicenseCoverage *float64 `yaml:"license-coverage" json:"license-coverage" mapstructure:"license-coverage"`
|
||||
|
||||
Content cataloging.LicenseContent `yaml:"content" json:"content" mapstructure:"content"`
|
||||
Coverage float64 `yaml:"coverage" json:"coverage" mapstructure:"coverage"`
|
||||
AvailableLicenseContent []cataloging.LicenseContent `yaml:"-" json:"-" mapstructure:"-"`
|
||||
}
|
||||
|
||||
@@ -25,43 +20,16 @@ var _ interface {
|
||||
|
||||
func (o *licenseConfig) DescribeFields(descriptions clio.FieldDescriptionSet) {
|
||||
descriptions.Add(&o.Content, fmt.Sprintf("include the content of licenses in the SBOM for a given syft scan; valid values are: %s", o.AvailableLicenseContent))
|
||||
descriptions.Add(&o.IncludeUnknownLicenseContent, `deprecated: please use 'license-content' instead`)
|
||||
|
||||
descriptions.Add(&o.Coverage, `adjust the percent as a fraction of the total text, in normalized words, that
|
||||
matches any valid license for the given inputs, expressed as a percentage across all of the licenses matched.`)
|
||||
descriptions.Add(&o.LicenseCoverage, `deprecated: please use 'coverage' instead`)
|
||||
}
|
||||
|
||||
func (o *licenseConfig) PostLoad() error {
|
||||
cfg := cataloging.DefaultLicenseConfig()
|
||||
defaultContent := cfg.IncludeContent
|
||||
defaultCoverage := cfg.Coverage
|
||||
|
||||
// if both legacy and new fields are specified, error out
|
||||
if o.IncludeUnknownLicenseContent != nil && o.Content != defaultContent {
|
||||
return fmt.Errorf("both 'include-unknown-license-content' and 'content' are set, please use only 'content'")
|
||||
validContent := internal.NewSet(o.AvailableLicenseContent...)
|
||||
if !validContent.Contains(o.Content) {
|
||||
return fmt.Errorf("could not use %q as license content option; valid values are: %v", o.Content, validContent.ToSlice())
|
||||
}
|
||||
|
||||
if o.LicenseCoverage != nil && o.Coverage != defaultCoverage {
|
||||
return fmt.Errorf("both 'license-coverage' and 'coverage' are set, please use only 'coverage'")
|
||||
}
|
||||
|
||||
// finalize the license content value
|
||||
if o.IncludeUnknownLicenseContent != nil {
|
||||
// convert 'include-unknown-license-content' -> 'license-content'
|
||||
v := cataloging.LicenseContentExcludeAll
|
||||
if *o.IncludeUnknownLicenseContent {
|
||||
v = cataloging.LicenseContentIncludeUnknown
|
||||
}
|
||||
o.Content = v
|
||||
}
|
||||
|
||||
// finalize the coverage value
|
||||
if o.LicenseCoverage != nil {
|
||||
// convert 'license-coverage' -> 'coverage'
|
||||
o.Coverage = *o.LicenseCoverage
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user