forked from gitleaks/gitleaks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
74 lines (62 loc) · 1.35 KB
/
main.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
package main
import (
"os"
"os/signal"
"time"
"github.com/zricethezav/gitleaks/v7/config"
"github.com/zricethezav/gitleaks/v7/options"
"github.com/zricethezav/gitleaks/v7/scan"
"github.com/hako/durafmt"
log "github.com/sirupsen/logrus"
)
func main() {
// this block sets up a go routine to listen for an interrupt signal
// which will immediately exit gitleaks
stopChan := make(chan os.Signal, 1)
signal.Notify(stopChan, os.Interrupt)
go listenForInterrupt(stopChan)
// setup options
opts, err := options.ParseOptions()
if err != nil {
log.Error(err)
os.Exit(1)
}
err = opts.Guard()
if err != nil {
log.Error(err)
os.Exit(1)
}
// setup configs
cfg, err := config.NewConfig(opts)
if err != nil {
log.Error(err)
os.Exit(1)
}
// setup scanner
scanner, err := scan.NewScanner(opts, cfg)
if err != nil {
log.Error(err)
os.Exit(1)
}
// run and time the scan
start := time.Now()
scannerReport, err := scanner.Scan()
log.Info("scan time: ", durafmt.Parse(time.Now().Sub(start)))
if err != nil {
log.Error(err)
os.Exit(1)
}
// report scan
if err := scan.WriteReport(scannerReport, opts, cfg); err != nil {
log.Error(err)
os.Exit(1)
}
if len(scannerReport.Leaks) != 0 {
os.Exit(opts.CodeOnLeak)
}
}
func listenForInterrupt(stopScan chan os.Signal) {
<-stopScan
log.Warn("halting gitleaks scan")
os.Exit(1)
}