mirror of
https://github.com/anchore/syft.git
synced 2026-11-01 06:56:40 +01:00
chore(deps): update Go version (#4773)
Signed-off-by: anchore-oss-update-bot <anchore-oss-update-bot@users.noreply.github.com> Co-authored-by: anchore-oss-update-bot <anchore-oss-update-bot@users.noreply.github.com>
This commit is contained in:
co-authored by
anchore-oss-update-bot
parent
26e87c7cd3
commit
5b58ec96b7
@@ -5,8 +5,8 @@ import "reflect"
|
||||
// EvaluateCapabilities evaluates a capability set against a given configuration
|
||||
// and returns the effective capability values as a flat map.
|
||||
// Example: {"license": false, "dependency.depth": ["direct", "indirect"]}
|
||||
func EvaluateCapabilities(caps CapabilitySet, config map[string]interface{}) map[string]interface{} {
|
||||
result := make(map[string]interface{})
|
||||
func EvaluateCapabilities(caps CapabilitySet, config map[string]any) map[string]any {
|
||||
result := make(map[string]any)
|
||||
for _, capField := range caps {
|
||||
result[capField.Name] = EvaluateField(capField, config)
|
||||
}
|
||||
@@ -16,7 +16,7 @@ func EvaluateCapabilities(caps CapabilitySet, config map[string]interface{}) map
|
||||
// EvaluateField evaluates a single capability field against a configuration.
|
||||
// Conditions are evaluated in order, and the first matching condition's value is returned.
|
||||
// If no conditions match, the default value is returned.
|
||||
func EvaluateField(capField CapabilityField, config map[string]interface{}) interface{} {
|
||||
func EvaluateField(capField CapabilityField, config map[string]any) any {
|
||||
// check conditions in order (first match wins)
|
||||
for _, cond := range capField.Conditions {
|
||||
if ConditionMatches(cond.When, config) {
|
||||
@@ -30,7 +30,7 @@ func EvaluateField(capField CapabilityField, config map[string]interface{}) inte
|
||||
// ConditionMatches checks if a condition's when clause matches the given configuration.
|
||||
// All fields in the when clause must match the config (AND logic).
|
||||
// Returns true if all key-value pairs in when match the config.
|
||||
func ConditionMatches(when map[string]interface{}, config map[string]interface{}) bool {
|
||||
func ConditionMatches(when map[string]any, config map[string]any) bool {
|
||||
// all fields in when must match config (AND logic)
|
||||
for key, expectedValue := range when {
|
||||
actualValue, exists := config[key]
|
||||
@@ -46,7 +46,7 @@ func ConditionMatches(when map[string]interface{}, config map[string]interface{}
|
||||
|
||||
// valuesEqual compares two values for equality, handling different types appropriately.
|
||||
// Uses reflect.DeepEqual for complex types like slices and maps.
|
||||
func valuesEqual(a, b interface{}) bool {
|
||||
func valuesEqual(a, b any) bool {
|
||||
// handle nil cases
|
||||
if a == nil && b == nil {
|
||||
return true
|
||||
|
||||
@@ -10,8 +10,8 @@ import (
|
||||
func Test_valuesEqual(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
a interface{}
|
||||
b interface{}
|
||||
a any
|
||||
b any
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
@@ -123,47 +123,47 @@ func Test_valuesEqual(t *testing.T) {
|
||||
func TestConditionMatches(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
when map[string]interface{}
|
||||
config map[string]interface{}
|
||||
when map[string]any
|
||||
config map[string]any
|
||||
want bool
|
||||
}{
|
||||
{
|
||||
name: "empty when clause matches anything",
|
||||
when: map[string]interface{}{},
|
||||
config: map[string]interface{}{"key": "value"},
|
||||
when: map[string]any{},
|
||||
config: map[string]any{"key": "value"},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "empty when clause with empty config",
|
||||
when: map[string]interface{}{},
|
||||
config: map[string]interface{}{},
|
||||
when: map[string]any{},
|
||||
config: map[string]any{},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "single key match",
|
||||
when: map[string]interface{}{"SearchLocalModCacheLicenses": true},
|
||||
config: map[string]interface{}{"SearchLocalModCacheLicenses": true},
|
||||
when: map[string]any{"SearchLocalModCacheLicenses": true},
|
||||
config: map[string]any{"SearchLocalModCacheLicenses": true},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "single key mismatch",
|
||||
when: map[string]interface{}{"SearchLocalModCacheLicenses": true},
|
||||
config: map[string]interface{}{"SearchLocalModCacheLicenses": false},
|
||||
when: map[string]any{"SearchLocalModCacheLicenses": true},
|
||||
config: map[string]any{"SearchLocalModCacheLicenses": false},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "key missing from config",
|
||||
when: map[string]interface{}{"SearchLocalModCacheLicenses": true},
|
||||
config: map[string]interface{}{},
|
||||
when: map[string]any{"SearchLocalModCacheLicenses": true},
|
||||
config: map[string]any{},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "multiple keys all match",
|
||||
when: map[string]interface{}{
|
||||
when: map[string]any{
|
||||
"SearchLocalModCacheLicenses": true,
|
||||
"UseNetwork": true,
|
||||
},
|
||||
config: map[string]interface{}{
|
||||
config: map[string]any{
|
||||
"SearchLocalModCacheLicenses": true,
|
||||
"UseNetwork": true,
|
||||
"ExtraKey": "ignored",
|
||||
@@ -172,11 +172,11 @@ func TestConditionMatches(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "multiple keys one mismatch",
|
||||
when: map[string]interface{}{
|
||||
when: map[string]any{
|
||||
"SearchLocalModCacheLicenses": true,
|
||||
"UseNetwork": true,
|
||||
},
|
||||
config: map[string]interface{}{
|
||||
config: map[string]any{
|
||||
"SearchLocalModCacheLicenses": true,
|
||||
"UseNetwork": false,
|
||||
},
|
||||
@@ -184,31 +184,31 @@ func TestConditionMatches(t *testing.T) {
|
||||
},
|
||||
{
|
||||
name: "multiple keys one missing",
|
||||
when: map[string]interface{}{
|
||||
when: map[string]any{
|
||||
"SearchLocalModCacheLicenses": true,
|
||||
"UseNetwork": true,
|
||||
},
|
||||
config: map[string]interface{}{
|
||||
config: map[string]any{
|
||||
"SearchLocalModCacheLicenses": true,
|
||||
},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
name: "string value match",
|
||||
when: map[string]interface{}{"mode": "fast"},
|
||||
config: map[string]interface{}{"mode": "fast"},
|
||||
when: map[string]any{"mode": "fast"},
|
||||
config: map[string]any{"mode": "fast"},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "slice value match",
|
||||
when: map[string]interface{}{"formats": []string{"json", "yaml"}},
|
||||
config: map[string]interface{}{"formats": []string{"json", "yaml"}},
|
||||
when: map[string]any{"formats": []string{"json", "yaml"}},
|
||||
config: map[string]any{"formats": []string{"json", "yaml"}},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
name: "slice value mismatch",
|
||||
when: map[string]interface{}{"formats": []string{"json", "yaml"}},
|
||||
config: map[string]interface{}{"formats": []string{"json", "xml"}},
|
||||
when: map[string]any{"formats": []string{"json", "yaml"}},
|
||||
config: map[string]any{"formats": []string{"json", "xml"}},
|
||||
want: false,
|
||||
},
|
||||
}
|
||||
@@ -225,8 +225,8 @@ func TestEvaluateField(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
capField CapabilityField
|
||||
config map[string]interface{}
|
||||
want interface{}
|
||||
config map[string]any
|
||||
want any
|
||||
}{
|
||||
{
|
||||
name: "no conditions returns default",
|
||||
@@ -235,7 +235,7 @@ func TestEvaluateField(t *testing.T) {
|
||||
Default: false,
|
||||
Conditions: nil,
|
||||
},
|
||||
config: map[string]interface{}{},
|
||||
config: map[string]any{},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
@@ -245,7 +245,7 @@ func TestEvaluateField(t *testing.T) {
|
||||
Default: false,
|
||||
Conditions: []CapabilityCondition{},
|
||||
},
|
||||
config: map[string]interface{}{},
|
||||
config: map[string]any{},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
@@ -260,7 +260,7 @@ func TestEvaluateField(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
config: map[string]interface{}{"SearchLocalModCacheLicenses": true},
|
||||
config: map[string]any{"SearchLocalModCacheLicenses": true},
|
||||
want: true,
|
||||
},
|
||||
{
|
||||
@@ -275,7 +275,7 @@ func TestEvaluateField(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
config: map[string]interface{}{"SearchLocalModCacheLicenses": false},
|
||||
config: map[string]any{"SearchLocalModCacheLicenses": false},
|
||||
want: false,
|
||||
},
|
||||
{
|
||||
@@ -294,7 +294,7 @@ func TestEvaluateField(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
config: map[string]interface{}{
|
||||
config: map[string]any{
|
||||
"SearchLocalModCacheLicenses": true,
|
||||
"SearchRemoteLicenses": true,
|
||||
},
|
||||
@@ -316,7 +316,7 @@ func TestEvaluateField(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
config: map[string]interface{}{
|
||||
config: map[string]any{
|
||||
"SearchLocalModCacheLicenses": false,
|
||||
"SearchRemoteLicenses": true,
|
||||
},
|
||||
@@ -338,7 +338,7 @@ func TestEvaluateField(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
config: map[string]interface{}{
|
||||
config: map[string]any{
|
||||
"SearchLocalModCacheLicenses": false,
|
||||
"SearchRemoteLicenses": false,
|
||||
},
|
||||
@@ -351,7 +351,7 @@ func TestEvaluateField(t *testing.T) {
|
||||
Default: []string{"direct", "indirect"},
|
||||
Conditions: nil,
|
||||
},
|
||||
config: map[string]interface{}{},
|
||||
config: map[string]any{},
|
||||
want: []string{"direct", "indirect"},
|
||||
},
|
||||
{
|
||||
@@ -369,7 +369,7 @@ func TestEvaluateField(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
config: map[string]interface{}{
|
||||
config: map[string]any{
|
||||
"EnableFeatureA": true,
|
||||
"EnableFeatureB": true,
|
||||
},
|
||||
@@ -390,7 +390,7 @@ func TestEvaluateField(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
config: map[string]interface{}{
|
||||
config: map[string]any{
|
||||
"EnableFeatureA": true,
|
||||
"EnableFeatureB": false,
|
||||
},
|
||||
@@ -412,14 +412,14 @@ func TestEvaluateCapabilities(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
caps CapabilitySet
|
||||
config map[string]interface{}
|
||||
want map[string]interface{}
|
||||
config map[string]any
|
||||
want map[string]any
|
||||
}{
|
||||
{
|
||||
name: "empty capability set",
|
||||
caps: CapabilitySet{},
|
||||
config: map[string]interface{}{},
|
||||
want: map[string]interface{}{},
|
||||
config: map[string]any{},
|
||||
want: map[string]any{},
|
||||
},
|
||||
{
|
||||
name: "single capability no conditions",
|
||||
@@ -429,8 +429,8 @@ func TestEvaluateCapabilities(t *testing.T) {
|
||||
Default: false,
|
||||
},
|
||||
},
|
||||
config: map[string]interface{}{},
|
||||
want: map[string]interface{}{
|
||||
config: map[string]any{},
|
||||
want: map[string]any{
|
||||
"license": false,
|
||||
},
|
||||
},
|
||||
@@ -448,8 +448,8 @@ func TestEvaluateCapabilities(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
config: map[string]interface{}{"SearchLocalModCacheLicenses": true},
|
||||
want: map[string]interface{}{
|
||||
config: map[string]any{"SearchLocalModCacheLicenses": true},
|
||||
want: map[string]any{
|
||||
"license": true,
|
||||
},
|
||||
},
|
||||
@@ -475,8 +475,8 @@ func TestEvaluateCapabilities(t *testing.T) {
|
||||
Default: "flat",
|
||||
},
|
||||
},
|
||||
config: map[string]interface{}{"SearchLocalModCacheLicenses": true},
|
||||
want: map[string]interface{}{
|
||||
config: map[string]any{"SearchLocalModCacheLicenses": true},
|
||||
want: map[string]any{
|
||||
"license": true,
|
||||
"dependency.depth": []string{"direct", "indirect"},
|
||||
"dependency.edges": "flat",
|
||||
@@ -512,11 +512,11 @@ func TestEvaluateCapabilities(t *testing.T) {
|
||||
Default: false,
|
||||
},
|
||||
},
|
||||
config: map[string]interface{}{
|
||||
config: map[string]any{
|
||||
"SearchLocalModCacheLicenses": false,
|
||||
"SearchRemoteLicenses": true,
|
||||
},
|
||||
want: map[string]interface{}{
|
||||
want: map[string]any{
|
||||
"license": true,
|
||||
"dependency.depth": []string{"direct", "indirect"},
|
||||
"dependency.edges": "flat",
|
||||
@@ -526,10 +526,10 @@ func TestEvaluateCapabilities(t *testing.T) {
|
||||
{
|
||||
name: "nil capability set",
|
||||
caps: nil,
|
||||
config: map[string]interface{}{
|
||||
config: map[string]any{
|
||||
"anything": true,
|
||||
},
|
||||
want: map[string]interface{}{},
|
||||
want: map[string]any{},
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -15,9 +15,9 @@ import (
|
||||
|
||||
// AppConfigField represents an application-level configuration field for catalogers
|
||||
type AppConfigField struct {
|
||||
Key string // e.g., "golang.search-local-mod-cache-licenses"
|
||||
Description string // extracted from DescribeFields() method
|
||||
DefaultValue interface{} // extracted from Default*() functions
|
||||
Key string // e.g., "golang.search-local-mod-cache-licenses"
|
||||
Description string // extracted from DescribeFields() method
|
||||
DefaultValue any // extracted from Default*() functions
|
||||
}
|
||||
|
||||
// extractEcosystemConfigFieldsFromCatalog parses catalog.go and extracts the ecosystem-specific
|
||||
@@ -390,7 +390,7 @@ func extractDescriptionsFromDescribeFields(f *ast.File) map[string]string {
|
||||
}
|
||||
|
||||
// extractNestedAppConfigs handles nested config structs like golang.MainModuleVersion
|
||||
func extractNestedAppConfigs(f *ast.File, parentKey, parentFieldName string, fieldType ast.Expr, descriptions map[string]string, defaults map[string]interface{}) []AppConfigField {
|
||||
func extractNestedAppConfigs(f *ast.File, parentKey, parentFieldName string, fieldType ast.Expr, descriptions map[string]string, defaults map[string]any) []AppConfigField {
|
||||
var configs []AppConfigField
|
||||
|
||||
// find the nested struct type
|
||||
@@ -449,8 +449,8 @@ func extractNestedAppConfigs(f *ast.File, parentKey, parentFieldName string, fie
|
||||
description := descriptions[nestedPath]
|
||||
|
||||
// try to get default value from nested defaults
|
||||
var defaultValue interface{}
|
||||
if nestedDefaults, ok := defaults[parentFieldName].(map[string]interface{}); ok {
|
||||
var defaultValue any
|
||||
if nestedDefaults, ok := defaults[parentFieldName].(map[string]any); ok {
|
||||
defaultValue = nestedDefaults[fieldName]
|
||||
}
|
||||
|
||||
@@ -465,8 +465,8 @@ func extractNestedAppConfigs(f *ast.File, parentKey, parentFieldName string, fie
|
||||
}
|
||||
|
||||
// extractAppDefaultValues extracts default values from the default*Config function
|
||||
func extractAppDefaultValues(f *ast.File) map[string]interface{} {
|
||||
defaults := make(map[string]interface{})
|
||||
func extractAppDefaultValues(f *ast.File) map[string]any {
|
||||
defaults := make(map[string]any)
|
||||
|
||||
for _, decl := range f.Decls {
|
||||
funcDecl, ok := decl.(*ast.FuncDecl)
|
||||
@@ -518,7 +518,7 @@ func extractAppDefaultValues(f *ast.File) map[string]interface{} {
|
||||
}
|
||||
|
||||
// extractAppValue extracts a Go value from an AST expression
|
||||
func extractAppValue(expr ast.Expr) interface{} {
|
||||
func extractAppValue(expr ast.Expr) any {
|
||||
switch v := expr.(type) {
|
||||
case *ast.BasicLit:
|
||||
// string, int, bool literals
|
||||
@@ -543,7 +543,7 @@ func extractAppValue(expr ast.Expr) interface{} {
|
||||
}
|
||||
case *ast.CompositeLit:
|
||||
// nested struct literal
|
||||
nested := make(map[string]interface{})
|
||||
nested := make(map[string]any)
|
||||
for _, elt := range v.Elts {
|
||||
kvExpr, ok := elt.(*ast.KeyValueExpr)
|
||||
if !ok {
|
||||
|
||||
@@ -340,7 +340,7 @@ func TestExtractAppValue(t *testing.T) {
|
||||
tests := []struct {
|
||||
name string
|
||||
src string
|
||||
want interface{}
|
||||
want any
|
||||
}{
|
||||
{
|
||||
name: "string literal",
|
||||
@@ -406,7 +406,7 @@ func TestExtractAppValue_NestedStruct(t *testing.T) {
|
||||
got := extractAppValue(compositeLit)
|
||||
|
||||
// verify it's a map with the expected values
|
||||
gotMap, ok := got.(map[string]interface{})
|
||||
gotMap, ok := got.(map[string]any)
|
||||
require.True(t, ok)
|
||||
require.Equal(t, "value", gotMap["Field1"])
|
||||
require.Equal(t, true, gotMap["Field2"])
|
||||
|
||||
@@ -567,8 +567,8 @@ func resolveImportedConstant(pkgName, constName string, ctx *parseContext) strin
|
||||
// resolveImportPath converts an import path to a file system path
|
||||
func resolveImportPath(importPath, repoRoot string) string {
|
||||
// for github.com/anchore/syft/... imports, convert to repo-relative path
|
||||
if strings.HasPrefix(importPath, "github.com/anchore/syft/") {
|
||||
relPath := strings.TrimPrefix(importPath, "github.com/anchore/syft/")
|
||||
if after, ok := strings.CutPrefix(importPath, "github.com/anchore/syft/"); ok {
|
||||
relPath := after
|
||||
return filepath.Join(repoRoot, relPath)
|
||||
}
|
||||
|
||||
|
||||
@@ -214,7 +214,7 @@ func mapCatalogerToEcosystem(cat capabilities.CatalogerEntry) string {
|
||||
}
|
||||
|
||||
// updateNodeTreeEcosystem updates an existing ecosystem YAML node tree
|
||||
func updateNodeTreeEcosystem(rootNode *yaml.Node, doc interface{}) error {
|
||||
func updateNodeTreeEcosystem(rootNode *yaml.Node, doc any) error {
|
||||
var newNode yaml.Node
|
||||
if err := newNode.Encode(doc); err != nil {
|
||||
return err
|
||||
@@ -242,7 +242,7 @@ func updateNodeTreeEcosystem(rootNode *yaml.Node, doc interface{}) error {
|
||||
}
|
||||
|
||||
// updateNodeTreeAppConfig updates appconfig YAML node tree
|
||||
func updateNodeTreeAppConfig(rootNode *yaml.Node, doc interface{}) error {
|
||||
func updateNodeTreeAppConfig(rootNode *yaml.Node, doc any) error {
|
||||
return updateNodeTreeEcosystem(rootNode, doc)
|
||||
}
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ const requireParserObservations = false
|
||||
|
||||
// metadataTypeCoverageExceptions lists metadata types that are allowed to not be represented in any cataloger
|
||||
var metadataTypeCoverageExceptions = strset.New(
|
||||
reflect.TypeOf(pkg.MicrosoftKbPatch{}).Name(),
|
||||
reflect.TypeFor[pkg.MicrosoftKbPatch]().Name(),
|
||||
)
|
||||
|
||||
// packageTypeCoverageExceptions lists package types that are allowed to not be represented in any cataloger
|
||||
@@ -408,7 +408,7 @@ func TestCapabilityValueTypes(t *testing.T) {
|
||||
}
|
||||
|
||||
// validateCapabilityValueType checks if a value matches the expected type for a capability field
|
||||
func validateCapabilityValueType(fieldPath string, value interface{}) error {
|
||||
func validateCapabilityValueType(fieldPath string, value any) error {
|
||||
if value == nil {
|
||||
return nil // nil is acceptable
|
||||
}
|
||||
@@ -428,7 +428,7 @@ func validateCapabilityValueType(fieldPath string, value interface{}) error {
|
||||
switch v := value.(type) {
|
||||
case []string:
|
||||
// ok
|
||||
case []interface{}:
|
||||
case []any:
|
||||
// check each element is a string
|
||||
for i, elem := range v {
|
||||
if _, ok := elem.(string); !ok {
|
||||
@@ -829,7 +829,6 @@ func TestCapabilityEvidenceFieldReferences(t *testing.T) {
|
||||
|
||||
// validate each evidence reference
|
||||
for _, ref := range allReferences {
|
||||
ref := ref // capture for subtest
|
||||
|
||||
// create test name
|
||||
testName := ref.catalogerName
|
||||
@@ -989,7 +988,6 @@ func validateCapabilitiesFilled(t *testing.T, catalogers []capabilities.Cataloge
|
||||
checkCompletenessTestsEnabled(t)
|
||||
|
||||
for _, c := range catalogers {
|
||||
c := c // capture loop variable for subtest
|
||||
|
||||
t.Run(c.Name, func(t *testing.T) {
|
||||
if c.Type == "generic" {
|
||||
@@ -997,7 +995,6 @@ func validateCapabilitiesFilled(t *testing.T, catalogers []capabilities.Cataloge
|
||||
require.NotEmpty(t, c.Parsers, "generic cataloger must have at least one parser")
|
||||
|
||||
for _, p := range c.Parsers {
|
||||
p := p // capture loop variable for subtest
|
||||
|
||||
t.Run(p.ParserFunction, func(t *testing.T) {
|
||||
require.NotEmpty(t, p.Capabilities, "parser must have at least one capability field defined")
|
||||
@@ -1120,7 +1117,6 @@ func TestCatalogerStructure(t *testing.T) {
|
||||
require.NoError(t, err)
|
||||
|
||||
for _, c := range catalogerEntries {
|
||||
c := c // capture loop variable for subtest
|
||||
|
||||
t.Run(c.Name, func(t *testing.T) {
|
||||
// ecosystem must always be set (it's MANUAL)
|
||||
|
||||
@@ -151,11 +151,11 @@ func TestGetter_GetToDir_CertConcerns(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func assertUnknownAuthorityError(t assert.TestingT, err error, _ ...interface{}) bool {
|
||||
func assertUnknownAuthorityError(t assert.TestingT, err error, _ ...any) bool {
|
||||
return assert.ErrorAs(t, err, &x509.UnknownAuthorityError{})
|
||||
}
|
||||
|
||||
func assertErrNonArchiveSource(t assert.TestingT, err error, _ ...interface{}) bool {
|
||||
func assertErrNonArchiveSource(t assert.TestingT, err error, _ ...any) bool {
|
||||
return assert.ErrorIs(t, err, ErrNonArchiveSource)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package file
|
||||
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package file
|
||||
|
||||
@@ -242,8 +241,8 @@ func assertZipSourceFixtureContents(t testing.TB, actual map[string]string, expe
|
||||
}
|
||||
|
||||
// looks like there isn't a helper for this yet? https://github.com/stretchr/testify/issues/497
|
||||
func assertErrorAs(expectedErr interface{}) assert.ErrorAssertionFunc {
|
||||
return func(t assert.TestingT, actualErr error, i ...interface{}) bool {
|
||||
func assertErrorAs(expectedErr any) assert.ErrorAssertionFunc {
|
||||
return func(t assert.TestingT, actualErr error, i ...any) bool {
|
||||
return errors.As(actualErr, &expectedErr)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,7 +143,7 @@ func build() *jsonschema.Schema {
|
||||
// srcMetadataContainer := assembleTypeContainer(sourcemetadata.AllTypes())
|
||||
// srcMetadataContainerType := reflect.TypeOf(srcMetadataContainer)
|
||||
|
||||
documentSchema := reflector.ReflectFromType(reflect.TypeOf(&syftJsonModel.Document{}))
|
||||
documentSchema := reflector.ReflectFromType(reflect.TypeFor[*syftJsonModel.Document]())
|
||||
pkgMetadataSchema := reflector.ReflectFromType(reflect.TypeOf(pkgMetadataContainer))
|
||||
// srcMetadataSchema := reflector.ReflectFromType(reflect.TypeOf(srcMetadataContainer))
|
||||
|
||||
|
||||
+12
-12
@@ -30,61 +30,61 @@ func Get() logger.Logger {
|
||||
}
|
||||
|
||||
// Errorf takes a formatted template string and template arguments for the error logging level.
|
||||
func Errorf(format string, args ...interface{}) {
|
||||
func Errorf(format string, args ...any) {
|
||||
log.Errorf(format, args...)
|
||||
}
|
||||
|
||||
// Error logs the given arguments at the error logging level.
|
||||
func Error(args ...interface{}) {
|
||||
func Error(args ...any) {
|
||||
log.Error(args...)
|
||||
}
|
||||
|
||||
// Warnf takes a formatted template string and template arguments for the warning logging level.
|
||||
func Warnf(format string, args ...interface{}) {
|
||||
func Warnf(format string, args ...any) {
|
||||
log.Warnf(format, args...)
|
||||
}
|
||||
|
||||
// Warn logs the given arguments at the warning logging level.
|
||||
func Warn(args ...interface{}) {
|
||||
func Warn(args ...any) {
|
||||
log.Warn(args...)
|
||||
}
|
||||
|
||||
// Infof takes a formatted template string and template arguments for the info logging level.
|
||||
func Infof(format string, args ...interface{}) {
|
||||
func Infof(format string, args ...any) {
|
||||
log.Infof(format, args...)
|
||||
}
|
||||
|
||||
// Info logs the given arguments at the info logging level.
|
||||
func Info(args ...interface{}) {
|
||||
func Info(args ...any) {
|
||||
log.Info(args...)
|
||||
}
|
||||
|
||||
// Debugf takes a formatted template string and template arguments for the debug logging level.
|
||||
func Debugf(format string, args ...interface{}) {
|
||||
func Debugf(format string, args ...any) {
|
||||
log.Debugf(format, args...)
|
||||
}
|
||||
|
||||
// Debug logs the given arguments at the debug logging level.
|
||||
func Debug(args ...interface{}) {
|
||||
func Debug(args ...any) {
|
||||
log.Debug(args...)
|
||||
}
|
||||
|
||||
// Tracef takes a formatted template string and template arguments for the trace logging level.
|
||||
func Tracef(format string, args ...interface{}) {
|
||||
func Tracef(format string, args ...any) {
|
||||
log.Tracef(format, args...)
|
||||
}
|
||||
|
||||
// Trace logs the given arguments at the trace logging level.
|
||||
func Trace(args ...interface{}) {
|
||||
func Trace(args ...any) {
|
||||
log.Trace(args...)
|
||||
}
|
||||
|
||||
// WithFields returns a message logger with multiple key-value fields.
|
||||
func WithFields(fields ...interface{}) logger.MessageLogger {
|
||||
func WithFields(fields ...any) logger.MessageLogger {
|
||||
return log.WithFields(fields...)
|
||||
}
|
||||
|
||||
// Nested returns a new logger with hard coded key-value pairs
|
||||
func Nested(fields ...interface{}) logger.Logger {
|
||||
func Nested(fields ...any) logger.Logger {
|
||||
return log.Nested(fields...)
|
||||
}
|
||||
|
||||
@@ -40,28 +40,28 @@ func TestReflectTypeFromJSONName(t *testing.T) {
|
||||
{
|
||||
name: "exact match on ID",
|
||||
lookup: "rust-cargo-lock-entry",
|
||||
wantRecord: reflect.TypeOf(pkg.RustCargoLockEntry{}),
|
||||
wantRecord: reflect.TypeFor[pkg.RustCargoLockEntry](),
|
||||
},
|
||||
{
|
||||
name: "exact match on former name",
|
||||
lookup: "RustCargoPackageMetadata",
|
||||
wantRecord: reflect.TypeOf(pkg.RustCargoLockEntry{}),
|
||||
wantRecord: reflect.TypeFor[pkg.RustCargoLockEntry](),
|
||||
},
|
||||
{
|
||||
name: "case insensitive on ID",
|
||||
lookup: "RUST-CARGO-lock-entrY",
|
||||
wantRecord: reflect.TypeOf(pkg.RustCargoLockEntry{}),
|
||||
wantRecord: reflect.TypeFor[pkg.RustCargoLockEntry](),
|
||||
},
|
||||
{
|
||||
name: "case insensitive on alias",
|
||||
lookup: "rusTcArgopacKagEmEtadATa",
|
||||
wantRecord: reflect.TypeOf(pkg.RustCargoLockEntry{}),
|
||||
wantRecord: reflect.TypeFor[pkg.RustCargoLockEntry](),
|
||||
},
|
||||
{
|
||||
name: "consistent override",
|
||||
// there are two correct answers for this -- we should always get the same answer.
|
||||
lookup: "HackageMetadataType",
|
||||
wantRecord: reflect.TypeOf(pkg.HackageStackYamlLockEntry{}),
|
||||
wantRecord: reflect.TypeFor[pkg.HackageStackYamlLockEntry](),
|
||||
},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
@@ -83,142 +83,142 @@ func TestReflectTypeFromJSONName_LegacyValues(t *testing.T) {
|
||||
{
|
||||
name: "map pkg.AlpmDBEntry struct type",
|
||||
input: "AlpmMetadata",
|
||||
expected: reflect.TypeOf(pkg.AlpmDBEntry{}),
|
||||
expected: reflect.TypeFor[pkg.AlpmDBEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.ApkDBEntry struct type",
|
||||
input: "ApkMetadata",
|
||||
expected: reflect.TypeOf(pkg.ApkDBEntry{}),
|
||||
expected: reflect.TypeFor[pkg.ApkDBEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.BinarySignature struct type",
|
||||
input: "BinaryMetadata",
|
||||
expected: reflect.TypeOf(pkg.BinarySignature{}),
|
||||
expected: reflect.TypeFor[pkg.BinarySignature](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.CocoaPodfileLockEntry struct type",
|
||||
input: "CocoapodsMetadataType",
|
||||
expected: reflect.TypeOf(pkg.CocoaPodfileLockEntry{}),
|
||||
expected: reflect.TypeFor[pkg.CocoaPodfileLockEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.ConanLockEntry struct type",
|
||||
input: "ConanLockMetadataType",
|
||||
expected: reflect.TypeOf(pkg.ConanV1LockEntry{}),
|
||||
expected: reflect.TypeFor[pkg.ConanV1LockEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.ConanfileEntry struct type",
|
||||
input: "ConanMetadataType",
|
||||
expected: reflect.TypeOf(pkg.ConanfileEntry{}),
|
||||
expected: reflect.TypeFor[pkg.ConanfileEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.DartPubspecLockEntry struct type",
|
||||
input: "DartPubMetadata",
|
||||
expected: reflect.TypeOf(pkg.DartPubspecLockEntry{}),
|
||||
expected: reflect.TypeFor[pkg.DartPubspecLockEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.DotnetDepsEntry struct type",
|
||||
input: "DotnetDepsMetadata",
|
||||
expected: reflect.TypeOf(pkg.DotnetDepsEntry{}),
|
||||
expected: reflect.TypeFor[pkg.DotnetDepsEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.DpkgDBEntry struct type",
|
||||
input: "DpkgMetadata",
|
||||
expected: reflect.TypeOf(pkg.DpkgDBEntry{}),
|
||||
expected: reflect.TypeFor[pkg.DpkgDBEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.RubyGemspec struct type",
|
||||
input: "GemMetadata",
|
||||
expected: reflect.TypeOf(pkg.RubyGemspec{}),
|
||||
expected: reflect.TypeFor[pkg.RubyGemspec](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.GolangBinaryBuildinfoEntry struct type",
|
||||
input: "GolangBinMetadata",
|
||||
expected: reflect.TypeOf(pkg.GolangBinaryBuildinfoEntry{}),
|
||||
expected: reflect.TypeFor[pkg.GolangBinaryBuildinfoEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.GolangModuleEntry struct type",
|
||||
input: "GolangModMetadata",
|
||||
expected: reflect.TypeOf(pkg.GolangModuleEntry{}),
|
||||
expected: reflect.TypeFor[pkg.GolangModuleEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.JavaArchive struct type",
|
||||
input: "JavaMetadata",
|
||||
expected: reflect.TypeOf(pkg.JavaArchive{}),
|
||||
expected: reflect.TypeFor[pkg.JavaArchive](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.MicrosoftKbPatch struct type",
|
||||
input: "KbPatchMetadata",
|
||||
expected: reflect.TypeOf(pkg.MicrosoftKbPatch{}),
|
||||
expected: reflect.TypeFor[pkg.MicrosoftKbPatch](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.LinuxKernel struct type",
|
||||
input: "LinuxKernel",
|
||||
expected: reflect.TypeOf(pkg.LinuxKernel{}),
|
||||
expected: reflect.TypeFor[pkg.LinuxKernel](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.LinuxKernelModule struct type",
|
||||
input: "LinuxKernelModule",
|
||||
expected: reflect.TypeOf(pkg.LinuxKernelModule{}),
|
||||
expected: reflect.TypeFor[pkg.LinuxKernelModule](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.ElixirMixLockEntry struct type",
|
||||
input: "MixLockMetadataType",
|
||||
expected: reflect.TypeOf(pkg.ElixirMixLockEntry{}),
|
||||
expected: reflect.TypeFor[pkg.ElixirMixLockEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.NixStoreEntry struct type",
|
||||
input: "NixStoreMetadata",
|
||||
expected: reflect.TypeOf(pkg.NixStoreEntry{}),
|
||||
expected: reflect.TypeFor[pkg.NixStoreEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.NpmPackage struct type",
|
||||
input: "NpmPackageJsonMetadata",
|
||||
expected: reflect.TypeOf(pkg.NpmPackage{}),
|
||||
expected: reflect.TypeFor[pkg.NpmPackage](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.NpmPackageLockEntry struct type",
|
||||
input: "NpmPackageLockJsonMetadata",
|
||||
expected: reflect.TypeOf(pkg.NpmPackageLockEntry{}),
|
||||
expected: reflect.TypeFor[pkg.NpmPackageLockEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.PortageEntry struct type",
|
||||
input: "PortageMetadata",
|
||||
expected: reflect.TypeOf(pkg.PortageEntry{}),
|
||||
expected: reflect.TypeFor[pkg.PortageEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.PythonPackage struct type",
|
||||
input: "PythonPackageMetadata",
|
||||
expected: reflect.TypeOf(pkg.PythonPackage{}),
|
||||
expected: reflect.TypeFor[pkg.PythonPackage](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.PythonPipfileLockEntry struct type",
|
||||
input: "PythonPipfileLockMetadata",
|
||||
expected: reflect.TypeOf(pkg.PythonPipfileLockEntry{}),
|
||||
expected: reflect.TypeFor[pkg.PythonPipfileLockEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.PythonRequirementsEntry struct type",
|
||||
input: "PythonRequirementsMetadata",
|
||||
expected: reflect.TypeOf(pkg.PythonRequirementsEntry{}),
|
||||
expected: reflect.TypeFor[pkg.PythonRequirementsEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.PhpPeclEntry struct type",
|
||||
input: "PhpPeclMetadata",
|
||||
expected: reflect.TypeOf(pkg.PhpPeclEntry{}),
|
||||
expected: reflect.TypeFor[pkg.PhpPeclEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.ErlangRebarLockEntry struct type",
|
||||
input: "RebarLockMetadataType",
|
||||
expected: reflect.TypeOf(pkg.ErlangRebarLockEntry{}),
|
||||
expected: reflect.TypeFor[pkg.ErlangRebarLockEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.RDescription struct type",
|
||||
input: "RDescriptionFileMetadataType",
|
||||
expected: reflect.TypeOf(pkg.RDescription{}),
|
||||
expected: reflect.TypeFor[pkg.RDescription](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.RpmDBEntry struct type",
|
||||
input: "RpmdbMetadata",
|
||||
expected: reflect.TypeOf(pkg.RpmDBEntry{}),
|
||||
expected: reflect.TypeFor[pkg.RpmDBEntry](),
|
||||
},
|
||||
// these cases are 1:many
|
||||
{
|
||||
@@ -228,28 +228,28 @@ func TestReflectTypeFromJSONName_LegacyValues(t *testing.T) {
|
||||
// from a data-shape perspective either would be equally correct
|
||||
// however, the RPMDBMetadata has been around longer and may have been more widely used
|
||||
// so we'll map to that type for backwards compatibility.
|
||||
expected: reflect.TypeOf(pkg.RpmDBEntry{}),
|
||||
expected: reflect.TypeFor[pkg.RpmDBEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.HackageStackYamlLockEntry struct type - overlap with HackageStack*Metadata",
|
||||
input: "HackageMetadataType",
|
||||
// this used to be shared as a use case for both HackageStackYamlLockEntry and HackageStackYamlEntry
|
||||
// but the HackageStackYamlLockEntry maps most closely to the original data shape.
|
||||
expected: reflect.TypeOf(pkg.HackageStackYamlLockEntry{}),
|
||||
expected: reflect.TypeFor[pkg.HackageStackYamlLockEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.PhpComposerLockEntry struct type",
|
||||
input: "PhpComposerJsonMetadata",
|
||||
// this used to be shared as a use case for both PhpComposerLockEntry and PhpComposerInstalledEntry
|
||||
// neither of these is more correct over the other. These parsers were also introduced at the same time.
|
||||
expected: reflect.TypeOf(pkg.PhpComposerLockEntry{}),
|
||||
expected: reflect.TypeFor[pkg.PhpComposerLockEntry](),
|
||||
},
|
||||
{
|
||||
name: "map pkg.RustCargoLockEntry struct type",
|
||||
input: "RustCargoPackageMetadata",
|
||||
// this used to be shared as a use case for both RustCargoLockEntry and RustBinaryAuditEntry
|
||||
// neither of these is more correct over the other.
|
||||
expected: reflect.TypeOf(pkg.RustCargoLockEntry{}),
|
||||
expected: reflect.TypeFor[pkg.RustCargoLockEntry](),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
@@ -92,10 +92,7 @@ func processReaderInChunks(rdr io.Reader, chunkSize int, handler func(data []byt
|
||||
lastRead := 0
|
||||
|
||||
for {
|
||||
offset := half
|
||||
if lastRead < half {
|
||||
offset = lastRead
|
||||
}
|
||||
offset := min(lastRead, half)
|
||||
start := half - offset
|
||||
if lastRead > 0 {
|
||||
copy(buf[start:], buf[half+offset:half+lastRead])
|
||||
|
||||
@@ -26,9 +26,9 @@ var (
|
||||
pkg.BitnamiPkg,
|
||||
}
|
||||
binaryMetadataTypes = []string{
|
||||
reflect.TypeOf(pkg.ELFBinaryPackageNoteJSONPayload{}).Name(),
|
||||
reflect.TypeOf(pkg.BinarySignature{}).Name(),
|
||||
reflect.TypeOf(pkg.JavaVMInstallation{}).Name(),
|
||||
reflect.TypeFor[pkg.ELFBinaryPackageNoteJSONPayload]().Name(),
|
||||
reflect.TypeFor[pkg.BinarySignature]().Name(),
|
||||
reflect.TypeFor[pkg.JavaVMInstallation]().Name(),
|
||||
}
|
||||
)
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ func TestExcludeByFileOwnershipOverlap(t *testing.T) {
|
||||
packageC := pkg.Package{Name: "package-c", Type: pkg.BinaryPkg, Metadata: pkg.ELFBinaryPackageNoteJSONPayload{Type: "rpm"}}
|
||||
packageD := pkg.Package{Name: "package-d", Type: pkg.BitnamiPkg}
|
||||
for _, p := range []*pkg.Package{&packageA, &packageB, &packageC, &packageD} {
|
||||
p := p
|
||||
p.SetID()
|
||||
}
|
||||
|
||||
|
||||
@@ -8,11 +8,11 @@ import (
|
||||
)
|
||||
|
||||
var jsonNameFromType = map[reflect.Type][]string{
|
||||
reflect.TypeOf(source.DirectoryMetadata{}): {"directory", "dir"},
|
||||
reflect.TypeOf(source.FileMetadata{}): {"file"},
|
||||
reflect.TypeOf(source.ImageMetadata{}): {"image"},
|
||||
reflect.TypeOf(source.SnapMetadata{}): {"snap"},
|
||||
reflect.TypeOf(source.OCIModelMetadata{}): {"oci-model"},
|
||||
reflect.TypeFor[source.DirectoryMetadata](): {"directory", "dir"},
|
||||
reflect.TypeFor[source.FileMetadata](): {"file"},
|
||||
reflect.TypeFor[source.ImageMetadata](): {"image"},
|
||||
reflect.TypeFor[source.SnapMetadata](): {"snap"},
|
||||
reflect.TypeFor[source.OCIModelMetadata](): {"oci-model"},
|
||||
}
|
||||
|
||||
func AllTypeNames() []string {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package internal
|
||||
|
||||
import "strings"
|
||||
import (
|
||||
"slices"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// HasAnyOfPrefixes returns an indication if the given string has any of the given prefixes.
|
||||
func HasAnyOfPrefixes(input string, prefixes ...string) bool {
|
||||
@@ -32,12 +35,7 @@ func TruncateMiddleEllipsis(input string, maxLen int) string {
|
||||
}
|
||||
|
||||
func StringInSlice(a string, list []string) bool {
|
||||
for _, b := range list {
|
||||
if b == a {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(list, a)
|
||||
}
|
||||
|
||||
func SplitAny(s string, seps string) []string {
|
||||
|
||||
@@ -198,7 +198,7 @@ func TestConcurrentNewChildAndNewFile(t *testing.T) {
|
||||
errs := make(chan error, goroutines)
|
||||
paths := make(chan string, goroutines)
|
||||
|
||||
for i := 0; i < goroutines; i++ {
|
||||
for i := range goroutines {
|
||||
go func(i int) {
|
||||
if i%2 == 0 {
|
||||
child, cleanup, err := td.NewChild("concurrent")
|
||||
@@ -223,7 +223,7 @@ func TestConcurrentNewChildAndNewFile(t *testing.T) {
|
||||
}
|
||||
|
||||
seen := make(map[string]bool)
|
||||
for i := 0; i < goroutines; i++ {
|
||||
for range goroutines {
|
||||
err := <-errs
|
||||
require.NoError(t, err)
|
||||
}
|
||||
@@ -250,7 +250,7 @@ func TestConcurrentNewChildDuringCleanup(t *testing.T) {
|
||||
close(done)
|
||||
}()
|
||||
// try creating children concurrently with cleanup — should get errors, not panics
|
||||
for i := 0; i < 10; i++ {
|
||||
for range 10 {
|
||||
_, c, _ := td.NewChild("race")
|
||||
if c != nil {
|
||||
c()
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ import (
|
||||
)
|
||||
|
||||
// Tprintf renders a string from a given template string and field values
|
||||
func Tprintf(tmpl string, data map[string]interface{}) string {
|
||||
func Tprintf(tmpl string, data map[string]any) string {
|
||||
t := template.Must(template.New("").Parse(tmpl))
|
||||
buf := &bytes.Buffer{}
|
||||
if err := t.Execute(buf, data); err != nil {
|
||||
|
||||
@@ -3,6 +3,7 @@ package unknown
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"slices"
|
||||
"strings"
|
||||
|
||||
"github.com/anchore/syft/internal/log"
|
||||
@@ -155,12 +156,7 @@ func containsErr(out []error, err error) bool {
|
||||
log.Tracef("error comparing errors: %v", err)
|
||||
}
|
||||
}()
|
||||
for _, e := range out {
|
||||
if e == err {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
return slices.Contains(out, err)
|
||||
}
|
||||
|
||||
// visitErrors visits every wrapped error. the returned error replaces the provided error, null errors are omitted from
|
||||
|
||||
Reference in New Issue
Block a user