-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathpip.go
43 lines (33 loc) · 1.03 KB
/
pip.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package pip
import (
"context"
"os"
"path/filepath"
"golang.org/x/xerrors"
"github.com/aquasecurity/trivy/pkg/dependency/parser/python/pip"
"github.com/aquasecurity/trivy/pkg/fanal/analyzer"
"github.com/aquasecurity/trivy/pkg/fanal/analyzer/language"
"github.com/aquasecurity/trivy/pkg/fanal/types"
)
func init() {
analyzer.RegisterAnalyzer(&pipLibraryAnalyzer{})
}
const version = 1
type pipLibraryAnalyzer struct{}
func (a pipLibraryAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
res, err := language.Analyze(types.Pip, input.FilePath, input.Content, pip.NewParser())
if err != nil {
return nil, xerrors.Errorf("unable to parse requirements.txt: %w", err)
}
return res, nil
}
func (a pipLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool {
fileName := filepath.Base(filePath)
return fileName == types.PipRequirements
}
func (a pipLibraryAnalyzer) Type() analyzer.Type {
return analyzer.TypePip
}
func (a pipLibraryAnalyzer) Version() int {
return version
}