forked from zhanglimao/trivy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gemspec.go
40 lines (30 loc) · 1.01 KB
/
gemspec.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
package gemspec
import (
"context"
"os"
"path/filepath"
"regexp"
"github.com/aquasecurity/go-dep-parser/pkg/ruby/gemspec"
"github.com/zhyocean/trivy/pkg/fanal/analyzer"
"github.com/zhyocean/trivy/pkg/fanal/analyzer/language"
"github.com/zhyocean/trivy/pkg/fanal/types"
)
func init() {
analyzer.RegisterAnalyzer(&gemspecLibraryAnalyzer{})
}
const version = 1
var fileRegex = regexp.MustCompile(`.*/specifications/.+\.gemspec`)
type gemspecLibraryAnalyzer struct{}
func (a gemspecLibraryAnalyzer) Analyze(_ context.Context, input analyzer.AnalysisInput) (*analyzer.AnalysisResult, error) {
return language.AnalyzePackage(types.GemSpec, input.FilePath, input.Content,
gemspec.NewParser(), input.Options.FileChecksum)
}
func (a gemspecLibraryAnalyzer) Required(filePath string, _ os.FileInfo) bool {
return fileRegex.MatchString(filepath.ToSlash(filePath))
}
func (a gemspecLibraryAnalyzer) Type() analyzer.Type {
return analyzer.TypeGemSpec
}
func (a gemspecLibraryAnalyzer) Version() int {
return version
}