-
Notifications
You must be signed in to change notification settings - Fork 1
/
camas.go
94 lines (76 loc) · 2.42 KB
/
camas.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// camas is a tool that finds potential secrets in source code
package main
import (
"flag"
"log"
"os"
"runtime/pprof"
"github.com/jtmelton/camas/config"
"github.com/jtmelton/camas/domain"
"github.com/jtmelton/camas/processing"
"github.com/jtmelton/camas/reporting"
)
var (
inputDirectory *string
configFile *string
outputFile *string
outputFormat *string
noiseLevel *int
numWorkers *int
)
// // Options struct represents the cli options passed to the camas tool
// type Options struct {
// inputDirectory string
// configFile string
// outputFile string
// outputFormat string
// noiseLevel int
// numWorkers int
// }
// // Finding struct represents a finding from the secrets analysis
// type Finding struct {
// RuleName string `json:"rule-name"`
// FilePath string `json:"absolute-file-path"`
// LineNumber int `json:"line-number"`
// Content string `json:"content"`
// Noise int `json:"noise-level"`
// }
func main() {
inputDirectory = flag.String("inputDirectory", "", "Directory to analyze (Required)")
configFile = flag.String("configFile", "", "Configuration File (Required)")
outputFile = flag.String("outputFile", "", "Output File")
outputFormat = flag.String("outputFormat", "", "Output Format [txt, json]")
noiseLevel = flag.Int("noiseLevel", 0, "minimum noise level to report on")
numWorkers = flag.Int("numWorkers", 0, "number of go workers to execute")
var cpuProfile = flag.Bool("cpuProfile", false, "write cpu profile to file")
flag.Parse()
if *inputDirectory == "" || *configFile == "" {
flag.PrintDefaults()
os.Exit(1)
}
if *cpuProfile == true {
f, err := os.Create("camas.prof")
if err != nil {
log.Fatalf("Could not construct .prof file for profiling: %v", err)
}
pprof.StartCPUProfile(f)
defer pprof.StopCPUProfile()
}
_options := domain.Options{
InputDirectory: *inputDirectory,
ConfigFile: *configFile,
OutputFile: *outputFile,
OutputFormat: *outputFormat,
NoiseLevel: *noiseLevel,
NumWorkers: *numWorkers,
}
configuration := config.ParseConfig(_options.ConfigFile)
findings := processing.Walk(*inputDirectory, _options, configuration)
reporting.WriteReport(findings, _options)
/*
TODO:
- do a CI setup
https://github.com/jandelgado/golang-ci-template-github-actions/blob/master/.github/workflows/test.yml
- add a test for "create user ... identified by $&*Q#*@#(*" in a sql file
*/
}