Code cleanup and badges

This commit is contained in:
Anton Postov committed 2018-02-17 10:51:20 +03:00
1 parent cf4c157141
commit a9c5d5a953
6 files changed
+32 -31

No files matched your search

+3
View File
@@ -1,5 +1,8 @@
# 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
### Features
+4 -6
View File
@@ -1,8 +1,9 @@
package main
import (
"github.com/nbutton23/zxcvbn-go"
"strings"
"github.com/nbutton23/zxcvbn-go"
)
// 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
target = strings.Trim(target[index[1]:len(target)], " ")
target = strings.Trim(target[index[1]:], " ")
if len(target) > 70 {
return false
@@ -47,8 +48,5 @@ func checkEntropy(target string) bool {
entropy := zxcvbn.PasswordStrength(target, nil).Entropy
// tune this/make option
if entropy > 70 {
return true
}
return false
return entropy > 70
}
+9 -6
View File
@@ -19,16 +19,16 @@ type LeakElem struct {
Commit string `json:"commit"`
}
func start(opts *Options, repoUrl string) {
func start(_ *Options, repoURL string) {
c := make(chan os.Signal, 2)
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
err := exec.Command("git", "clone", repoUrl).Run()
err := exec.Command("git", "clone", repoURL).Run()
if err != nil {
log.Fatalf("failed to clone repo %v", err)
}
repoName := getLocalRepoName(repoUrl)
if err := os.Chdir(repoName); err != nil {
repoName := getLocalRepoName(repoURL)
if err = os.Chdir(repoName); err != nil {
log.Fatal(err)
}
go func() {
@@ -39,8 +39,11 @@ func start(opts *Options, repoUrl string) {
report := getLeaks(repoName)
cleanup(repoName)
reportJson, _ := json.MarshalIndent(report, "", "\t")
err = ioutil.WriteFile(fmt.Sprintf("%s_leaks.json", repoName), reportJson, 0644)
reportJSON, _ := json.MarshalIndent(report, "", "\t")
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
+4 -4
View File
@@ -3,9 +3,9 @@ package main
import "testing"
func TestGetLocalRepoName(t *testing.T) {
cases := []struct{
name string
input string
cases := []struct {
name string
input 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)
}
}
}
}
+10 -4
View File
@@ -1,6 +1,7 @@
package main
import (
"log"
"os"
"regexp"
)
@@ -12,7 +13,12 @@ var (
)
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 ability to add/filter regex
// client("AKAI32fJ334...",
@@ -30,7 +36,7 @@ func init() {
func main() {
args := os.Args[2:]
repoUrl := os.Args[1]
opts := parseOptions(args, repoUrl)
start(opts, repoUrl)
repoURL := os.Args[1]
opts := parseOptions(args)
start(opts, repoURL)
}
+2 -11
View File
@@ -10,7 +10,7 @@ import (
// hittps://github.com/<user or org>
// hittps://github.com/<user or org>/repo
const usage = `usage: gitleaks [git link] [options]
Options:
-c Concurrency factor (potential number of git files open)
-h --help Display this message
@@ -39,16 +39,7 @@ func optionsNextInt(args []string, i *int) int {
return argInt
}
func optionsNextString(args []string, i *int) string {
if len(args) > *i+1 {
*i++
} else {
help()
}
return args[*i]
}
func parseOptions(args []string, repoUrl string) *Options {
func parseOptions(args []string) *Options {
opts := &Options{}
for i := 0; i < len(args); i++ {
arg := args[i]