[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 { func DefaultDetectors() []detectors.Detector {
return []detectors.Detector{ detectorList := []detectors.Detector{
&heroku.Scanner{}, &heroku.Scanner{},
&pypi.Scanner{}, &pypi.Scanner{},
&linearapi.Scanner{}, &linearapi.Scanner{},
@@ -1635,6 +1635,23 @@ func DefaultDetectors() []detectors.Detector {
nvapi.Scanner{}, nvapi.Scanner{},
railwayapp.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{} { 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 { if err != nil {
return nil, err 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 { if len(detectorsWithCustomVerifierEndpoints) > 0 {
filters = append(filters, func(d detectors.Detector) bool { filters = append(filters, func(d detectors.Detector) bool {
urls, ok := getWithDetectorID(d, detectorsWithCustomVerifierEndpoints) urls, ok := getWithDetectorID(d, detectorsWithCustomVerifierEndpoints)
@@ -293,20 +278,15 @@ func NewEngine(ctx context.Context, cfg *Config) (*Engine, error) {
return false return false
} }
if !cfg.CustomVerifiersOnly || len(urls) == 0 { if cfg.CustomVerifiersOnly && len(urls) > 0 {
customizer.UseFoundEndpoints(true) customizer.UseCloudEndpoint(false)
customizer.UseCloudEndpoint(true) customizer.UseFoundEndpoints(false)
} }
if err := customizer.SetConfiguredEndpoints(urls...); err != nil { if err := customizer.SetConfiguredEndpoints(urls...); err != nil {
return false return false
} }
cloudProvider, ok := d.(detectors.CloudProvider)
if ok {
customizer.SetCloudEndpoint(cloudProvider.CloudEndpoint())
}
return true return true
}) })
} }