github.com/anchore/syft@v1.4.2-0.20240516191711-1bec1fc5d397/syft/pkg/cataloger/erlang/parse_otp_app.go (about) 1 package erlang 2 3 import ( 4 "context" 5 6 "github.com/anchore/syft/internal/log" 7 "github.com/anchore/syft/syft/artifact" 8 "github.com/anchore/syft/syft/file" 9 "github.com/anchore/syft/syft/pkg" 10 "github.com/anchore/syft/syft/pkg/cataloger/generic" 11 ) 12 13 // parseOTPApp parses a OTP *.app files to a package objects 14 func parseOTPApp(_ context.Context, _ file.Resolver, _ *generic.Environment, reader file.LocationReadCloser) ([]pkg.Package, []artifact.Relationship, error) { 15 doc, err := parseErlang(reader) 16 if err != nil { 17 // there are multiple file formats that use the *.app extension, so it's possible that this is not an OTP app file at all 18 // ... which means we should not return an error here 19 log.WithFields("error", err).Trace("unable to parse Erlang OTP app") 20 return nil, nil, nil 21 } 22 23 var packages []pkg.Package 24 25 root := doc.Get(0) 26 27 name := root.Get(1).String() 28 29 keys := root.Get(2) 30 31 for _, key := range keys.Slice() { 32 if key.Get(0).String() == "vsn" { 33 version := key.Get(1).String() 34 35 p := newPackageFromOTP( 36 name, version, 37 reader.Location.WithAnnotation(pkg.EvidenceAnnotationKey, pkg.PrimaryEvidenceAnnotation), 38 ) 39 40 packages = append(packages, p) 41 } 42 } 43 44 return packages, nil, nil 45 } 46 47 // integrity check 48 var _ generic.Parser = parseOTPApp