1
0
mirror of https://github.com/StackExchange/dnscontrol.git synced 2024-05-11 05:55:12 +00:00

Refactor: Move creds.json processing out of InitializeProviders (#1495)

* Rename providers/config to pkg/credsfile

* Refactor InitializeProviders in preparation for v3.16
This commit is contained in:
Tom Limoncelli
2022-05-04 11:02:36 -04:00
committed by GitHub
parent c8a5060dfb
commit 1c43d03d89
3 changed files with 19 additions and 12 deletions

View File

@ -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
}

View File

@ -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
}

View File

@ -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"]
}