mirror of
https://github.com/gitleaks/gitleaks.git
synced 2026-11-30 21:24:21 +01:00
Merge pull request #151 from AdamKobi/add_support_for_tokens
Add support for tokens
This commit is contained in:
2 files changed
+24
-2
No files matched your search
@@ -1,6 +1,10 @@
|
|||||||
CHANGELOG
|
CHANGELOG
|
||||||
=========
|
=========
|
||||||
|
|
||||||
|
1.21.0
|
||||||
|
----
|
||||||
|
- added support for cloning repositories using github api
|
||||||
|
|
||||||
1.20.0
|
1.20.0
|
||||||
----
|
----
|
||||||
- adding gitlab user and group support
|
- adding gitlab user and group support
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ import (
|
|||||||
log "github.com/sirupsen/logrus"
|
log "github.com/sirupsen/logrus"
|
||||||
"golang.org/x/oauth2"
|
"golang.org/x/oauth2"
|
||||||
git "gopkg.in/src-d/go-git.v4"
|
git "gopkg.in/src-d/go-git.v4"
|
||||||
|
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"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -177,6 +178,7 @@ func cloneGithubRepo(githubRepo *github.Repository) (*RepoDescriptor, error) {
|
|||||||
repo *git.Repository
|
repo *git.Repository
|
||||||
err error
|
err error
|
||||||
)
|
)
|
||||||
|
githubToken := os.Getenv("GITHUB_TOKEN")
|
||||||
if opts.ExcludeForks && githubRepo.GetFork() {
|
if opts.ExcludeForks && githubRepo.GetFork() {
|
||||||
return nil, fmt.Errorf("skipping %s, excluding forks", *githubRepo.Name)
|
return nil, fmt.Errorf("skipping %s, excluding forks", *githubRepo.Name)
|
||||||
}
|
}
|
||||||
@@ -191,22 +193,38 @@ func cloneGithubRepo(githubRepo *github.Repository) (*RepoDescriptor, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("unable to generater owner temp dir: %v", err)
|
return nil, fmt.Errorf("unable to generater owner temp dir: %v", err)
|
||||||
}
|
}
|
||||||
if sshAuth != nil {
|
if sshAuth != nil && githubToken == "" {
|
||||||
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
|
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
|
||||||
URL: *githubRepo.SSHURL,
|
URL: *githubRepo.SSHURL,
|
||||||
Auth: sshAuth,
|
Auth: sshAuth,
|
||||||
})
|
})
|
||||||
|
} else if githubToken != "" {
|
||||||
|
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
|
||||||
|
URL: *githubRepo.CloneURL,
|
||||||
|
Auth: &gitHttp.BasicAuth{
|
||||||
|
Username: "fakeUsername", // yes, this can be anything except an empty string
|
||||||
|
Password: githubToken,
|
||||||
|
},
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
|
repo, err = git.PlainClone(fmt.Sprintf("%s/%s", ownerDir, *githubRepo.Name), false, &git.CloneOptions{
|
||||||
URL: *githubRepo.CloneURL,
|
URL: *githubRepo.CloneURL,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if sshAuth != nil {
|
if sshAuth != nil && githubToken == "" {
|
||||||
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||||
URL: *githubRepo.SSHURL,
|
URL: *githubRepo.SSHURL,
|
||||||
Auth: sshAuth,
|
Auth: sshAuth,
|
||||||
})
|
})
|
||||||
|
} else if githubToken != "" {
|
||||||
|
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||||
|
URL: *githubRepo.CloneURL,
|
||||||
|
Auth: &gitHttp.BasicAuth{
|
||||||
|
Username: "fakeUsername", // yes, this can be anything except an empty string
|
||||||
|
Password: githubToken,
|
||||||
|
},
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
repo, err = git.Clone(memory.NewStorage(), nil, &git.CloneOptions{
|
||||||
URL: *githubRepo.CloneURL,
|
URL: *githubRepo.CloneURL,
|
||||||
|
|||||||
Reference in new issue
Block a user