Find, verify, and analyze leaked credentials
Go credentialsdevsecopsdynamic-analysisprecommitscanningsecretsecret-managementsecretssecuritysecurity-toolstrufflehogverification
Make prints to stdout serial. (#1597)
ahravb1947246d95f
diff --git a/pkg/output/github_actions.go b/pkg/output/github_actions.goindex 077a4da7f..d8d99eaf2 100644--- a/pkg/output/github_actions.go+++ b/pkg/output/github_actions.go@@ -4,6 +4,7 @@ import ("crypto/sha256""encoding/hex""fmt"+ "sync""github.com/trufflesecurity/trufflehog/v3/pkg/context""github.com/trufflesecurity/trufflehog/v3/pkg/detectors"@@ -13,7 +14,7 @@ import (var dedupeCache = make(map[string]struct{})// GitHubActionsPrinter is a printer that prints results in GitHub Actions format.-type GitHubActionsPrinter struct{}+type GitHubActionsPrinter struct{ mu sync.Mutex }func (p *GitHubActionsPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata) error {out := gitHubActionsOutputFormat{@@ -56,6 +57,8 @@ func (p *GitHubActionsPrinter) Print(_ context.Context, r *detectors.ResultWithM}dedupeCache[key] = struct{}{}+ p.mu.Lock()+ defer p.mu.Unlock()message := fmt.Sprintf("Found %s %s result π·π\n", verifiedStatus, out.DetectorType)if r.Result.DecoderType != detectorspb.DecoderType_PLAIN {message = fmt.Sprintf("Found %s %s result with %s encoding π·π\n", verifiedStatus, out.DetectorType, out.DecoderType)diff --git a/pkg/output/json.go b/pkg/output/json.goindex af15be63b..2510fdaf5 100644--- a/pkg/output/json.go+++ b/pkg/output/json.go@@ -3,6 +3,7 @@ package outputimport ("encoding/json""fmt"+ "sync""github.com/trufflesecurity/trufflehog/v3/pkg/context""github.com/trufflesecurity/trufflehog/v3/pkg/detectors"@@ -12,7 +13,7 @@ import ()// JSONPrinter is a printer that prints results in JSON format.-type JSONPrinter struct{}+type JSONPrinter struct{ mu sync.Mutex }func (p *JSONPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata) error {v := &struct {@@ -60,6 +61,9 @@ func (p *JSONPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata)if err != nil {return fmt.Errorf("could not marshal result: %w", err)}++ p.mu.Lock()fmt.Println(string(out))+ p.mu.Unlock()return nil}diff --git a/pkg/output/legacy_json.go b/pkg/output/legacy_json.goindex bbeea627a..5ea3f1d3d 100644--- a/pkg/output/legacy_json.go+++ b/pkg/output/legacy_json.go@@ -7,6 +7,7 @@ import ("net/url""os""strings"+ "sync"gogit "github.com/go-git/go-git/v5""github.com/go-git/go-git/v5/plumbing"@@ -20,7 +21,7 @@ import ()// LegacyJSONPrinter is a printer that prints results in legacy JSON format for backwards compatibility.-type LegacyJSONPrinter struct{}+type LegacyJSONPrinter struct{ mu sync.Mutex }func (p *LegacyJSONPrinter) Print(ctx context.Context, r *detectors.ResultWithMetadata) error {var repo string@@ -52,7 +53,10 @@ func (p *LegacyJSONPrinter) Print(ctx context.Context, r *detectors.ResultWithMeif err != nil {return fmt.Errorf("could not marshal result: %w", err)}++ p.mu.Lock()fmt.Println(string(out))+ p.mu.Unlock()return nil}diff --git a/pkg/output/plain.go b/pkg/output/plain.goindex ec70f8ae0..9629e4393 100644--- a/pkg/output/plain.go+++ b/pkg/output/plain.go@@ -5,6 +5,7 @@ import ("fmt""sort""strings"+ "sync""github.com/fatih/color""golang.org/x/text/cases"@@ -22,7 +23,7 @@ var ()// PlainPrinter is a printer that prints results in plain text format.-type PlainPrinter struct{}+type PlainPrinter struct{ mu sync.Mutex }func (p *PlainPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata) error {out := outputFormat{@@ -39,6 +40,8 @@ func (p *PlainPrinter) Print(_ context.Context, r *detectors.ResultWithMetadata)}printer := greenPrinter+ p.mu.Lock()+ defer p.mu.Unlock()if out.Verified {yellowPrinter.Print("Found verified result π·π\n")