Skip to content

Commit 8f13dd1

Browse files
authored
POWERDNS: Split horizon feature now enabled by flag (StackExchange#3829)
1 parent bfc2b26 commit 8f13dd1

File tree

5 files changed

+17
-15
lines changed

5 files changed

+17
-15
lines changed

documentation/provider/powerdns.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ Following metadata are available:
4545
<br> Can be one of `DEFAULT`, `INCREASE`, `EPOCH`, `SOA-EDIT` or `SOA-EDIT-INCREASE`, default format is YYYYMMDD01.
4646
<br>Please see [PowerDNS SOA-EDIT-DNSUPDATE documentation](https://doc.powerdns.com/authoritative/dnsupdate.html#soa-edit-dnsupdate-settings) for explanation of the kinds.
4747
<br>**Note that these tokens are case-sensitive!**
48+
- `use_views` enables mapping dnscontrol tags to PowerDNS views.
49+
<br>Set to `true` to enable, defaults to `false`.
4850

4951
## Usage
5052
An example configuration:
@@ -64,7 +66,7 @@ D("example.com", REG_NONE, DnsProvider(DSP_POWERDNS),
6466
See the [PowerDNS documentation](https://doc.powerdns.com/authoritative/http-api/index.html) how the API can be enabled.
6567

6668
## Tags and Variants
67-
If you use a dnscontrol *tag* (like `example.com!internal`) it will be mapped to a powerdns *variant* (like `example.com..internal`).
69+
If you use a dnscontrol *tag* (like `example.com!internal`) it will be mapped to a powerdns *variant* (like `example.com..internal`) when `use_views` is enabled in the provider metadata.
6870

6971
See [PowerDNS documentation on Views](https://doc.powerdns.com/authoritative/views.html) for details on how to setup networks and views for these variants.
7072

providers/powerdns/diff.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (dsp *powerdnsProvider) getDiff2DomainCorrections(dc *models.DomainConfig,
5858
}
5959
}
6060

61-
domainVariant := GetVariantName(dc.Name, dc.Metadata[models.DomainTag])
61+
domainVariant := dsp.zoneName(dc.Name, dc.Metadata[models.DomainTag])
6262

6363
// only append a Correction if there are any, otherwise causes an error when sending an empty rrset
6464
if len(rrDeleteSets) > 0 {
@@ -100,14 +100,3 @@ func buildRecordList(change diff2.Change) (records []zones.Record) {
100100
func canonical(fqdn string) string {
101101
return fqdn + "."
102102
}
103-
104-
// Build the variant name for powerdns. this is the domain + "." + the tag
105-
// so dnscontrol "example.com!internal" becomes powerdns "example.com..internal"
106-
// See https://doc.powerdns.com/authoritative/views.html
107-
func GetVariantName(domain string, tag string) string {
108-
if tag != "" {
109-
return canonical(domain) + "." + tag
110-
} else {
111-
return canonical(domain)
112-
}
113-
}

providers/powerdns/dns.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (dsp *powerdnsProvider) GetNameservers(string) ([]*models.Nameserver, error
2121
// GetZoneRecords gets the records of a zone and returns them in RecordConfig format.
2222
func (dsp *powerdnsProvider) GetZoneRecords(domain string, meta map[string]string) (models.Records, error) {
2323
curRecords := models.Records{}
24-
domainVariant := GetVariantName(domain, meta[models.DomainTag])
24+
domainVariant := dsp.zoneName(domain, meta[models.DomainTag])
2525
zone, err := dsp.client.Zones().GetZone(context.Background(), dsp.ServerName, domainVariant)
2626
if err != nil {
2727
if _, ok := err.(pdnshttp.ErrNotFound); ok {

providers/powerdns/dnssec.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
// getDNSSECCorrections returns corrections that update a domain's DNSSEC state.
1212
func (dsp *powerdnsProvider) getDNSSECCorrections(dc *models.DomainConfig) ([]*models.Correction, error) {
13-
domainVariant := GetVariantName(dc.Name, dc.Metadata[models.DomainTag])
13+
domainVariant := dsp.zoneName(dc.Name, dc.Metadata[models.DomainTag])
1414
zoneCryptokeys, getErr := dsp.client.Cryptokeys().ListCryptokeys(context.Background(), dsp.ServerName, domainVariant)
1515
if getErr != nil {
1616
if _, ok := getErr.(pdnshttp.ErrNotFound); ok {

providers/powerdns/powerdnsProvider.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,21 @@ type powerdnsProvider struct {
5959
DNSSecOnCreate bool `json:"dnssec_on_create"`
6060
ZoneKind zones.ZoneKind `json:"zone_kind"`
6161
SOAEditAPI zones.ZoneSOAEditAPI `json:"soa_edit_api,omitempty"`
62+
UseViews bool `json:"use_views,omitempty"`
6263

6364
nameservers []*models.Nameserver
6465
}
6566

67+
// Build the variant name for powerdns. this is the domain + "." + the tag
68+
// so dnscontrol "example.com!internal" becomes powerdns "example.com..internal"
69+
// See https://doc.powerdns.com/authoritative/views.html
70+
func (dsp *powerdnsProvider) zoneName(domain string, tag string) string {
71+
if dsp.UseViews && tag == "" {
72+
return canonical(domain) + "." + tag
73+
}
74+
return canonical(domain)
75+
}
76+
6677
// newDSP initializes a PowerDNS DNSServiceProvider.
6778
func newDSP(m map[string]string, metadata json.RawMessage) (providers.DNSServiceProvider, error) {
6879
dsp := &powerdnsProvider{}

0 commit comments

Comments
 (0)