2017-09-13 22:00:41 +08:00
package commands
import (
"fmt"
2023-05-21 01:21:45 +08:00
"github.com/StackExchange/dnscontrol/v4/pkg/credsfile"
"github.com/StackExchange/dnscontrol/v4/providers"
2022-08-15 08:46:56 +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" ,
2022-06-09 03:18:26 +08:00
Usage : "DEPRECATED: 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 ( ) ,
2022-06-09 03:18:26 +08:00
Before : func ( context * cli . Context ) error {
fmt . Println ( "DEPRECATED: This command is deprecated. The domain is automatically created at the Domain Service Provider during the push command." )
fmt . Println ( "DEPRECATED: To prevent disable auto-creating, use --no-populate with the push command." )
return nil
} ,
2017-09-13 22:00:41 +08:00
}
} ( ) )
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
}
2022-05-04 23:02:36 +08:00
providerConfigs , err := credsfile . LoadProviderConfigs ( args . CredsFile )
if err != nil {
return err
}
_ , err = InitializeProviders ( cfg , providerConfigs , 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 {
2023-02-07 20:22:49 +08:00
if creator , ok := provider . Driver . ( providers . ZoneCreator ) ; ok {
2018-02-02 00:45:53 +08:00
fmt . Println ( " -" , provider . Name )
2023-02-07 20:22:49 +08:00
err := creator . EnsureZoneExists ( domain . Name )
2017-09-13 22:00:41 +08:00
if err != nil {
fmt . Printf ( "Error creating domain: %s\n" , err )
}
}
}
}
return nil
}