Bug fix and add authentication in shallow clone (#595)
This commit is contained in:
@@ -143,6 +143,12 @@ func run(state overseer.State) {
|
||||
fmt.Println("trufflehog " + version.BuildVersion)
|
||||
}
|
||||
|
||||
if *githubScanToken != "" {
|
||||
// NOTE: this kludge is here to do an authenticated shallow commit
|
||||
// TODO: refactor to better pass credentials
|
||||
os.Setenv("GITHUB_TOKEN", *githubScanToken)
|
||||
}
|
||||
|
||||
// When setting a base commit, chunks must be scanned in order.
|
||||
if *gitScanSinceCommit != "" {
|
||||
*concurrency = 1
|
||||
|
||||
+11
-1
@@ -22,6 +22,7 @@ import (
|
||||
"github.com/rs/zerolog"
|
||||
log "github.com/sirupsen/logrus"
|
||||
glgo "github.com/zricethezav/gitleaks/v8/detect/git"
|
||||
"golang.org/x/oauth2"
|
||||
"golang.org/x/sync/semaphore"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
@@ -496,12 +497,21 @@ func PrepareRepoSinceCommit(uriString, commitHash string) (string, bool, error)
|
||||
return PrepareRepo(uriString)
|
||||
}
|
||||
|
||||
owner, repoName, found := strings.Cut(uri.Path, "/")
|
||||
uriPath := strings.TrimPrefix(uri.Path, "/")
|
||||
owner, repoName, found := strings.Cut(uriPath, "/")
|
||||
if !found {
|
||||
return PrepareRepo(uriString)
|
||||
}
|
||||
|
||||
client := github.NewClient(nil)
|
||||
if token := os.Getenv("GITHUB_TOKEN"); token != "" {
|
||||
ts := oauth2.StaticTokenSource(
|
||||
&oauth2.Token{AccessToken: token},
|
||||
)
|
||||
tc := oauth2.NewClient(context.TODO(), ts)
|
||||
client = github.NewClient(tc)
|
||||
}
|
||||
|
||||
commit, _, err := client.Git.GetCommit(context.Background(), owner, repoName, commitHash)
|
||||
if err != nil {
|
||||
return PrepareRepo(uriString)
|
||||
|
||||
Reference in New Issue
Block a user