github.com/devseccon/trivy@v0.47.1-0.20231123133102-bd902a0bd996/pkg/fanal/analyzer/language/elixir/mix/mix.go (about) 1 package mix 2 3 import ( 4 "context" 5 "os" 6 "path/filepath" 7 8 "golang.org/x/xerrors" 9 10 "github.com/aquasecurity/go-dep-parser/pkg/hex/mix" 11 "github.com/devseccon/trivy/pkg/fanal/analyzer" 12 "github.com/devseccon/trivy/pkg/fanal/analyzer/language" 13 "github.com/devseccon/trivy/pkg/fanal/types" 14 ) 15 16 func init() { 17 analyzer.RegisterAnalyzer(&mixLockAnalyzer{}) 18 } 19 20 const ( 21 version = 1 22 ) 23 24 // mixLockAnalyzer analyzes 'mix.lock' 25 type mixLockAnalyzer struct{} 26 27 func (a mixLockAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) { 28 p := mix.NewParser() 29 res, err := language.Analyze(types.Hex, input.FilePath, input.Content, p) 30 if err != nil { 31 return nil, xerrors.Errorf("%s parse error: %w", input.FilePath, err) 32 } 33 return res, nil 34 } 35 36 func (a mixLockAnalyzer) Required(filePath string, _ os.FileInfo) bool { 37 // Lock file name can be anything. 38 // cf. https://hexdocs.pm/mix/Mix.Project.html#module-configuration 39 // By default, we only check the default file name - `mix.lock`. 40 return filepath.Base(filePath) == types.MixLock 41 } 42 43 func (a mixLockAnalyzer) Type() analyzer.Type { 44 return analyzer.TypeMixLock 45 } 46 47 func (a mixLockAnalyzer) Version() int { 48 return version 49 }