-
Notifications
You must be signed in to change notification settings - Fork 2.4k
/
Copy pathdeps.go
47 lines (36 loc) · 1.08 KB
/
deps.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
44
45
46
47
package deps
import (
"context"
"os"
"strings"
"golang.org/x/xerrors"
core "github.com/aquasecurity/go-dep-parser/pkg/dotnet/core_deps"
"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(&depsLibraryAnalyzer{})
}
const (
version = 1
depsExtension = ".deps.json"
)
type depsLibraryAnalyzer struct{}
func (a depsLibraryAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
parser := core.NewParser()
res, err := language.Analyze(types.DotNetCore, input.FilePath, input.Content, parser)
if err != nil {
return nil, xerrors.Errorf(".Net Core dependencies analysis error: %w", err)
}
return res, nil
}
func (a depsLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool {
return strings.HasSuffix(filePath, depsExtension)
}
func (a depsLibraryAnalyzer) Type() analyzer.Type {
return analyzer.TypeDotNetDeps
}
func (a depsLibraryAnalyzer) Version() int {
return version
}