-
Notifications
You must be signed in to change notification settings - Fork 347
Expand file tree
/
Copy pathoptions.go
More file actions
74 lines (66 loc) · 3.3 KB
/
Copy pathoptions.go
File metadata and controls
74 lines (66 loc) · 3.3 KB
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
package core
import (
"flag"
"os"
"strings"
)
const (
TempDirSuffix = "SecretScanning"
ExtractedImageFilesDir = "ExtractedFiles"
)
type Options struct {
Threads *int
DebugLevel *string
MaximumFileSize *uint
TempDirectory *string
Local *string
HostMountPath *string
ConfigPath *repeatableStringValue
MergeConfigs *bool
OutputPath *string
JsonFilename *string
ImageName *string
MultipleMatch *bool
MaxMultiMatch *uint
MaxSecrets *uint
ContainerId *string
ContainerNS *string
Quiet *bool
}
type repeatableStringValue struct {
values []string
}
func (v *repeatableStringValue) String() string {
return strings.Join(v.values, ", ")
}
func (v *repeatableStringValue) Set(s string) error {
v.values = append(v.values, s)
return nil
}
func (v *repeatableStringValue) Values() []string {
return v.values
}
func ParseOptions() (*Options, error) {
options := &Options{
Threads: flag.Int("threads", 0, "Number of concurrent threads (default number of logical CPUs)"),
DebugLevel: flag.String("debug-level", "ERROR", "Debug levels are one of FATAL, ERROR, IMPORTANT, WARN, INFO, DEBUG. Only levels higher than the debug-level are displayed"),
MaximumFileSize: flag.Uint("maximum-file-size", 256, "Maximum file size to process in KB"),
TempDirectory: flag.String("temp-directory", os.TempDir(), "Directory to process and store repositories/matches"),
Local: flag.String("local", "", "Specify local directory (absolute path) which to scan. Scans only given directory recursively."),
HostMountPath: flag.String("host-mount-path", "", "If scanning the host, specify the host mount path for path exclusions to work correctly."),
ConfigPath: &repeatableStringValue{},
MergeConfigs: flag.Bool("merge-configs", false, "Merge config files specified by --config-path into the default config"),
OutputPath: flag.String("output-path", ".", "Output directory where json file will be stored. If not set, it will output to current directory"),
JsonFilename: flag.String("json-filename", "", "Output json file name. If not set, it will automatically create a filename based on image or dir name"),
ImageName: flag.String("image-name", "", "Name of the image along with tag to scan for secrets"),
MultipleMatch: flag.Bool("multi-match", false, "Output multiple matches of same pattern in one file. By default, only one match of a pattern is output for a file for better performance"),
MaxMultiMatch: flag.Uint("max-multi-match", 3, "Maximum number of matches of same pattern in one file. This is used only when multi-match option is enabled."),
MaxSecrets: flag.Uint("max-secrets", 1000, "Maximum number of secrets to find in one container image or file system."),
ContainerId: flag.String("container-id", "", "Id of existing container ID"),
ContainerNS: flag.String("container-ns", "", "Namespace of existing container to scan, empty for docker runtime"),
Quiet: flag.Bool("quiet", true, "Don't display any output in stdout"),
}
flag.Var(options.ConfigPath, "config-path", "Searches for config.yaml from given directory. If not set, tries to find it from SecretScanner binary's and current directory. Can be specified multiple times.")
flag.Parse()
return options, nil
}