diff --git a/commands/createDomains.go b/commands/createDomains.go index 7bc14504f..6c70187de 100644 --- a/commands/createDomains.go +++ b/commands/createDomains.go @@ -3,6 +3,7 @@ package commands import ( "fmt" + "github.com/StackExchange/dnscontrol/v3/pkg/credsfile" "github.com/StackExchange/dnscontrol/v3/providers" "github.com/urfave/cli/v2" ) @@ -37,7 +38,11 @@ func CreateDomains(args CreateDomainsArgs) error { if err != nil { return err } - _, err = InitializeProviders(args.CredsFile, cfg, false) + providerConfigs, err := credsfile.LoadProviderConfigs(args.CredsFile) + if err != nil { + return err + } + _, err = InitializeProviders(cfg, providerConfigs, false) if err != nil { return err } diff --git a/commands/getCerts.go b/commands/getCerts.go index a2f388307..1f6bc2009 100644 --- a/commands/getCerts.go +++ b/commands/getCerts.go @@ -9,6 +9,7 @@ import ( "github.com/StackExchange/dnscontrol/v3/models" "github.com/StackExchange/dnscontrol/v3/pkg/acme" + "github.com/StackExchange/dnscontrol/v3/pkg/credsfile" "github.com/StackExchange/dnscontrol/v3/pkg/normalize" "github.com/StackExchange/dnscontrol/v3/pkg/printer" "github.com/urfave/cli/v2" @@ -141,7 +142,11 @@ func GetCerts(args GetCertsArgs) error { if PrintValidationErrors(errs) { return fmt.Errorf("exiting due to validation errors") } - notifier, err := InitializeProviders(args.CredsFile, cfg, args.Notify) + providerConfigs, err := credsfile.LoadProviderConfigs(args.CredsFile) + if err != nil { + return err + } + notifier, err := InitializeProviders(cfg, providerConfigs, args.Notify) if err != nil { return err } diff --git a/commands/previewPush.go b/commands/previewPush.go index 3ef5fe461..4e1703d23 100644 --- a/commands/previewPush.go +++ b/commands/previewPush.go @@ -103,8 +103,11 @@ func run(args PreviewArgs, push bool, interactive bool, out printer.CLI) error { if PrintValidationErrors(errs) { return fmt.Errorf("exiting due to validation errors") } - // TODO: - notifier, err := InitializeProviders(args.CredsFile, cfg, args.Notify) + providerConfigs, err := credsfile.LoadProviderConfigs(args.CredsFile) + if err != nil { + return err + } + notifier, err := InitializeProviders(cfg, providerConfigs, args.Notify) if err != nil { return err } @@ -180,18 +183,12 @@ DomainLoop: return nil } -// InitializeProviders takes a creds file path and a DNSConfig object. Creates all providers with the proper types, and returns them. -// nonDefaultProviders is a list of providers that should not be run unless explicitly asked for by flags. -func InitializeProviders(credsFile string, cfg *models.DNSConfig, notifyFlag bool) (notify notifications.Notifier, err error) { - var providerConfigs map[string]map[string]string +// InitializeProviders takes (fully processed) configuration and instantiates all providers and returns them. +func InitializeProviders(cfg *models.DNSConfig, providerConfigs map[string]map[string]string, notifyFlag bool) (notify notifications.Notifier, err error) { var notificationCfg map[string]string defer func() { notify = notifications.Init(notificationCfg) }() - providerConfigs, err = credsfile.LoadProviderConfigs(credsFile) - if err != nil { - return - } if notifyFlag { notificationCfg = providerConfigs["notifications"] }