Skip to content

Commit

Permalink
feat(engine): make |detectionTimeout| configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
rgmz committed Dec 11, 2024
1 parent 6ceb490 commit ed2b244
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 4 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ var (
fail = cli.Flag("fail", "Exit with code 183 if results are found.").Bool()
verifiers = cli.Flag("verifier", "Set custom verification endpoints.").StringMap()
customVerifiersOnly = cli.Flag("custom-verifiers-only", "Only use custom verification endpoints.").Bool()
detectorTimeout = cli.Flag("detector-timeout", "Maximum time to spend scanning chunks per detector.").Duration()
archiveMaxSize = cli.Flag("archive-max-size", "Maximum size of archive to scan. (Byte units eg. 512B, 2KB, 4MB)").Bytes()
archiveMaxDepth = cli.Flag("archive-max-depth", "Maximum depth of archive to scan.").Int()
archiveTimeout = cli.Flag("archive-timeout", "Maximum time to spend extracting an archive.").Duration()
Expand Down Expand Up @@ -439,6 +440,9 @@ func run(state overseer.State) {
}
}

if *detectorTimeout != 0 {
engine.SetDetectorTimeout(*detectorTimeout)
}
if *archiveMaxSize != 0 {
handlers.SetArchiveMaxSize(int(*archiveMaxSize))
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/engine/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
)

const detectionTimeout = 10 * time.Second
var detectionTimeout = 10 * time.Second

var errOverlap = errors.New(
"More than one detector has found this result. For your safety, verification has been disabled." +
Expand Down Expand Up @@ -316,6 +316,9 @@ func NewEngine(ctx context.Context, cfg *Config) (*Engine, error) {
return engine, nil
}

// SetDetectorTimeout sets the maximum timeout for each detector to scan a chunk.
func SetDetectorTimeout(timeout time.Duration) { detectionTimeout = timeout }

// setDefaults ensures that if specific engine properties aren't provided,
// they're set to reasonable default values. It makes the engine robust to
// incomplete configuration.
Expand Down

0 comments on commit ed2b244

Please sign in to comment.