From 1a8fcc878aeb73f2bcc2bd2a26cf912ffd0f2495 Mon Sep 17 00:00:00 2001 From: Jon Hadfield Date: Mon, 23 Sep 2024 11:18:30 +0100 Subject: [PATCH] only create clients if provider enabled. fail if no providers enabled. --- process/process.go | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/process/process.go b/process/process.go index d34facc..1ee09bc 100644 --- a/process/process.go +++ b/process/process.go @@ -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) @@ -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 } @@ -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