2017-09-13 22:00:41 +08:00
package commands
import (
"fmt"
2020-04-15 04:47:30 +08:00
"github.com/StackExchange/dnscontrol/v3/providers"
2020-02-04 01:44:11 +08:00
"github.com/urfave/cli/v2"
2017-09-13 22:00:41 +08:00
)
var _ = cmd ( catUtils , func ( ) * cli . Command {
var args CreateDomainsArgs
return & cli . Command {
Name : "create-domains" ,
2021-03-08 04:24:23 +08:00
Usage : "Ensures that all domains in your configuration are activated at their Domain Service Provider (This does not purchase the domain or otherwise interact with Registrars.)" ,
2017-09-13 22:00:41 +08:00
Action : func ( ctx * cli . Context ) error {
return exit ( CreateDomains ( args ) )
} ,
Flags : args . flags ( ) ,
}
} ( ) )
2018-01-10 01:53:16 +08:00
// CreateDomainsArgs args required for the create-domain subcommand.
2017-09-13 22:00:41 +08:00
type CreateDomainsArgs struct {
GetDNSConfigArgs
GetCredentialsArgs
}
func ( args * CreateDomainsArgs ) flags ( ) [ ] cli . Flag {
flags := args . GetDNSConfigArgs . flags ( )
flags = append ( flags , args . GetCredentialsArgs . flags ( ) ... )
return flags
}
2018-01-10 01:53:16 +08:00
// CreateDomains contains all data/flags needed to run create-domains, independently of CLI.
2017-09-13 22:00:41 +08:00
func CreateDomains ( args CreateDomainsArgs ) error {
cfg , err := GetDNSConfig ( args . GetDNSConfigArgs )
if err != nil {
return err
}
2018-02-02 00:45:53 +08:00
_ , err = InitializeProviders ( args . CredsFile , cfg , false )
2017-09-13 22:00:41 +08:00
if err != nil {
return err
}
for _ , domain := range cfg . Domains {
fmt . Println ( "*** " , domain . Name )
2018-02-02 00:45:53 +08:00
for _ , provider := range domain . DNSProviderInstances {
if creator , ok := provider . Driver . ( providers . DomainCreator ) ; ok {
fmt . Println ( " -" , provider . Name )
2017-09-13 22:00:41 +08:00
err := creator . EnsureDomainExists ( domain . Name )
if err != nil {
fmt . Printf ( "Error creating domain: %s\n" , err )
}
}
}
}
return nil
}