Merge pull request #9 from apostov/master

Code cleanup and badges
This commit is contained in:
Zachary Rice authored and GitHub committed 2018-02-17 10:51:44 -06:00
commit 159f5d6185
6 files changed
+32 -31

No files matched your search

+3
View File
@@ -1,5 +1,8 @@
# GitLeaks # GitLeaks
[![godoc](https://godoc.org/github.com/zricethezav/gitleaks?status.svg)](http://godoc.org/github.com/zricethezav/gitleaks)
[![GolangCI](https://golangci.com/badges/github.com/zricethezav/gitleaks.svg)](https://golangci.com)
## Check git repos for secrets and keys ## Check git repos for secrets and keys
### Features ### Features
+4 -6
View File
@@ -1,8 +1,9 @@
package main package main
import ( import (
"github.com/nbutton23/zxcvbn-go"
"strings" "strings"
"github.com/nbutton23/zxcvbn-go"
) )
// check each line of a diff and see if there are any potential secrets // check each line of a diff and see if there are any potential secrets
@@ -38,7 +39,7 @@ func checkEntropy(target string) bool {
} }
// TODO check for stop words here // TODO check for stop words here
target = strings.Trim(target[index[1]:len(target)], " ") target = strings.Trim(target[index[1]:], " ")
if len(target) > 70 { if len(target) > 70 {
return false return false
@@ -47,8 +48,5 @@ func checkEntropy(target string) bool {
entropy := zxcvbn.PasswordStrength(target, nil).Entropy entropy := zxcvbn.PasswordStrength(target, nil).Entropy
// tune this/make option // tune this/make option
if entropy > 70 { return entropy > 70
return true
}
return false
} }
+9 -6
View File
@@ -19,16 +19,16 @@ type LeakElem struct {
Commit string `json:"commit"` Commit string `json:"commit"`
} }
func start(opts *Options, repoUrl string) { func start(_ *Options, repoURL string) {
c := make(chan os.Signal, 2) c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM) signal.Notify(c, os.Interrupt, syscall.SIGTERM)
err := exec.Command("git", "clone", repoUrl).Run() err := exec.Command("git", "clone", repoURL).Run()
if err != nil { if err != nil {
log.Fatalf("failed to clone repo %v", err) log.Fatalf("failed to clone repo %v", err)
} }
repoName := getLocalRepoName(repoUrl) repoName := getLocalRepoName(repoURL)
if err := os.Chdir(repoName); err != nil { if err = os.Chdir(repoName); err != nil {
log.Fatal(err) log.Fatal(err)
} }
go func() { go func() {
@@ -39,8 +39,11 @@ func start(opts *Options, repoUrl string) {
report := getLeaks(repoName) report := getLeaks(repoName)
cleanup(repoName) cleanup(repoName)
reportJson, _ := json.MarshalIndent(report, "", "\t") reportJSON, _ := json.MarshalIndent(report, "", "\t")
err = ioutil.WriteFile(fmt.Sprintf("%s_leaks.json", repoName), reportJson, 0644) err = ioutil.WriteFile(fmt.Sprintf("%s_leaks.json", repoName), reportJSON, 0644)
if err != nil {
log.Fatalf("Can't write to file: %s", err)
}
} }
// getLocalRepoName generates the name of the local clone folder based on the given URL // getLocalRepoName generates the name of the local clone folder based on the given URL
+4 -4
View File
@@ -3,9 +3,9 @@ package main
import "testing" import "testing"
func TestGetLocalRepoName(t *testing.T) { func TestGetLocalRepoName(t *testing.T) {
cases := []struct{ cases := []struct {
name string name string
input string input string
expected string expected string
}{ }{
{ {
@@ -51,4 +51,4 @@ func TestGetLocalRepoName(t *testing.T) {
t.Errorf("'%s' failed. Input: '%s'; Expected: '%s'; Got: '%s'", c.input, c.name, c.expected, actual) t.Errorf("'%s' failed. Input: '%s'; Expected: '%s'; Got: '%s'", c.input, c.name, c.expected, actual)
} }
} }
} }
+10 -4
View File
@@ -1,6 +1,7 @@
package main package main
import ( import (
"log"
"os" "os"
"regexp" "regexp"
) )
@@ -12,7 +13,12 @@ var (
) )
func init() { func init() {
appRoot, _ = os.Getwd() var err error
appRoot, err = os.Getwd()
if err != nil {
log.Fatalf("Can't get working dir: %s", err)
}
// TODO update regex to look for things like: // TODO update regex to look for things like:
// TODO ability to add/filter regex // TODO ability to add/filter regex
// client("AKAI32fJ334...", // client("AKAI32fJ334...",
@@ -30,7 +36,7 @@ func init() {
func main() { func main() {
args := os.Args[2:] args := os.Args[2:]
repoUrl := os.Args[1] repoURL := os.Args[1]
opts := parseOptions(args, repoUrl) opts := parseOptions(args)
start(opts, repoUrl) start(opts, repoURL)
} }
+2 -11
View File
@@ -10,7 +10,7 @@ import (
// hittps://github.com/<user or org> // hittps://github.com/<user or org>
// hittps://github.com/<user or org>/repo // hittps://github.com/<user or org>/repo
const usage = `usage: gitleaks [git link] [options] const usage = `usage: gitleaks [git link] [options]
Options: Options:
-c Concurrency factor (potential number of git files open) -c Concurrency factor (potential number of git files open)
-h --help Display this message -h --help Display this message
@@ -39,16 +39,7 @@ func optionsNextInt(args []string, i *int) int {
return argInt return argInt
} }
func optionsNextString(args []string, i *int) string { func parseOptions(args []string) *Options {
if len(args) > *i+1 {
*i++
} else {
help()
}
return args[*i]
}
func parseOptions(args []string, repoUrl string) *Options {
opts := &Options{} opts := &Options{}
for i := 0; i < len(args); i++ { for i := 0; i < len(args); i++ {
arg := args[i] arg := args[i]