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