Skip to content

Commit

Permalink
only create clients if provider enabled. fail if no providers enabled.
Browse files Browse the repository at this point in the history
  • Loading branch information
jonhadfield committed Sep 23, 2024
1 parent f3d1b54 commit 1a8fcc8
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions process/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,15 @@ func getEnabledProviderClients(sess session.Session) (map[string]providers.Provi
{Name: virustotal.ProviderName, Enabled: sess.Providers.VirusTotal.Enabled, APIKey: sess.Providers.VirusTotal.APIKey, NewClient: virustotal.NewProviderClient},
}

var enabled int

for _, provider := range pros {
if provider.Enabled == nil || !*provider.Enabled {
continue
}

enabled++

client, err := provider.NewClient(sess)
if err != nil {
return nil, fmt.Errorf("error creating %s client: %w", provider.Name, err)
Expand All @@ -99,6 +107,10 @@ func getEnabledProviderClients(sess session.Session) (map[string]providers.Provi
}
}

if enabled == 0 {
return nil, fmt.Errorf("no providers enabled")
}

return runners, nil
}

Expand Down Expand Up @@ -225,6 +237,10 @@ func initialiseProviders(l *slog.Logger, runners map[string]providers.ProviderCl
}

for name, runner := range runners {
if !runner.Enabled() {
continue
}

g.Go(func() error {
name := name

Expand Down

0 comments on commit 1a8fcc8

Please sign in to comment.