Compare commits

..
12 Commits
Author SHA1 Message Date
Zachary Rice 8eb28cbb4c Merge pull request #91 from zricethezav/audit_branch
test branch opt, bump changelog
2018-09-12 19:33:46 -05:00
zach rice 9dc9a8e62a bump version 2018-09-12 19:23:20 -05:00
zach rice e6caef0d94 test branch opt, bump changelog 2018-09-12 19:17:04 -05:00
Zachary Rice 5e289ed0cc Merge pull request #88 from Fabse333/master
Added Support for branches
2018-09-12 12:41:00 -05:00
Fabian Helfert d99588fe19 Fixed failure when Branch option is ommited 2018-08-23 14:07:25 +02:00
Fabian Helfert a7ccb7a9d1 Added Support for branches 2018-08-23 13:50:32 +02:00
Zachary Rice f32abb921d Merge pull request #87 from nenadstojanovikj/patch-1
Update description to reflect regex
2018-08-22 09:41:28 -05:00
Nenad Stojanovikj e8851c1f99 Update description to reflect regex 2018-08-21 21:08:44 +02:00
Zachary Rice f3a8359ac0 Merge pull request #86 from zricethezav/patch-err-check
Patch err check
2018-08-11 15:33:39 -04:00
zach rice 829e8fed8c up check to warning msg 2018-08-11 14:30:34 -05:00
zach rice c7e3605bff bump patch 2018-08-11 14:29:23 -05:00
zach rice c1774b1596 err check on patch 2018-08-11 14:27:51 -05:00
4 changed files with 55 additions and 6 deletions

No files matched your search

+8
View File
@@ -1,6 +1,14 @@
CHANGELOG
=========
1.3.0
-----
- Target specific branch
1.2.1
-----
- Check errors when generating commit patch
1.2.0
-----
- Added support for providing an alternate GitHub URL to support scanning GitHub Enteprise repositories
+2 -2
View File
@@ -18,7 +18,7 @@ regex = '''-----BEGIN OPENSSH PRIVATE KEY-----'''
description = "Facebook"
regex = '''(?i)facebook.*['\"][0-9a-f]{32}['\"]'''
[[regexes]]
description = "Facebook"
description = "Twitter"
regex = '''(?i)twitter.*['\"][0-9a-zA-Z]{35,44}['\"]'''
[whitelist]
@@ -27,4 +27,4 @@ regexes = [
]
files = [
"(.*?)(jpg|gif|doc|pdf|bin|go)$"
]
]
+16
View File
@@ -339,6 +339,22 @@ func TestAuditRepo(t *testing.T) {
MaxGoRoutines: 2,
},
},
{
repo: leaksRepo,
description: "audit specific bad branch",
numLeaks: 2,
testOpts: Options{
Branch: "master",
},
},
{
repo: leaksRepo,
description: "audit specific good branch",
numLeaks: 0,
testOpts: Options{
Branch: "dev",
},
},
{
repo: leaksRepo,
description: "audit all branch",
+29 -4
View File
@@ -115,7 +115,7 @@ type Config struct {
}
const defaultGithubURL = "https://api.github.com/"
const version = "1.1.2"
const version = "1.3.0"
const defaultConfig = `
title = "gitleaks config"
# add regexes to the regex table
@@ -276,8 +276,8 @@ func getRepo() (Repo, error) {
r *git.Repository
)
log.Infof("cloning %s", opts.Repo)
if opts.Disk {
log.Infof("cloning %s", opts.Repo)
cloneTarget := fmt.Sprintf("%s/%x", dir, md5.Sum([]byte(fmt.Sprintf("%s%s", opts.GithubUser, opts.Repo))))
if opts.IncludePrivate {
r, err = git.PlainClone(cloneTarget, false, &git.CloneOptions{
@@ -293,8 +293,10 @@ func getRepo() (Repo, error) {
}
} else if opts.RepoPath != "" {
// use existing repo
log.Infof("opening %s", opts.Repo)
r, err = git.PlainOpen(opts.RepoPath)
} else {
log.Infof("cloning %s", opts.Repo)
if opts.IncludePrivate {
r, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
URL: opts.Repo,
@@ -351,7 +353,6 @@ func auditRef(r *git.Repository, ref *plumbing.Reference, commitWg *sync.WaitGro
if prevCommit == nil {
prevCommit = c
}
commitWg.Add(1)
go func(c *object.Commit, prevCommit *object.Commit) {
var (
@@ -359,7 +360,15 @@ func auditRef(r *git.Repository, ref *plumbing.Reference, commitWg *sync.WaitGro
filePath string
skipFile bool
)
patch, _ := c.Patch(prevCommit)
patch, err := c.Patch(prevCommit)
if err != nil {
log.Warnf("problem generating patch for commit: %s\n", c.Hash.String())
if limitGoRoutines {
<-semaphore
}
commitChan <- leaks
return
}
for _, f := range patch.FilePatches() {
skipFile = false
from, to := f.Files()
@@ -436,6 +445,22 @@ func auditRepo(r *git.Repository) ([]Leak, error) {
return nil
})
} else {
if opts.Branch != "" {
foundBranch := false
refs, _ := r.Storer.IterReferences()
branch := strings.Split(opts.Branch, "/")[len(strings.Split(opts.Branch, "/"))-1]
err = refs.ForEach(func(refBranch *plumbing.Reference) error {
if strings.Split(refBranch.Name().String(), "/")[len(strings.Split(refBranch.Name().String(), "/"))-1] == branch {
foundBranch = true
ref = refBranch
}
return nil
})
if foundBranch == false {
log.Fatalf("No branch with name", opts.Branch)
return nil, nil
}
}
auditRef(r, ref, &commitWg, commitChan)
}