Files
gitleaks/main.go
T
Zachary Rice 7db08bfd90 Bugs v7 (#475)
* fixing some v7 bugs
2020-12-05 11:57:43 -05:00

71 lines
1.3 KiB
Go

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)
}
}
func listenForInterrupt(stopScan chan os.Signal) {
<-stopScan
log.Warn("halting gitleaks scan")
os.Exit(1)
}