diff --git a/audit/audit.go b/audit/audit.go index 0d5391e8..d86348f1 100644 --- a/audit/audit.go +++ b/audit/audit.go @@ -2,11 +2,12 @@ package audit import ( "fmt" - log "github.com/sirupsen/logrus" - "github.com/zricethezav/gitleaks/manager" "io/ioutil" - "path" + + "github.com/zricethezav/gitleaks/manager" + + log "github.com/sirupsen/logrus" ) // Run accepts a manager and begins an audit based on the options/configs set in the manager. diff --git a/audit/repo.go b/audit/repo.go index 136d4bc7..a08de932 100644 --- a/audit/repo.go +++ b/audit/repo.go @@ -4,23 +4,25 @@ import ( "bytes" "crypto/md5" "fmt" - "github.com/BurntSushi/toml" - "github.com/sergi/go-diff/diffmatchpatch" - log "github.com/sirupsen/logrus" - "github.com/zricethezav/gitleaks/config" - "github.com/zricethezav/gitleaks/manager" - "gopkg.in/src-d/go-billy.v4" - "gopkg.in/src-d/go-git.v4" - "gopkg.in/src-d/go-git.v4/plumbing" - "gopkg.in/src-d/go-git.v4/plumbing/object" - "gopkg.in/src-d/go-git.v4/plumbing/storer" - "gopkg.in/src-d/go-git.v4/storage/memory" "io" "os" "path" "path/filepath" "sync" "time" + + "github.com/zricethezav/gitleaks/config" + "github.com/zricethezav/gitleaks/manager" + + "github.com/BurntSushi/toml" + "github.com/sergi/go-diff/diffmatchpatch" + log "github.com/sirupsen/logrus" + "gopkg.in/src-d/go-billy.v4" + "gopkg.in/src-d/go-git.v4" + "gopkg.in/src-d/go-git.v4/plumbing" + "gopkg.in/src-d/go-git.v4/plumbing/object" + "gopkg.in/src-d/go-git.v4/plumbing/storer" + "gopkg.in/src-d/go-git.v4/storage/memory" ) // Repo wraps a *git.Repository object in addition to a manager object and the name of the repo. @@ -209,7 +211,6 @@ func (repo *Repo) Audit() error { return err } - //checker := make(map[string]bool) cc := 0 semaphore := make(chan bool, howManyThreads(repo.Manager.Opts.Threads)) wg := sync.WaitGroup{} @@ -233,6 +234,14 @@ func (repo *Repo) Audit() error { cc++ err = c.Parents().ForEach(func(parent *object.Commit) error { + defer func() { + if err := recover(); err != nil { + // sometimes the patch generation will fail due to a known bug in + // sergi's go-diff: https://github.com/sergi/go-diff/issues/89. + // Once a fix has been merged I will remove this recover. + return + } + }() start := time.Now() patch, err := c.Patch(parent) if err != nil { diff --git a/audit/util.go b/audit/util.go index 4d8ddbfe..50e85d5f 100644 --- a/audit/util.go +++ b/audit/util.go @@ -2,19 +2,20 @@ package audit import ( "fmt" - log "github.com/sirupsen/logrus" - "github.com/zricethezav/gitleaks/config" - "github.com/zricethezav/gitleaks/manager" - "gopkg.in/src-d/go-git.v4" - "gopkg.in/src-d/go-git.v4/plumbing" - fdiff "gopkg.in/src-d/go-git.v4/plumbing/format/diff" - "gopkg.in/src-d/go-git.v4/plumbing/object" "math" - "path" "regexp" "runtime" "strings" "time" + + "github.com/zricethezav/gitleaks/config" + "github.com/zricethezav/gitleaks/manager" + + log "github.com/sirupsen/logrus" + "gopkg.in/src-d/go-git.v4" + "gopkg.in/src-d/go-git.v4/plumbing" + fdiff "gopkg.in/src-d/go-git.v4/plumbing/format/diff" + "gopkg.in/src-d/go-git.v4/plumbing/object" ) const maxLineLen = 200 @@ -59,9 +60,9 @@ func getFileName(f fdiff.FilePatch) string { fn := "???" from, to := f.Files() if from != nil { - return path.Base(from.Path()) + return from.Path() } else if to != nil { - return path.Base(to.Path()) + return to.Path() } return fn diff --git a/config/config.go b/config/config.go index a3f75835..22c73c8a 100644 --- a/config/config.go +++ b/config/config.go @@ -2,11 +2,13 @@ package config import ( "fmt" - "github.com/BurntSushi/toml" - "github.com/zricethezav/gitleaks/options" "regexp" "strconv" "strings" + + "github.com/zricethezav/gitleaks/options" + + "github.com/BurntSushi/toml" ) // Whitelist is struct containing items that if encountered will whitelist diff --git a/hosts/github.go b/hosts/github.go index 5114b7fa..e2dd1b94 100644 --- a/hosts/github.go +++ b/hosts/github.go @@ -2,18 +2,20 @@ package hosts import ( "context" - "github.com/google/go-github/github" - log "github.com/sirupsen/logrus" + "strconv" + "strings" + "sync" + "github.com/zricethezav/gitleaks/audit" "github.com/zricethezav/gitleaks/manager" "github.com/zricethezav/gitleaks/options" + + "github.com/google/go-github/github" + log "github.com/sirupsen/logrus" "golang.org/x/oauth2" "gopkg.in/src-d/go-git.v4" "gopkg.in/src-d/go-git.v4/plumbing" "gopkg.in/src-d/go-git.v4/plumbing/object" - "strconv" - "strings" - "sync" ) // Github wraps a github client and manager. This struct implements what the Host interface defines. diff --git a/hosts/gitlab.go b/hosts/gitlab.go index 3cfe7b2a..669f27f7 100644 --- a/hosts/gitlab.go +++ b/hosts/gitlab.go @@ -2,12 +2,14 @@ package hosts import ( "context" - log "github.com/sirupsen/logrus" - "github.com/xanzy/go-gitlab" + "sync" + "github.com/zricethezav/gitleaks/audit" "github.com/zricethezav/gitleaks/manager" "github.com/zricethezav/gitleaks/options" - "sync" + + log "github.com/sirupsen/logrus" + "github.com/xanzy/go-gitlab" ) // Gitlab wraps a gitlab client and manager. This struct implements what the Host interface defines. diff --git a/main.go b/main.go index 5a995ef0..637d4a06 100644 --- a/main.go +++ b/main.go @@ -1,16 +1,18 @@ package main import ( - "github.com/hako/durafmt" - log "github.com/sirupsen/logrus" + "io/ioutil" + "os" + "time" + "github.com/zricethezav/gitleaks/audit" "github.com/zricethezav/gitleaks/config" "github.com/zricethezav/gitleaks/hosts" "github.com/zricethezav/gitleaks/manager" "github.com/zricethezav/gitleaks/options" - "io/ioutil" - "os" - "time" + + "github.com/hako/durafmt" + log "github.com/sirupsen/logrus" ) func main() { diff --git a/manager/manager.go b/manager/manager.go index c6889f69..c4d9baae 100644 --- a/manager/manager.go +++ b/manager/manager.go @@ -6,18 +6,20 @@ import ( "encoding/hex" "encoding/json" "fmt" - "github.com/hako/durafmt" - "github.com/mattn/go-colorable" - log "github.com/sirupsen/logrus" - "github.com/zricethezav/gitleaks/config" - "github.com/zricethezav/gitleaks/options" - "gopkg.in/src-d/go-git.v4" "os" "os/signal" "runtime" "sync" "text/tabwriter" "time" + + "github.com/zricethezav/gitleaks/config" + "github.com/zricethezav/gitleaks/options" + + "github.com/hako/durafmt" + "github.com/mattn/go-colorable" + log "github.com/sirupsen/logrus" + "gopkg.in/src-d/go-git.v4" ) // Manager is a struct containing options and configs as well CloneOptions and CloneDir. diff --git a/options/options.go b/options/options.go index 0bc0cf76..f222a69d 100644 --- a/options/options.go +++ b/options/options.go @@ -2,16 +2,18 @@ package options import ( "fmt" - "github.com/jessevdk/go-flags" - log "github.com/sirupsen/logrus" - "github.com/zricethezav/gitleaks/version" - "gopkg.in/src-d/go-git.v4" - "gopkg.in/src-d/go-git.v4/plumbing/transport/http" - "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh" "io/ioutil" "os" "os/user" "strings" + + "github.com/zricethezav/gitleaks/version" + + "github.com/jessevdk/go-flags" + log "github.com/sirupsen/logrus" + "gopkg.in/src-d/go-git.v4" + "gopkg.in/src-d/go-git.v4/plumbing/transport/http" + "gopkg.in/src-d/go-git.v4/plumbing/transport/ssh" ) // No leaks or early exit due to invalid options @@ -72,7 +74,11 @@ func ParseOptions() (Options, error) { } if opts.Version { - fmt.Printf("%s\n", version.Version) + if version.Version == "" { + fmt.Println("Gitleaks uses LDFLAGS to pull most recent version. Build with 'make build' for version") + } else { + fmt.Printf("%s\n", version.Version) + } os.Exit(Success) }