mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Rename DomainCreator to the more accurate ZoneCreator (#2038)
Co-authored-by: Yannik Sembritzki <yannik@sembritzki.org> Co-authored-by: Tom Limoncelli <tlimoncelli@stackoverflow.com>
This commit is contained in:
committed by
GitHub
parent
e8ae619f89
commit
5e06c249d6
@ -54,9 +54,9 @@ func CreateDomains(args CreateDomainsArgs) error {
|
||||
for _, domain := range cfg.Domains {
|
||||
fmt.Println("*** ", domain.Name)
|
||||
for _, provider := range domain.DNSProviderInstances {
|
||||
if creator, ok := provider.Driver.(providers.DomainCreator); ok {
|
||||
if creator, ok := provider.Driver.(providers.ZoneCreator); ok {
|
||||
fmt.Println(" -", provider.Name)
|
||||
err := creator.EnsureDomainExists(domain.Name)
|
||||
err := creator.EnsureZoneExists(domain.Name)
|
||||
if err != nil {
|
||||
fmt.Printf("Error creating domain: %s\n", err)
|
||||
}
|
||||
|
@ -151,12 +151,12 @@ DomainLoop:
|
||||
out.Warnf("DEBUG: zones: %v\n", zones)
|
||||
out.Warnf("DEBUG: Name: %v\n", domain.Name)
|
||||
|
||||
out.Warnf("Domain '%s' does not exist in the '%s' profile and will be added automatically.\n", domain.Name, provider.Name)
|
||||
out.Warnf("Zone '%s' does not exist in the '%s' profile and will be added automatically.\n", domain.Name, provider.Name)
|
||||
continue // continue with next provider, as we can not determine corrections without an existing zone
|
||||
}
|
||||
} else if creator, ok := provider.Driver.(providers.DomainCreator); ok && push {
|
||||
} else if creator, ok := provider.Driver.(providers.ZoneCreator); ok && push {
|
||||
// this is the actual push, ensure domain exists at DSP
|
||||
if err := creator.EnsureDomainExists(domain.Name); err != nil {
|
||||
if err := creator.EnsureZoneExists(domain.Name); err != nil {
|
||||
out.Warnf("Error creating domain: %s\n", err)
|
||||
continue // continue with next provider, as we couldn't create this one
|
||||
}
|
||||
|
@ -95,8 +95,8 @@ func newEdgeDNSDSP(config map[string]string, metadata json.RawMessage) (provider
|
||||
return api, nil
|
||||
}
|
||||
|
||||
// EnsureDomainExists configures a new zone if the zone does not already exist.
|
||||
func (a *edgeDNSProvider) EnsureDomainExists(domain string) error {
|
||||
// EnsureZoneExists creates a zone if it does not exist
|
||||
func (a *edgeDNSProvider) EnsureZoneExists(domain string) error {
|
||||
if zoneDoesExist(domain) {
|
||||
printer.Debugf("Zone %s already exists\n", domain)
|
||||
return nil
|
||||
|
@ -662,7 +662,7 @@ func (a *azurednsProvider) fetchRecordSets(zoneName string) ([]*adns.RecordSet,
|
||||
return records, nil
|
||||
}
|
||||
|
||||
func (a *azurednsProvider) EnsureDomainExists(domain string) error {
|
||||
func (a *azurednsProvider) EnsureZoneExists(domain string) error {
|
||||
if _, ok := a.zones[domain]; ok {
|
||||
return nil
|
||||
}
|
||||
|
@ -870,8 +870,8 @@ func getProxyMetadata(r *models.RecordConfig) map[string]string {
|
||||
}
|
||||
}
|
||||
|
||||
// EnsureDomainExists returns an error of domain does not exist.
|
||||
func (c *cloudflareProvider) EnsureDomainExists(domain string) error {
|
||||
// EnsureZoneExists creates a zone if it does not exist
|
||||
func (c *cloudflareProvider) EnsureZoneExists(domain string) error {
|
||||
if c.domainIndex == nil {
|
||||
if err := c.fetchDomainList(); err != nil {
|
||||
return err
|
||||
|
@ -206,12 +206,12 @@ func (c *cloudnsProvider) GetZoneRecords(domain string) (models.Records, error)
|
||||
return existingRecords, nil
|
||||
}
|
||||
|
||||
// EnsureDomainExists returns an error if domain doesn't exist.
|
||||
func (c *cloudnsProvider) EnsureDomainExists(domain string) error {
|
||||
// EnsureZoneExists creates a zone if it does not exist
|
||||
func (c *cloudnsProvider) EnsureZoneExists(domain string) error {
|
||||
if err := c.fetchDomainList(); err != nil {
|
||||
return err
|
||||
}
|
||||
// domain already exists
|
||||
// zone already exists
|
||||
if _, ok := c.domainIndex[domain]; ok {
|
||||
return nil
|
||||
}
|
||||
|
@ -112,9 +112,8 @@ func (c *desecProvider) GetZoneRecords(domain string) (models.Records, error) {
|
||||
return existingRecords, nil
|
||||
}
|
||||
|
||||
// EnsureDomainExists returns an error if domain doesn't exist.
|
||||
func (c *desecProvider) EnsureDomainExists(domain string) error {
|
||||
// domain already exists
|
||||
// EnsureZoneExists creates a zone if it does not exist
|
||||
func (c *desecProvider) EnsureZoneExists(domain string) error {
|
||||
c.mutex.Lock()
|
||||
defer c.mutex.Unlock()
|
||||
if _, ok := c.domainIndex[domain]; ok {
|
||||
|
@ -87,8 +87,8 @@ func init() {
|
||||
providers.RegisterDomainServiceProviderType("DIGITALOCEAN", fns, features)
|
||||
}
|
||||
|
||||
// EnsureDomainExists returns an error if domain doesn't exist.
|
||||
func (api *digitaloceanProvider) EnsureDomainExists(domain string) error {
|
||||
// EnsureZoneExists creates a zone if it does not exist
|
||||
func (api *digitaloceanProvider) EnsureZoneExists(domain string) error {
|
||||
retry:
|
||||
ctx := context.Background()
|
||||
_, resp, err := api.client.Domains.Get(ctx, domain)
|
||||
|
@ -177,9 +177,9 @@ func (api *dnsMadeEasyProvider) GetDomainCorrections(dc *models.DomainConfig) ([
|
||||
return corrections, nil
|
||||
}
|
||||
|
||||
// EnsureDomainExists returns an error if domain doesn't exist.
|
||||
func (api *dnsMadeEasyProvider) EnsureDomainExists(domainName string) error {
|
||||
exists, err := api.domainExists(domainName)
|
||||
// EnsureZoneExists creates a zone if it does not exist
|
||||
func (api *dnsMadeEasyProvider) EnsureZoneExists(domain string) error {
|
||||
exists, err := api.domainExists(domain)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -189,7 +189,7 @@ func (api *dnsMadeEasyProvider) EnsureDomainExists(domainName string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
return api.createDomain(domainName)
|
||||
return api.createDomain(domain)
|
||||
}
|
||||
|
||||
// GetNameservers returns the nameservers for a domain.
|
||||
|
@ -74,9 +74,9 @@ func init() {
|
||||
providers.RegisterDomainServiceProviderType("EXOSCALE", fns, features)
|
||||
}
|
||||
|
||||
// EnsureDomainExists returns an error if domain doesn't exist.
|
||||
func (c *exoscaleProvider) EnsureDomainExists(domainName string) error {
|
||||
_, err := c.findDomainByName(domainName)
|
||||
// EnsureZoneExists creates a zone if it does not exist
|
||||
func (c *exoscaleProvider) EnsureZoneExists(domain string) error {
|
||||
_, err := c.findDomainByName(domain)
|
||||
|
||||
return err
|
||||
}
|
||||
|
@ -327,7 +327,7 @@ func (g *gcloudProvider) getRecords(domain string) ([]*gdns.ResourceRecordSet, s
|
||||
return sets, zone.Name, nil
|
||||
}
|
||||
|
||||
func (g *gcloudProvider) EnsureDomainExists(domain string) error {
|
||||
func (g *gcloudProvider) EnsureZoneExists(domain string) error {
|
||||
z, err := g.getZone(domain)
|
||||
if err != nil {
|
||||
if _, ok := err.(errNoExist); !ok {
|
||||
|
@ -114,8 +114,8 @@ func (c *gcoreProvider) GetZoneRecords(domain string) (models.Records, error) {
|
||||
return existingRecords, nil
|
||||
}
|
||||
|
||||
// EnsureDomainExists returns an error if domain doesn't exist.
|
||||
func (c *gcoreProvider) EnsureDomainExists(domain string) error {
|
||||
// EnsureZoneExists creates a zone if it does not exist
|
||||
func (c *gcoreProvider) EnsureZoneExists(domain string) error {
|
||||
zones, err := c.provider.Zones(c.ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -156,8 +156,8 @@ func (c *hednsProvider) ListZones() ([]string, error) {
|
||||
return domains, err
|
||||
}
|
||||
|
||||
// EnsureDomainExists creates the domain if it does not exist.
|
||||
func (c *hednsProvider) EnsureDomainExists(domain string) error {
|
||||
// EnsureZoneExists creates a zone if it does not exist
|
||||
func (c *hednsProvider) EnsureZoneExists(domain string) error {
|
||||
domains, err := c.ListZones()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -61,8 +61,8 @@ func New(settings map[string]string, _ json.RawMessage) (providers.DNSServicePro
|
||||
return api, nil
|
||||
}
|
||||
|
||||
// EnsureDomainExists creates the domain if it does not exist.
|
||||
func (api *hetznerProvider) EnsureDomainExists(domain string) error {
|
||||
// EnsureZoneExists creates a zone if it does not exist
|
||||
func (api *hetznerProvider) EnsureZoneExists(domain string) error {
|
||||
domains, err := api.ListZones()
|
||||
if err != nil {
|
||||
return err
|
||||
|
@ -2,10 +2,10 @@ package hexonet
|
||||
|
||||
import "fmt"
|
||||
|
||||
// EnsureDomainExists returns an error
|
||||
// EnsureZoneExists returns an error
|
||||
// * if access to dnszone is not allowed (not authorized) or
|
||||
// * if it doesn't exist and creating it fails
|
||||
func (n *HXClient) EnsureDomainExists(domain string) error {
|
||||
func (n *HXClient) EnsureZoneExists(domain string) error {
|
||||
r := n.client.Request(map[string]interface{}{
|
||||
"COMMAND": "StatusDNSZone",
|
||||
"DNSZONE": domain + ".",
|
||||
@ -17,7 +17,7 @@ func (n *HXClient) EnsureDomainExists(domain string) error {
|
||||
"DNSZONE": domain + ".",
|
||||
})
|
||||
if !r.IsSuccess() {
|
||||
return n.GetHXApiError("Failed to create not existing zone for domain", domain, r)
|
||||
return n.GetHXApiError("Failed to create not existing zone ", domain, r)
|
||||
}
|
||||
} else if code == 531 {
|
||||
return n.GetHXApiError("Not authorized to manage dnszone", domain, r)
|
||||
|
@ -351,7 +351,7 @@ func (hp *hostingdeProvider) GetRegistrarCorrections(dc *models.DomainConfig) ([
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
func (hp *hostingdeProvider) EnsureDomainExists(domain string) error {
|
||||
func (hp *hostingdeProvider) EnsureZoneExists(domain string) error {
|
||||
_, err := hp.getZoneConfig(domain)
|
||||
if err == errZoneNotFound {
|
||||
if err := hp.createZone(domain); err != nil {
|
||||
|
@ -399,8 +399,8 @@ func (api *inwxAPI) fetchNameserverDomains() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// EnsureDomainExists returns an error if domain does not exist.
|
||||
func (api *inwxAPI) EnsureDomainExists(domain string) error {
|
||||
// EnsureZoneExists creates a zone if it does not exist
|
||||
func (api *inwxAPI) EnsureZoneExists(domain string) error {
|
||||
if api.domainIndex == nil { // only pull the data once.
|
||||
if err := api.fetchNameserverDomains(); err != nil {
|
||||
return err
|
||||
@ -408,10 +408,10 @@ func (api *inwxAPI) EnsureDomainExists(domain string) error {
|
||||
}
|
||||
|
||||
if _, ok := api.domainIndex[domain]; ok {
|
||||
return nil // domain exists.
|
||||
return nil // zone exists.
|
||||
}
|
||||
|
||||
// creating the domain.
|
||||
// creating the zone.
|
||||
request := &goinwx.NameserverCreateRequest{
|
||||
Domain: domain,
|
||||
Type: "MASTER",
|
||||
|
@ -50,7 +50,7 @@ func newProvider(creds map[string]string, meta json.RawMessage) (providers.DNSSe
|
||||
return &nsone{rest.NewClient(http.DefaultClient, rest.SetAPIKey(creds["api_token"]))}, nil
|
||||
}
|
||||
|
||||
func (n *nsone) EnsureDomainExists(domain string) error {
|
||||
func (n *nsone) EnsureZoneExists(domain string) error {
|
||||
// This enables the create-domains subcommand
|
||||
|
||||
zone := dns.NewZone(domain)
|
||||
|
@ -84,8 +84,8 @@ func (o *oracleProvider) ListZones() ([]string, error) {
|
||||
return zones, nil
|
||||
}
|
||||
|
||||
// EnsureDomainExists creates the domain if it does not exist.
|
||||
func (o *oracleProvider) EnsureDomainExists(domain string) error {
|
||||
// EnsureZoneExists creates a zone if it does not exist
|
||||
func (o *oracleProvider) EnsureZoneExists(domain string) error {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Minute)
|
||||
defer cancel()
|
||||
|
||||
|
@ -131,15 +131,15 @@ func (dsp *powerdnsProvider) GetDomainCorrections(dc *models.DomainConfig) ([]*m
|
||||
return corrections, nil
|
||||
}
|
||||
|
||||
// EnsureDomainExists adds a domain to the DNS service if it does not exist
|
||||
func (dsp *powerdnsProvider) EnsureDomainExists(domain string) error {
|
||||
// EnsureZoneExists creates a zone if it does not exist
|
||||
func (dsp *powerdnsProvider) EnsureZoneExists(domain string) error {
|
||||
if _, err := dsp.client.Zones().GetZone(context.Background(), dsp.ServerName, domain+"."); err != nil {
|
||||
if e, ok := err.(pdnshttp.ErrUnexpectedStatus); ok {
|
||||
if e.StatusCode != http.StatusNotFound {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else { // domain seems to be there
|
||||
} else { // zone seems to exist
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -18,10 +18,10 @@ type DNSServiceProvider interface {
|
||||
models.DNSProvider
|
||||
}
|
||||
|
||||
// DomainCreator should be implemented by providers that have the ability to add domains to an account. the create-domains command
|
||||
// can be run to ensure all domains are present before running preview/push. Implement this only if the provider supoprts the `dnscontrol create-domain` command.
|
||||
type DomainCreator interface {
|
||||
EnsureDomainExists(domain string) error
|
||||
// ZoneCreator should be implemented by providers that have the ability to create zones
|
||||
// (used for automatically creating zones if they don't exist)
|
||||
type ZoneCreator interface {
|
||||
EnsureZoneExists(domain string) error
|
||||
}
|
||||
|
||||
// ZoneLister should be implemented by providers that have the
|
||||
|
@ -818,7 +818,7 @@ func unescape(s *string) string {
|
||||
return name
|
||||
}
|
||||
|
||||
func (r *route53Provider) EnsureDomainExists(domain string) error {
|
||||
func (r *route53Provider) EnsureZoneExists(domain string) error {
|
||||
if err := r.getZones(); err != nil {
|
||||
return err
|
||||
}
|
||||
|
@ -223,8 +223,8 @@ func (api *vultrProvider) GetNameservers(domain string) ([]*models.Nameserver, e
|
||||
return models.ToNameservers(defaultNS)
|
||||
}
|
||||
|
||||
// EnsureDomainExists adds a domain to the Vutr DNS service if it does not exist
|
||||
func (api *vultrProvider) EnsureDomainExists(domain string) error {
|
||||
// EnsureZoneExists creates a zone if it does not exist
|
||||
func (api *vultrProvider) EnsureZoneExists(domain string) error {
|
||||
if ok, err := api.isDomainInAccount(domain); err != nil {
|
||||
return err
|
||||
} else if ok {
|
||||
|
Reference in New Issue
Block a user