/
scan_options.go
76 lines (65 loc) · 1.6 KB
/
scan_options.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package git
import (
"github.com/go-git/go-git/v5"
"github.com/trufflesecurity/trufflehog/v3/pkg/common"
)
type ScanOptions struct {
Filter *common.Filter
BaseHash string // When scanning a git.Log, this is the oldest/first commit.
HeadHash string
MaxDepth int64
Bare bool
ExcludeGlobs []string
LogOptions *git.LogOptions
}
type ScanOption func(*ScanOptions)
func ScanOptionFilter(filter *common.Filter) ScanOption {
return func(scanOptions *ScanOptions) {
scanOptions.Filter = filter
}
}
func ScanOptionBaseHash(hash string) ScanOption {
return func(scanOptions *ScanOptions) {
scanOptions.BaseHash = hash
}
}
func ScanOptionHeadCommit(hash string) ScanOption {
return func(scanOptions *ScanOptions) {
scanOptions.HeadHash = hash
}
}
func ScanOptionMaxDepth(maxDepth int64) ScanOption {
return func(scanOptions *ScanOptions) {
scanOptions.MaxDepth = maxDepth
}
}
func ScanOptionExcludeGlobs(globs []string) ScanOption {
return func(scanOptions *ScanOptions) {
scanOptions.ExcludeGlobs = globs
}
}
func ScanOptionLogOptions(logOptions *git.LogOptions) ScanOption {
return func(scanOptions *ScanOptions) {
scanOptions.LogOptions = logOptions
}
}
func ScanOptionBare(bare bool) ScanOption {
return func(scanOptions *ScanOptions) {
scanOptions.Bare = bare
}
}
func NewScanOptions(options ...ScanOption) *ScanOptions {
scanOptions := &ScanOptions{
Filter: common.FilterEmpty(),
BaseHash: "",
HeadHash: "",
MaxDepth: -1,
LogOptions: &git.LogOptions{
All: true,
},
}
for _, option := range options {
option(scanOptions)
}
return scanOptions
}