mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 21:24:21 +01:00
added support for scanning only single remote branch
This commit is contained in:
1 parent
1cdf315bfa
commit
432c76a9d9
2 files changed
+24
-4
No files matched your search
@@ -159,6 +159,10 @@ func auditGithubRepos() ([]Leak, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
leaksFromRepo, err := auditGitRepo(repo)
|
leaksFromRepo, err := auditGitRepo(repo)
|
||||||
|
if err != nil {
|
||||||
|
log.Warn(err)
|
||||||
|
continue
|
||||||
|
}
|
||||||
if opts.Disk {
|
if opts.Disk {
|
||||||
os.RemoveAll(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name))
|
os.RemoveAll(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,8 +22,8 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"gopkg.in/src-d/go-git.v4/plumbing"
|
"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/object"
|
||||||
|
"gopkg.in/src-d/go-git.v4/plumbing/storer"
|
||||||
"gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
|
"gopkg.in/src-d/go-git.v4/plumbing/transport/ssh"
|
||||||
"gopkg.in/src-d/go-git.v4/storage/memory"
|
"gopkg.in/src-d/go-git.v4/storage/memory"
|
||||||
|
|
||||||
@@ -69,8 +69,9 @@ type Options struct {
|
|||||||
GitLabUser string `long:"gitlab-user" description:"GitLab user ID to audit"`
|
GitLabUser string `long:"gitlab-user" description:"GitLab user ID to audit"`
|
||||||
GitLabOrg string `long:"gitlab-org" description:"GitLab group ID to audit"`
|
GitLabOrg string `long:"gitlab-org" description:"GitLab group ID to audit"`
|
||||||
|
|
||||||
Commit string `short:"c" long:"commit" description:"sha of commit to stop at"`
|
Commit string `short:"c" long:"commit" description:"sha of commit to stop at"`
|
||||||
Depth int `long:"depth" description:"maximum commit depth"`
|
Depth int `long:"depth" description:"maximum commit depth"`
|
||||||
|
Branch plumbing.ReferenceName `long:"branch" description:"scan remote branch only (default is all)"`
|
||||||
|
|
||||||
// local target option
|
// local target option
|
||||||
RepoPath string `long:"repo-path" description:"Path to repo"`
|
RepoPath string `long:"repo-path" description:"Path to repo"`
|
||||||
@@ -429,6 +430,7 @@ func auditGitRepo(repo *RepoDescriptor) ([]Leak, error) {
|
|||||||
var (
|
var (
|
||||||
err error
|
err error
|
||||||
leaks []Leak
|
leaks []Leak
|
||||||
|
refs storer.ReferenceIter
|
||||||
)
|
)
|
||||||
for _, re := range whiteListRepos {
|
for _, re := range whiteListRepos {
|
||||||
if re.FindString(repo.name) != "" {
|
if re.FindString(repo.name) != "" {
|
||||||
@@ -439,7 +441,21 @@ func auditGitRepo(repo *RepoDescriptor) ([]Leak, error) {
|
|||||||
// clear commit cache
|
// clear commit cache
|
||||||
commitMap = make(map[string]bool)
|
commitMap = make(map[string]bool)
|
||||||
|
|
||||||
refs, err := repo.repository.Storer.IterReferences()
|
if opts.Branch != "" {
|
||||||
|
// var branchRef plumbing.ReferenceName
|
||||||
|
branchRef := "refs/remotes/origin/" + opts.Branch
|
||||||
|
log.Debugf("Auditing ref: %v", branchRef)
|
||||||
|
ref, err := repo.repository.Storer.Reference(branchRef)
|
||||||
|
if err != nil {
|
||||||
|
return leaks, err
|
||||||
|
}
|
||||||
|
branchLeaks := auditGitReference(repo, ref)
|
||||||
|
for _, leak := range branchLeaks {
|
||||||
|
leaks = append(leaks, leak)
|
||||||
|
}
|
||||||
|
return leaks, nil
|
||||||
|
}
|
||||||
|
refs, err = repo.repository.Storer.IterReferences()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return leaks, err
|
return leaks, err
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user