diff --git a/main.go b/main.go index 6b5458f1dd55..174f5307779a 100644 --- a/main.go +++ b/main.go @@ -50,7 +50,7 @@ var ( concurrency = cli.Flag("concurrency", "Number of concurrent workers.").Default(strconv.Itoa(runtime.NumCPU())).Int() noVerification = cli.Flag("no-verification", "Don't verify the results.").Bool() onlyVerified = cli.Flag("only-verified", "Only output verified results.").Hidden().Bool() - results = cli.Flag("results", "Specifies which type(s) of results to output: verified, unknown, unverified. This flag can be repeated. Defaults to all types.").Enums("verified", "unknown", "unverified") + results = cli.Flag("results", "Specifies which type(s) of results to output: verified, unknown, unverified. This flag can be repeated. Defaults to all types.").Default("verified,unknown").String() allowVerificationOverlap = cli.Flag("allow-verification-overlap", "Allow verification of similar credentials across detectors").Bool() filterUnverified = cli.Flag("filter-unverified", "Only output first unverified result per chunk per detector if there are more than one results.").Bool() @@ -409,7 +409,7 @@ func run(state overseer.State) { } if *onlyVerified { - r := []string{"verified"} + r := "verified" results = &r } diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index c545778156ce..92c3648f32e8 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -7,6 +7,8 @@ import ( "fmt" "io" "runtime" + "slices" + "strings" "sync" "sync/atomic" "time" @@ -14,7 +16,6 @@ import ( "github.com/adrg/strutil" "github.com/adrg/strutil/metrics" lru "github.com/hashicorp/golang-lru/v2" - "golang.org/x/exp/slices" "google.golang.org/protobuf/proto" "github.com/trufflesecurity/trufflehog/v3/pkg/common" @@ -167,20 +168,28 @@ func WithFilterEntropy(entropy float64) Option { } } -// WithResults sets the |logVerificationErrors| flag on the engine. -// If set to true, the engine will print results with verification errors, -// even if the result is unverified and |onlyVerified| is true. -func WithResults(results []string) Option { +var expectedResults = []string{"verified", "unknown", "unverified"} + +// WithResults defines which results will be printed by the engine. +func WithResults(results string) Option { return func(e *Engine) { - if len(results) > 0 { - if slices.Contains(results, "verified") { - e.notifyVerifiedResults = true - } - if slices.Contains(results, "unknown") { - e.notifyUnknownResults = true - } - if slices.Contains(results, "unverified") { - e.notifyUnverifiedResults = true + values := strings.Split(strings.ToLower(results), ",") + + if len(values) > 0 { + for _, value := range values { + if slices.Contains(expectedResults, value) { + switch value { + case "verified": + e.notifyVerifiedResults = true + case "unknown": + e.notifyUnknownResults = true + case "unverified": + e.notifyUnverifiedResults = true + } + } else { + // TODO: Log/handle this error. + fmt.Printf("Uh oh!") + } } } else { e.notifyVerifiedResults = true