mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 21:24:21 +01:00
Updating Makefile, making in-memory default, adding disk option
This commit is contained in:
1 parent
ebb9be999f
commit
e0c717c3a3
4 files changed
+58
-57
No files matched your search
@@ -19,3 +19,4 @@ build-all:
|
|||||||
env GOOS="linux" GOARCH="arm" go build -o "build/gitleaks-linux-arm"
|
env GOOS="linux" GOARCH="arm" go build -o "build/gitleaks-linux-arm"
|
||||||
env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips"
|
env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips"
|
||||||
env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips"
|
env GOOS="linux" GOARCH="mips" go build -o "build/gitleaks-linux-mips"
|
||||||
|
env GOOS="darwin" GOARCH="amd64" go build -o "build/gitleaks-darwin-amd64"
|
||||||
@@ -30,7 +30,7 @@ Application Options:
|
|||||||
--repo-path= Path to repo
|
--repo-path= Path to repo
|
||||||
--owner-path= Path to owner directory (repos discovered)
|
--owner-path= Path to owner directory (repos discovered)
|
||||||
--max-go= Maximum number of concurrent go-routines gitleaks spawns
|
--max-go= Maximum number of concurrent go-routines gitleaks spawns
|
||||||
-m, --in-memory Run gitleaks in memory
|
--disk Clones repo(s) to disk
|
||||||
--all-refs run audit on all refs
|
--all-refs run audit on all refs
|
||||||
--single-search= single regular expression to search for
|
--single-search= single regular expression to search for
|
||||||
--config= path to gitleaks config
|
--config= path to gitleaks config
|
||||||
|
|||||||
+10
-10
@@ -85,10 +85,10 @@ func TestGetRepo(t *testing.T) {
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
Repo: "https://github.com/gitleakstest/gronit",
|
Repo: "https://github.com/gitleakstest/gronit",
|
||||||
InMem: true,
|
Disk: true,
|
||||||
},
|
},
|
||||||
description: "test inmem clone remote repo",
|
description: "test on disk clone remote repo",
|
||||||
expectedErrMsg: "",
|
expectedErrMsg: "",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -117,7 +117,7 @@ func TestGetRepo(t *testing.T) {
|
|||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
Repo: "https://github.com/gitleakstest/private",
|
Repo: "https://github.com/gitleakstest/private",
|
||||||
IncludePrivate: true,
|
IncludePrivate: true,
|
||||||
InMem: true,
|
Disk: true,
|
||||||
},
|
},
|
||||||
description: "test private repo",
|
description: "test private repo",
|
||||||
expectedErrMsg: "invalid auth method",
|
expectedErrMsg: "invalid auth method",
|
||||||
@@ -167,9 +167,9 @@ func TestGetOwnerRepo(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
GithubUser: "gitleakstest",
|
GithubUser: "gitleakstest",
|
||||||
InMem: true,
|
Disk: true,
|
||||||
},
|
},
|
||||||
description: "test github user in mem",
|
description: "test github user on disk ",
|
||||||
numRepos: 2,
|
numRepos: 2,
|
||||||
expectedErrMsg: "",
|
expectedErrMsg: "",
|
||||||
},
|
},
|
||||||
@@ -201,9 +201,9 @@ func TestGetOwnerRepo(t *testing.T) {
|
|||||||
{
|
{
|
||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
GithubOrg: "gitleakstestorg",
|
GithubOrg: "gitleakstestorg",
|
||||||
InMem: true,
|
Disk: true,
|
||||||
},
|
},
|
||||||
description: "test org in mem",
|
description: "test org on disk",
|
||||||
numRepos: 2,
|
numRepos: 2,
|
||||||
expectedErrMsg: "",
|
expectedErrMsg: "",
|
||||||
},
|
},
|
||||||
@@ -211,9 +211,9 @@ func TestGetOwnerRepo(t *testing.T) {
|
|||||||
testOpts: Options{
|
testOpts: Options{
|
||||||
GithubOrg: "gitleakstestorg",
|
GithubOrg: "gitleakstestorg",
|
||||||
IncludePrivate: true,
|
IncludePrivate: true,
|
||||||
InMem: true,
|
Disk: true,
|
||||||
},
|
},
|
||||||
description: "test private org in mem no ssh",
|
description: "test private org on disk no ssh",
|
||||||
numRepos: 0,
|
numRepos: 0,
|
||||||
expectedErrMsg: "no ssh auth available",
|
expectedErrMsg: "no ssh auth available",
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -79,7 +79,7 @@ type Options struct {
|
|||||||
|
|
||||||
// Process options
|
// Process options
|
||||||
MaxGoRoutines int `long:"max-go" description:"Maximum number of concurrent go-routines gitleaks spawns"`
|
MaxGoRoutines int `long:"max-go" description:"Maximum number of concurrent go-routines gitleaks spawns"`
|
||||||
InMem bool `short:"m" long:"in-memory" description:"Run gitleaks in memory"`
|
Disk bool `long:"disk" description:"Clones repo(s) to disk"`
|
||||||
AuditAllRefs bool `long:"all-refs" description:"run audit on all refs"`
|
AuditAllRefs bool `long:"all-refs" description:"run audit on all refs"`
|
||||||
SingleSearch string `long:"single-search" description:"single regular expression to search for"`
|
SingleSearch string `long:"single-search" description:"single regular expression to search for"`
|
||||||
ConfigPath string `long:"config" description:"path to gitleaks config"`
|
ConfigPath string `long:"config" description:"path to gitleaks config"`
|
||||||
@@ -200,7 +200,7 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !opts.InMem {
|
if opts.Disk {
|
||||||
// temporary directory where all the gitleaks plain clones will reside
|
// temporary directory where all the gitleaks plain clones will reside
|
||||||
dir, err = ioutil.TempDir("", "gitleaks")
|
dir, err = ioutil.TempDir("", "gitleaks")
|
||||||
defer os.RemoveAll(dir)
|
defer os.RemoveAll(dir)
|
||||||
@@ -254,23 +254,7 @@ func getRepo() (Repo, error) {
|
|||||||
r *git.Repository
|
r *git.Repository
|
||||||
)
|
)
|
||||||
|
|
||||||
if opts.InMem {
|
if opts.Disk {
|
||||||
if opts.IncludePrivate {
|
|
||||||
r, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
|
||||||
URL: opts.Repo,
|
|
||||||
Progress: os.Stdout,
|
|
||||||
Auth: sshAuth,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
r, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
|
||||||
URL: opts.Repo,
|
|
||||||
Progress: os.Stdout,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else if opts.RepoPath != "" {
|
|
||||||
// use existing repo
|
|
||||||
r, err = git.PlainOpen(opts.RepoPath)
|
|
||||||
} else {
|
|
||||||
cloneTarget := fmt.Sprintf("%s/%x", dir, md5.Sum([]byte(fmt.Sprintf("%s%s", opts.GithubUser, opts.Repo))))
|
cloneTarget := fmt.Sprintf("%s/%x", dir, md5.Sum([]byte(fmt.Sprintf("%s%s", opts.GithubUser, opts.Repo))))
|
||||||
if opts.IncludePrivate {
|
if opts.IncludePrivate {
|
||||||
r, err = git.PlainClone(cloneTarget, false, &git.CloneOptions{
|
r, err = git.PlainClone(cloneTarget, false, &git.CloneOptions{
|
||||||
@@ -284,6 +268,22 @@ func getRepo() (Repo, error) {
|
|||||||
Progress: os.Stdout,
|
Progress: os.Stdout,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
} else if opts.RepoPath != "" {
|
||||||
|
// use existing repo
|
||||||
|
r, err = git.PlainOpen(opts.RepoPath)
|
||||||
|
} else {
|
||||||
|
if opts.IncludePrivate {
|
||||||
|
r, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||||
|
URL: opts.Repo,
|
||||||
|
Progress: os.Stdout,
|
||||||
|
Auth: sshAuth,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
r, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||||
|
URL: opts.Repo,
|
||||||
|
Progress: os.Stdout,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Repo{}, err
|
return Repo{}, err
|
||||||
@@ -535,18 +535,7 @@ func getUserGithubRepos(ctx context.Context, listOpts *github.RepositoryListOpti
|
|||||||
|
|
||||||
for _, rDesc := range rs {
|
for _, rDesc := range rs {
|
||||||
log.Debugf("Cloning: %s from %s", *rDesc.Name, *rDesc.SSHURL)
|
log.Debugf("Cloning: %s from %s", *rDesc.Name, *rDesc.SSHURL)
|
||||||
if opts.InMem {
|
if opts.Disk {
|
||||||
if opts.IncludePrivate {
|
|
||||||
r, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
|
||||||
URL: *rDesc.SSHURL,
|
|
||||||
Auth: sshAuth,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
r, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
|
||||||
URL: *rDesc.CloneURL,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ownerDir, err := ioutil.TempDir(dir, opts.GithubUser)
|
ownerDir, err := ioutil.TempDir(dir, opts.GithubUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return repos, fmt.Errorf("unable to generater owner temp dir: %v", err)
|
return repos, fmt.Errorf("unable to generater owner temp dir: %v", err)
|
||||||
@@ -562,6 +551,17 @@ func getUserGithubRepos(ctx context.Context, listOpts *github.RepositoryListOpti
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if opts.IncludePrivate {
|
||||||
|
r, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||||
|
URL: *rDesc.SSHURL,
|
||||||
|
Auth: sshAuth,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
r, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||||
|
URL: *rDesc.CloneURL,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return repos, fmt.Errorf("problem cloning %s -- %v", *rDesc.Name, err)
|
return repos, fmt.Errorf("problem cloning %s -- %v", *rDesc.Name, err)
|
||||||
@@ -593,21 +593,7 @@ func getOrgGithubRepos(ctx context.Context, listOpts *github.RepositoryListByOrg
|
|||||||
rs, resp, err := client.Repositories.ListByOrg(ctx, opts.GithubOrg, listOpts)
|
rs, resp, err := client.Repositories.ListByOrg(ctx, opts.GithubOrg, listOpts)
|
||||||
for _, rDesc := range rs {
|
for _, rDesc := range rs {
|
||||||
log.Debugf("Cloning: %s from %s", *rDesc.Name, *rDesc.SSHURL)
|
log.Debugf("Cloning: %s from %s", *rDesc.Name, *rDesc.SSHURL)
|
||||||
if opts.InMem {
|
if opts.Disk {
|
||||||
if opts.IncludePrivate {
|
|
||||||
if sshAuth == nil {
|
|
||||||
return nil, fmt.Errorf("no ssh auth available")
|
|
||||||
}
|
|
||||||
r, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
|
||||||
URL: *rDesc.SSHURL,
|
|
||||||
Auth: sshAuth,
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
r, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
|
||||||
URL: *rDesc.CloneURL,
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ownerDir, err = ioutil.TempDir(dir, opts.GithubUser)
|
ownerDir, err = ioutil.TempDir(dir, opts.GithubUser)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return repos, fmt.Errorf("unable to generater owner temp dir: %v", err)
|
return repos, fmt.Errorf("unable to generater owner temp dir: %v", err)
|
||||||
@@ -626,6 +612,20 @@ func getOrgGithubRepos(ctx context.Context, listOpts *github.RepositoryListByOrg
|
|||||||
})
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if opts.IncludePrivate {
|
||||||
|
if sshAuth == nil {
|
||||||
|
return nil, fmt.Errorf("no ssh auth available")
|
||||||
|
}
|
||||||
|
r, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||||
|
URL: *rDesc.SSHURL,
|
||||||
|
Auth: sshAuth,
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
r, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||||
|
URL: *rDesc.CloneURL,
|
||||||
|
})
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
|
|||||||
Reference in new issue
Block a user