Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[oc-147] - Add context to all git methods #901

Merged
merged 6 commits into from Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion hack/snifftest/main.go
Expand Up @@ -162,7 +162,7 @@ func main() {
defer sem.Release(1)
defer wgChunkers.Done()
log.Infof("cloning %s", r)
path, repo, err := git.CloneRepoUsingUnauthenticated(r)
path, repo, err := git.CloneRepoUsingUnauthenticated(ctx, r)
if err != nil {
log.Fatal(err)
}
Expand Down
4 changes: 2 additions & 2 deletions main.go
Expand Up @@ -185,7 +185,7 @@ func run(state overseer.State) {
var remote bool
switch cmd {
case gitScan.FullCommand():
repoPath, remote, err = git.PrepareRepoSinceCommit(*gitScanURI, *gitScanSinceCommit)
repoPath, remote, err = git.PrepareRepoSinceCommit(ctx, *gitScanURI, *gitScanSinceCommit)
if err != nil || repoPath == "" {
logrus.WithError(err).Fatal("error preparing git repo for scanning")
}
Expand Down Expand Up @@ -282,7 +282,7 @@ func run(state overseer.State) {

switch {
case *jsonLegacy:
output.PrintLegacyJSON(&r)
output.PrintLegacyJSON(ctx, &r)
case *jsonOut:
output.PrintJSON(&r)
default:
Expand Down
6 changes: 4 additions & 2 deletions pkg/engine/git_test.go
Expand Up @@ -18,8 +18,9 @@ type expResult struct {
}

func TestGitEngine(t *testing.T) {
ctx := context.Background()
repoUrl := "https://github.com/dustin-decker/secretsandstuff.git"
path, _, err := git.PrepareRepo(repoUrl)
path, _, err := git.PrepareRepo(ctx, repoUrl)
if err != nil {
t.Error(err)
}
Expand Down Expand Up @@ -89,8 +90,9 @@ func TestGitEngine(t *testing.T) {
}

func BenchmarkGitEngine(b *testing.B) {
ctx := context.Background()
repoUrl := "https://github.com/dustin-decker/secretsandstuff.git"
path, _, err := git.PrepareRepo(repoUrl)
path, _, err := git.PrepareRepo(ctx, repoUrl)
if err != nil {
b.Error(err)
}
Expand Down
6 changes: 4 additions & 2 deletions pkg/output/legacy_json.go
Expand Up @@ -13,12 +13,14 @@ import (
"github.com/go-git/go-git/v5/plumbing/object"
"github.com/sergi/go-diff/diffmatchpatch"
"github.com/sirupsen/logrus"

"github.com/trufflesecurity/trufflehog/v3/pkg/context"
"github.com/trufflesecurity/trufflehog/v3/pkg/detectors"
"github.com/trufflesecurity/trufflehog/v3/pkg/pb/sourcespb"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources/git"
)

func PrintLegacyJSON(r *detectors.ResultWithMetadata) {
func PrintLegacyJSON(ctx context.Context, r *detectors.ResultWithMetadata) {
var repo string
switch r.SourceType {
case sourcespb.SourceType_SOURCE_TYPE_GIT:
Expand All @@ -32,7 +34,7 @@ func PrintLegacyJSON(r *detectors.ResultWithMetadata) {
}

// cloning the repo again here is not great and only works with unauthed repos
repoPath, remote, err := git.PrepareRepo(repo)
repoPath, remote, err := git.PrepareRepo(ctx, repo)
if err != nil || repoPath == "" {
logrus.WithError(err).Fatal("error preparing git repo for scanning")
}
Expand Down