github.com/anchore/syft@v1.38.2/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 ProvidesRequires: dependency.ProvidesRequires{ 26 Provides: provides, 27 Requires: stripVersionSpecifiers(meta.Dependencies), 28 }, 29 } 30 } 31 32 func stripVersionSpecifiers(given []string) []string { 33 var keys []string 34 for _, key := range given { 35 key = stripVersionSpecifier(key) 36 if key == "" { 37 continue 38 } 39 keys = append(keys, key) 40 } 41 return keys 42 } 43 44 func stripVersionSpecifier(s string) string { 45 // examples: 46 // musl>=1 --> musl 47 // cmd:scanelf=1.3.4-r0 --> cmd:scanelf 48 49 return strings.TrimSpace(internal.SplitAny(s, "<>=")[0]) 50 }