mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Fixing PowerDNS domain creation (#786)
This commit is contained in:
committed by
GitHub
parent
42f7568074
commit
4211cf1dc0
@ -11,6 +11,8 @@ import (
|
||||
"github.com/miekg/dns/dnsutil"
|
||||
"github.com/mittwald/go-powerdns"
|
||||
"github.com/mittwald/go-powerdns/apis/zones"
|
||||
"github.com/mittwald/go-powerdns/pdnshttp"
|
||||
"net/http"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@ -196,12 +198,18 @@ func (api *PowerDNS) GetDomainCorrections(dc *models.DomainConfig) ([]*models.Co
|
||||
|
||||
// EnsureDomainExists adds a domain to the DNS service if it does not exist
|
||||
func (api *PowerDNS) EnsureDomainExists(domain string) error {
|
||||
if zone, _ := api.client.Zones().GetZone(context.Background(), api.ServerName, domain); zone.ID != "" {
|
||||
if _, err := api.client.Zones().GetZone(context.Background(), api.ServerName, domain+"."); err != nil {
|
||||
if e, ok := err.(pdnshttp.ErrUnexpectedStatus); ok {
|
||||
if e.StatusCode != http.StatusNotFound {
|
||||
return err
|
||||
}
|
||||
}
|
||||
} else { // domain seems to be there
|
||||
return nil
|
||||
}
|
||||
|
||||
_, err := api.client.Zones().CreateZone(context.Background(), api.ServerName, zones.Zone{
|
||||
Name: domain,
|
||||
Name: domain + ".",
|
||||
Type: zones.ZoneTypeZone,
|
||||
DNSSec: api.DNSSecOnCreate,
|
||||
Nameservers: api.DefaultNS,
|
||||
|
Reference in New Issue
Block a user