diff --git a/internal/core/analysis.go b/internal/core/analysis.go index 4c71fb2..e31e9e1 100644 --- a/internal/core/analysis.go +++ b/internal/core/analysis.go @@ -22,6 +22,10 @@ import ( "gopkg.in/src-d/go-git.v4/plumbing/object" ) +type threadID int + +const TID threadID = 0 + // AnalyzeRepositories will clone the repos, grab their history for analysis of files and content. // // Before the analysis is done we also check various conditions that can be thought of as filters and @@ -72,7 +76,7 @@ func AnalyzeRepositories(ctx context.Context, sess *session.Session, st *stats.S func analyzeWorker(ctx context.Context, workerID int, wg *sync.WaitGroup, ch chan coreapi.Repository, sess *session.Session, st *stats.Stats) { log := log.Log - ctxworker := context.WithValue(ctx, "tid", workerID) + ctxworker := context.WithValue(ctx, TID, workerID) for { select { case <-ctx.Done(): @@ -114,7 +118,7 @@ func cleanUpPath(path string) { func analyzeHistory(ctx context.Context, sess *session.Session, clone *_git.Repository, path string, repo coreapi.Repository) { stats := sess.State.Stats log := log.Log - tid := ctx.Value("tid") + tid := ctx.Value(TID) // Get the full commit history for the repo history, err := git.GetRepositoryHistory(clone) if err != nil { @@ -154,7 +158,7 @@ func analyzeHistory(ctx context.Context, sess *session.Session, clone *_git.Repo func isDirtyCommit(ctx context.Context, sess *session.Session, commit *object.Commit, repo coreapi.Repository, clone *_git.Repository, path string) bool { // stats := sess.State.Stats log := log.Log - tid := ctx.Value("tid") + tid := ctx.Value(TID) // This will be used to increment the dirty commit stat if any matches are found. A dirty commit // means that a secret was found in that commit. This provides an easier way to manually to look // through the commit history of a given repo. @@ -173,7 +177,7 @@ func isDirtyCommit(ctx context.Context, sess *session.Session, commit *object.Co func AnalyzeObject(ctx context.Context, sess *session.Session, change *object.Change, commit *object.Commit, filepath string, repo coreapi.Repository) bool { log := log.Log - tid := ctx.Value("tid") + tid := ctx.Value(TID) cfg := sess.Config fPath := filepath diff --git a/internal/pkg/scan/localpath/localpath.go b/internal/pkg/scan/localpath/localpath.go index 284cf26..eb701a5 100644 --- a/internal/pkg/scan/localpath/localpath.go +++ b/internal/pkg/scan/localpath/localpath.go @@ -48,7 +48,7 @@ func (l Localpath) Run() error { // By default we display a header to the user giving basic info about application. This will not be displayed // during a silent run which is the default when using this in an automated fashion. banner.HeaderInfo(cfg.Global, sess.State.Stats.StartedAt.Format(time.RFC3339), len(sess.Signatures)) - ctxworker := context.WithValue(ctx, "tid", 0) + ctxworker := context.WithValue(ctx, core.TID, 0) for _, p := range cfg.Local.Paths { if util.PathExists(p) { last := p[len(p)-1:]