[fix] Move detector initialization to DefaultDetectors function (#3341)
Lint / golangci-lint (push) Waiting to run
Lint / semgrep (push) Waiting to run
Release / Release (push) Waiting to run
Scan for secrets / test (push) Waiting to run
Snifftest / Run Snifftest (push) Waiting to run
Test / test (push) Waiting to run
Test / test-community (push) Waiting to run

This commit is contained in:
Miccah
2024-09-26 14:03:24 -07:00
committed by GitHub
parent f3630da1e0
commit 0328a19a9d
2 changed files with 21 additions and 24 deletions
+18 -1
View File
@@ -806,7 +806,7 @@ import (
)
func DefaultDetectors() []detectors.Detector {
return []detectors.Detector{
detectorList := []detectors.Detector{
&heroku.Scanner{},
&pypi.Scanner{},
&linearapi.Scanner{},
@@ -1635,6 +1635,23 @@ func DefaultDetectors() []detectors.Detector {
nvapi.Scanner{},
railwayapp.Scanner{},
}
// Automatically initialize all detectors that implement
// EndpointCustomizer and/or CloudProvider interfaces.
for _, d := range detectorList {
customizer, ok := d.(detectors.EndpointCustomizer)
if !ok {
continue
}
// Default to always use the cloud endpoints (if available) and the found endpoints.
customizer.UseFoundEndpoints(true)
customizer.UseCloudEndpoint(true)
if cloudProvider, ok := d.(detectors.CloudProvider); ok {
customizer.SetCloudEndpoint(cloudProvider.CloudEndpoint())
}
}
return detectorList
}
func DefaultDetectorTypesImplementing[T any]() map[detectorspb.DetectorType]struct{} {
+3 -23
View File
@@ -267,21 +267,6 @@ func NewEngine(ctx context.Context, cfg *Config) (*Engine, error) {
if err != nil {
return nil, err
}
// Abuse filters to initialize endpoint customizer detectors.
filters = append(filters, func(d detectors.Detector) bool {
customizer, ok := d.(detectors.EndpointCustomizer)
if !ok {
return true
}
customizer.UseFoundEndpoints(true)
customizer.UseCloudEndpoint(true)
if cloudProvider, ok := d.(detectors.CloudProvider); ok {
customizer.SetCloudEndpoint(cloudProvider.CloudEndpoint())
}
return true
})
if len(detectorsWithCustomVerifierEndpoints) > 0 {
filters = append(filters, func(d detectors.Detector) bool {
urls, ok := getWithDetectorID(d, detectorsWithCustomVerifierEndpoints)
@@ -293,20 +278,15 @@ func NewEngine(ctx context.Context, cfg *Config) (*Engine, error) {
return false
}
if !cfg.CustomVerifiersOnly || len(urls) == 0 {
customizer.UseFoundEndpoints(true)
customizer.UseCloudEndpoint(true)
if cfg.CustomVerifiersOnly && len(urls) > 0 {
customizer.UseCloudEndpoint(false)
customizer.UseFoundEndpoints(false)
}
if err := customizer.SetConfiguredEndpoints(urls...); err != nil {
return false
}
cloudProvider, ok := d.(detectors.CloudProvider)
if ok {
customizer.SetCloudEndpoint(cloudProvider.CloudEndpoint())
}
return true
})
}