Skip to content

Commit

Permalink
wip: parse --results flag
Browse files Browse the repository at this point in the history
  • Loading branch information
rgmz authored and Richard Gomez committed Mar 8, 2024
1 parent 2ebe0ee commit 3fd6f3c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 16 deletions.
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -409,7 +409,7 @@ func run(state overseer.State) {
}

if *onlyVerified {
r := []string{"verified"}
r := "verified"
results = &r
}

Expand Down
37 changes: 23 additions & 14 deletions pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ import (
"fmt"
"io"
"runtime"
"slices"
"strings"
"sync"
"sync/atomic"
"time"

"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"
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 3fd6f3c

Please sign in to comment.