github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/pkg/cataloger/alpine/dependency.go (about) 1 package alpine 2 3 import ( 4 "strings" 5 6 "github.com/anchore/syft/internal" 7 "github.com/anchore/syft/internal/log" 8 "github.com/anchore/syft/syft/pkg" 9 "github.com/anchore/syft/syft/pkg/cataloger/internal/dependency" 10 ) 11 12 var _ dependency.Specifier = dbEntryDependencySpecifier 13 14 func dbEntryDependencySpecifier(p pkg.Package) dependency.Specification { 15 meta, ok := p.Metadata.(pkg.ApkDBEntry) 16 if !ok { 17 log.Tracef("cataloger failed to extract apk metadata for package %+v", p.Name) 18 return dependency.Specification{} 19 } 20 21 provides := []string{p.Name} 22 provides = append(provides, stripVersionSpecifiers(meta.Provides)...) 23 24 return dependency.Specification{ 25 Provides: provides, 26 Requires: stripVersionSpecifiers(meta.Dependencies), 27 } 28 } 29 30 func stripVersionSpecifiers(given []string) []string { 31 var keys []string 32 for _, key := range given { 33 key = stripVersionSpecifier(key) 34 if key == "" { 35 continue 36 } 37 keys = append(keys, key) 38 } 39 return keys 40 } 41 42 func stripVersionSpecifier(s string) string { 43 // examples: 44 // musl>=1 --> musl 45 // cmd:scanelf=1.3.4-r0 --> cmd:scanelf 46 47 return strings.TrimSpace(internal.SplitAny(s, "<>=")[0]) 48 }