mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 13:14:22 +01:00
Merge pull request #224 from eargollo/overwrite-error
Solved bug on error being overwritten and not passed to postAudit, closes #223
This commit is contained in:
4 files changed
+22
-13
No files matched your search
@@ -2,14 +2,19 @@ package main
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"github.com/zricethezav/gitleaks/src"
|
gitleaks "github.com/zricethezav/gitleaks/src"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
report, err := gitleaks.Run(gitleaks.ParseOpts())
|
report, err := gitleaks.Run(gitleaks.ParseOpts())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if strings.Contains(err.Error(), "whitelisted") {
|
||||||
|
log.Info(err.Error())
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
log.Error(err)
|
log.Error(err)
|
||||||
os.Exit(gitleaks.ErrExit)
|
os.Exit(gitleaks.ErrExit)
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-9
@@ -3,7 +3,6 @@ package gitleaks
|
|||||||
import (
|
import (
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -60,7 +59,8 @@ func Run(optsL *Options) (*Report, error) {
|
|||||||
|
|
||||||
// start audits
|
// start audits
|
||||||
if opts.Repo != "" || opts.RepoPath != "" {
|
if opts.Repo != "" || opts.RepoPath != "" {
|
||||||
repoInfo, err := newRepoInfo()
|
var repoInfo *RepoInfo
|
||||||
|
repoInfo, err = newRepoInfo()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
goto postAudit
|
goto postAudit
|
||||||
}
|
}
|
||||||
@@ -70,7 +70,8 @@ func Run(optsL *Options) (*Report, error) {
|
|||||||
}
|
}
|
||||||
leaks, err = repoInfo.audit()
|
leaks, err = repoInfo.audit()
|
||||||
} else if opts.OwnerPath != "" {
|
} else if opts.OwnerPath != "" {
|
||||||
repoDs, err := discoverRepos(opts.OwnerPath)
|
var repoDs []*RepoInfo
|
||||||
|
repoDs, err = discoverRepos(opts.OwnerPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
goto postAudit
|
goto postAudit
|
||||||
}
|
}
|
||||||
@@ -96,12 +97,7 @@ func Run(optsL *Options) (*Report, error) {
|
|||||||
|
|
||||||
postAudit:
|
postAudit:
|
||||||
if err != nil {
|
if err != nil {
|
||||||
if strings.Contains(err.Error(), "whitelisted") {
|
return &Report{}, err
|
||||||
log.Info(err.Error())
|
|
||||||
os.Exit(0)
|
|
||||||
}
|
|
||||||
log.Error(err)
|
|
||||||
os.Exit(ErrExit)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if opts.Report != "" {
|
if opts.Report != "" {
|
||||||
|
|||||||
@@ -207,7 +207,7 @@ func TestRun(t *testing.T) {
|
|||||||
},
|
},
|
||||||
description: "test empty",
|
description: "test empty",
|
||||||
numLeaks: 0,
|
numLeaks: 0,
|
||||||
expectedErrMsg: "reference not found",
|
expectedErrMsg: "repository not found",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
testOpts: &Options{
|
testOpts: &Options{
|
||||||
|
|||||||
+10
-2
@@ -15,6 +15,7 @@ import (
|
|||||||
diffType "gopkg.in/src-d/go-git.v4/plumbing/format/diff"
|
diffType "gopkg.in/src-d/go-git.v4/plumbing/format/diff"
|
||||||
"gopkg.in/src-d/go-git.v4/plumbing/object"
|
"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/plumbing/storer"
|
||||||
|
gitHttp "gopkg.in/src-d/go-git.v4/plumbing/transport/http"
|
||||||
"gopkg.in/src-d/go-git.v4/storage/memory"
|
"gopkg.in/src-d/go-git.v4/storage/memory"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -98,10 +99,17 @@ func (repoInfo *RepoInfo) clone() error {
|
|||||||
Auth: config.sshAuth,
|
Auth: config.sshAuth,
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
options := &git.CloneOptions{
|
||||||
URL: opts.Repo,
|
URL: opts.Repo,
|
||||||
Progress: os.Stdout,
|
Progress: os.Stdout,
|
||||||
})
|
}
|
||||||
|
if os.Getenv("GITHUB_TOKEN") != "" {
|
||||||
|
options.Auth = &gitHttp.BasicAuth{
|
||||||
|
Username: "fakeUsername", // yes, this can be anything except an empty string
|
||||||
|
Password: os.Getenv("GITHUB_TOKEN"),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
repo, err = git.Clone(memory.NewStorage(), nil, options)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
repoInfo.repository = repo
|
repoInfo.repository = repo
|
||||||
|
|||||||
Reference in new issue
Block a user