mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 05:04:22 +01:00
my, things have changed...
This commit is contained in:
1 parent
faca0e14d9
commit
7919e15a65
6 files changed
+415
-307
No files matched your search
@@ -2,38 +2,38 @@ package main
|
||||
|
||||
import (
|
||||
_ "fmt"
|
||||
"github.com/mitchellh/go-homedir"
|
||||
"log"
|
||||
_"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
"go.uber.org/zap"
|
||||
_"time"
|
||||
"go.uber.org/zap/zapcore"
|
||||
_ "io/ioutil"
|
||||
"os"
|
||||
"regexp"
|
||||
_ "time"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
const EXIT_CLEAN = 0
|
||||
const EXIT_FAILURE = 1
|
||||
const EXIT_LEAKS = 2
|
||||
|
||||
// package globals
|
||||
var (
|
||||
regexes map[string]*regexp.Regexp
|
||||
stopWords []string
|
||||
base64Chars string
|
||||
hexChars string
|
||||
assignRegex *regexp.Regexp
|
||||
fileDiffRegex *regexp.Regexp
|
||||
gitLeaksPath string
|
||||
gitLeaksClonePath string
|
||||
gitLeaksReportPath string
|
||||
logger *zap.Logger
|
||||
regexes map[string]*regexp.Regexp
|
||||
stopWords []string
|
||||
base64Chars string
|
||||
hexChars string
|
||||
assignRegex *regexp.Regexp
|
||||
fileDiffRegex *regexp.Regexp
|
||||
logger *zap.Logger
|
||||
opts *Options
|
||||
)
|
||||
|
||||
func init() {
|
||||
base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="
|
||||
hexChars = "1234567890abcdefABCDEF"
|
||||
stopWords = []string{"setting", "info", "env", "environment"}
|
||||
fileDiffRegex = regexp.MustCompile("diff --git a.+b/")
|
||||
assignRegex = regexp.MustCompile(`(=|:|:=|<-)`)
|
||||
|
||||
// TODO Externalize regex... this is tricky making it yml compliant
|
||||
regexes = map[string]*regexp.Regexp{
|
||||
"PKCS8": regexp.MustCompile("-----BEGIN PRIVATE KEY-----"),
|
||||
"RSA": regexp.MustCompile("-----BEGIN RSA PRIVATE KEY-----"),
|
||||
@@ -44,53 +44,19 @@ func init() {
|
||||
"AWS": regexp.MustCompile("AKIA[0-9A-Z]{16}"),
|
||||
"Reddit": regexp.MustCompile("(?i)reddit.*['|\"][0-9a-zA-Z]{14}['|\"]"),
|
||||
"Heroku": regexp.MustCompile("(?i)heroku.*[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}"),
|
||||
// "Custom": regexp.MustCompile(".*")
|
||||
}
|
||||
fileDiffRegex = regexp.MustCompile("diff --git a.+b/")
|
||||
assignRegex = regexp.MustCompile(`(=|:|:=|<-)`)
|
||||
|
||||
// gitleaks dir defaults to $HOME/.gitleaks if no env var GITLEAKS_HOME is present.
|
||||
gitLeaksPath = os.Getenv("GITLEAKS_HOME")
|
||||
if gitLeaksPath == "" {
|
||||
homeDir, err := homedir.Dir()
|
||||
if err != nil {
|
||||
log.Fatal("Cant find home dir")
|
||||
}
|
||||
gitLeaksPath = filepath.Join(homeDir, ".gitleaks")
|
||||
}
|
||||
|
||||
if _, err := os.Stat(gitLeaksPath); os.IsNotExist(err) {
|
||||
os.Mkdir(gitLeaksPath, os.ModePerm)
|
||||
}
|
||||
gitLeaksClonePath = filepath.Join(gitLeaksPath, "clones")
|
||||
if _, err := os.Stat(gitLeaksClonePath); os.IsNotExist(err) {
|
||||
os.Mkdir(gitLeaksClonePath, os.ModePerm)
|
||||
}
|
||||
gitLeaksReportPath = filepath.Join(gitLeaksPath, "report")
|
||||
if _, err := os.Stat(gitLeaksReportPath); os.IsNotExist(err) {
|
||||
os.Mkdir(gitLeaksReportPath, os.ModePerm)
|
||||
}
|
||||
}
|
||||
|
||||
func main() {
|
||||
// TODO abstract logging
|
||||
atom := zap.NewAtomicLevel()
|
||||
encoderCfg := zap.NewProductionEncoderConfig()
|
||||
encoderCfg.TimeKey = ""
|
||||
logger = zap.New(zapcore.NewCore(
|
||||
zapcore.NewJSONEncoder(encoderCfg),
|
||||
zapcore.Lock(os.Stdout),
|
||||
atom,
|
||||
))
|
||||
logger.Info("HEY")
|
||||
atom.SetLevel(zap.InfoLevel)
|
||||
logger.Info("HEY")
|
||||
|
||||
|
||||
args := os.Args[1:]
|
||||
opts := parseOptions(args)
|
||||
owner := newOwner(opts)
|
||||
owner.auditRepos(opts)
|
||||
// repos := getRepos(opts, owner)
|
||||
// start(repos, owner, opts)
|
||||
opts = newOpts(args)
|
||||
owner := newOwner()
|
||||
os.Exit(owner.auditRepos())
|
||||
}
|
||||
|
||||
func failF(format string, args ...interface{}) {
|
||||
fmt.Fprintf(os.Stderr, format, args...)
|
||||
os.Exit(EXIT_FAILURE)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user