Files
trufflehog/pkg/engine/scan.go
Miccah ce3f2aeb62 Add support for defining sources via a config file (#4172)
* Add config.proto

* Make protos

* Add ConfigurableSource implementation

* Parse config protoyaml into configured sources

* Refactor setting postman keywords into a helper method on the engine

* Add scan subcommand and plumb it all together

* Refactor ConfigurableSource to ConfiguredSource

* Export AhoCorasickCoreKeywords and return the set

* Disallow source configurations for non-scan subcommands

* Fix stdin scan compilation errors

* Rename command to multi-scan

* Add config file documentation

* Add more documentation for ConfiguredSource

* Replace initFunc closure with an embedded anonymous struct

* Assign directly to refs

* Fix typo
2025-06-06 07:46:31 -07:00

37 lines
1.3 KiB
Go

package engine
import (
"github.com/trufflesecurity/trufflehog/v3/pkg/context"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources"
"github.com/trufflesecurity/trufflehog/v3/pkg/sources/postman"
)
// ScanConfig starts a scan of all of the configured (but not initialized)
// sources and returns their job references. If there is an error during
// initialization or starting of the scan, an error is returned along with the
// references that successfully started up to that point.
func (e *Engine) ScanConfig(ctx context.Context, configuredSources ...sources.ConfiguredSource) ([]sources.JobProgressRef, error) {
var refs []sources.JobProgressRef
for _, configuredSource := range configuredSources {
sourceID, jobID, _ := e.sourceManager.GetIDs(ctx, configuredSource.Name, configuredSource.SourceType())
source, err := configuredSource.Init(ctx, sourceID, jobID)
if err != nil {
return refs, err
}
// Postman needs special initialization to set Keywords from
// the engine.
if postmanSource, ok := source.(*postman.Source); ok {
postmanSource.DetectorKeywords = e.AhoCorasickCoreKeywords()
}
// Start the scan.
ref, err := e.sourceManager.EnumerateAndScan(ctx, configuredSource.Name, source)
if err != nil {
return refs, err
}
refs = append(refs, ref)
}
return refs, nil
}