diff --git a/main.go b/main.go index e77cfe2b1bd2..f5d36d7b3795 100644 --- a/main.go +++ b/main.go @@ -342,13 +342,13 @@ func run(state overseer.State) { // Verify that all the user-provided detectors support the optional // detector features. { - if err, id := verifyDetectorsAreVersioner(includeDetectorSet); err != nil { + if id, err := verifyDetectorsAreVersioner(includeDetectorSet); err != nil { logFatal(err, "invalid include list detector configuration", "detector", id) } - if err, id := verifyDetectorsAreVersioner(excludeDetectorSet); err != nil { + if id, err := verifyDetectorsAreVersioner(excludeDetectorSet); err != nil { logFatal(err, "invalid exclude list detector configuration", "detector", id) } - if err, id := verifyDetectorsAreVersioner(detectorsWithCustomVerifierEndpoints); err != nil { + if id, err := verifyDetectorsAreVersioner(detectorsWithCustomVerifierEndpoints); err != nil { logFatal(err, "invalid verifier detector configuration", "detector", id) } // Extra check for endpoint customization. @@ -608,6 +608,8 @@ func run(state overseer.State) { if err := e.ScanPostman(ctx, cfg); err != nil { logFatal(err, "Failed to scan Postman.") } + default: + logFatal(fmt.Errorf("invalid command"), "Command not recognized.") } // Wait for all workers to finish. @@ -691,7 +693,10 @@ func commaSeparatedToSlice(s []string) []string { } func printAverageDetectorTime(e *engine.Engine) { - fmt.Fprintln(os.Stderr, "Average detector time is the measurement of average time spent on each detector when results are returned.") + fmt.Fprintln( + os.Stderr, + "Average detector time is the measurement of average time spent on each detector when results are returned.", + ) for detectorName, duration := range e.GetDetectorsMetrics() { fmt.Fprintf(os.Stderr, "%s: %s\n", detectorName, duration) } @@ -724,7 +729,7 @@ func getWithDetectorID[T any](d detectors.Detector, data map[config.DetectorID]T // verifyDetectorsAreVersioner checks all keys in a provided map to verify the // provided type is actually a Versioner. -func verifyDetectorsAreVersioner[T any](data map[config.DetectorID]T) (error, config.DetectorID) { +func verifyDetectorsAreVersioner[T any](data map[config.DetectorID]T) (config.DetectorID, error) { isVersioner := engine.DefaultDetectorTypesImplementing[detectors.Versioner]() for id := range data { if id.Version == 0 { @@ -736,7 +741,7 @@ func verifyDetectorsAreVersioner[T any](data map[config.DetectorID]T) (error, co continue } // Version provided on a non-Versioner detector. - return fmt.Errorf("version provided but detector does not have a version"), id + return id, fmt.Errorf("version provided but detector does not have a version") } - return nil, config.DetectorID{} + return config.DetectorID{}, nil } diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 0a810c5e6980..7c1e2ca1bb60 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -30,7 +30,10 @@ import ( "github.com/trufflesecurity/trufflehog/v3/pkg/sources" ) -var overlapError = errors.New("More than one detector has found this result. For your safety, verification has been disabled. You can override this behavior by using the --allow-verification-overlap flag.") +var errOverlap = errors.New( + "More than one detector has found this result. For your safety, verification has been disabled." + + "You can override this behavior by using the --allow-verification-overlap flag.", +) // Metrics for the scan engine for external consumption. type Metrics struct { @@ -383,7 +386,9 @@ func (e *Engine) initialize(ctx context.Context, options ...Option) error { e.notifyVerifiedResults = true e.notifyUnknownResults = true e.notifyUnverifiedResults = true - e.verificationOverlapChunksChan = make(chan verificationOverlapChunk, defaultChannelBuffer*verificationOverlapChunksChanMultiplier) + e.verificationOverlapChunksChan = make( + chan verificationOverlapChunk, defaultChannelBuffer*verificationOverlapChunksChanMultiplier, + ) e.results = make(chan detectors.ResultWithMetadata, defaultChannelBuffer) e.dedupeCache = cache e.printer = new(output.PlainPrinter) @@ -405,8 +410,8 @@ func (e *Engine) initSourceManager(ctx context.Context) { const defaultOutputBufferSize = 64 opts := []func(*sources.SourceManager){ - sources.WithConcurrentSources(int(e.concurrency)), - sources.WithConcurrentUnits(int(e.concurrency)), + sources.WithConcurrentSources(e.concurrency), + sources.WithConcurrentUnits(e.concurrency), sources.WithSourceUnits(), sources.WithBufferedOutput(defaultOutputBufferSize), } @@ -528,7 +533,7 @@ func (e *Engine) startWorkers(ctx context.Context) { const notifierWorkerRatio = 4 maxNotifierWorkers := 1 if numWorkers := e.concurrency / notifierWorkerRatio; numWorkers > 0 { - maxNotifierWorkers = int(numWorkers) + maxNotifierWorkers = numWorkers } ctx.Logger().V(2).Info("starting notifier workers", "count", maxNotifierWorkers) for worker := 0; worker < maxNotifierWorkers; worker++ { @@ -745,7 +750,7 @@ func (e *Engine) verificationOverlapWorker(ctx context.Context) { if e.verificationOverlapTracker != nil { e.verificationOverlapTracker.increment() } - res.SetVerificationError(overlapError) + res.SetVerificationError(errOverlap) e.processResult(ctx, detectableChunk{ chunk: chunk.chunk, detector: detector,