diff --git a/pkg/engine/defaults.go b/pkg/engine/defaults.go index e592e206b783..7bebe8197f63 100644 --- a/pkg/engine/defaults.go +++ b/pkg/engine/defaults.go @@ -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{} { diff --git a/pkg/engine/engine.go b/pkg/engine/engine.go index 289d7acdee66..454330d52d52 100644 --- a/pkg/engine/engine.go +++ b/pkg/engine/engine.go @@ -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 }) }