dnscontrol/commands/createDomains.go
Patrick Gaskin 2f83aa9302 Internals: Switch to v2 go.mod, drop GOPATH, and fix Azure Pipelines (#595)
* Switched to v2 go.mod

Also set GO111MODULE=on in build stuff to always use Go modules
even when in GOPATH.

* Ensure go.mod, go.sum, and vendor are up to date

* Attempt to fix Azure pipelines

* Add set -e to properly fail on exit (it didn't seem to be
  propagating properly before).
* Set workingDirectory for GoFmt and GoGen (this might be why it
  fails unlike compile and unitests).

* Another attempt to fix Azure Pipelines

* Use the Go env template for all go-related jobs.

* Completely fixed Azure Pipelines

* Added a display name to GoFmt for consistency.
* Fixed diffs for GoFmt and GoGen.
* Show git status for checks.

* Drop GOPATH for tests

TODO: Do the same for integration tests.

* Drop GOPATH for integration tests

* Show more diffs

* Regenerate provider support matrix

This wasn't done in #590...
2020-01-28 10:42:31 -05:00

57 lines
1.4 KiB
Go

package commands
import (
"fmt"
"github.com/StackExchange/dnscontrol/v2/providers"
"github.com/urfave/cli"
)
var _ = cmd(catUtils, func() *cli.Command {
var args CreateDomainsArgs
return &cli.Command{
Name: "create-domains",
Usage: "ensures that all domains in your configuration are present in all providers.",
Action: func(ctx *cli.Context) error {
return exit(CreateDomains(args))
},
Flags: args.flags(),
}
}())
// CreateDomainsArgs args required for the create-domain subcommand.
type CreateDomainsArgs struct {
GetDNSConfigArgs
GetCredentialsArgs
}
func (args *CreateDomainsArgs) flags() []cli.Flag {
flags := args.GetDNSConfigArgs.flags()
flags = append(flags, args.GetCredentialsArgs.flags()...)
return flags
}
// CreateDomains contains all data/flags needed to run create-domains, independently of CLI.
func CreateDomains(args CreateDomainsArgs) error {
cfg, err := GetDNSConfig(args.GetDNSConfigArgs)
if err != nil {
return err
}
_, err = InitializeProviders(args.CredsFile, cfg, false)
if err != nil {
return err
}
for _, domain := range cfg.Domains {
fmt.Println("*** ", domain.Name)
for _, provider := range domain.DNSProviderInstances {
if creator, ok := provider.Driver.(providers.DomainCreator); ok {
fmt.Println(" -", provider.Name)
err := creator.EnsureDomainExists(domain.Name)
if err != nil {
fmt.Printf("Error creating domain: %s\n", err)
}
}
}
}
return nil
}