From 7f8305e8d81dbe9a7d5e7e2081ca5b4e363372ec Mon Sep 17 00:00:00 2001 From: Melchior NOGUES Date: Sun, 8 Jan 2023 15:12:06 +0100 Subject: [PATCH] pdns: fix usage of notify only when zone kind is Master or Slave (#1781) Co-authored-by: Fernandez Ludovic --- providers/dns/pdns/client.go | 17 ++++++++++------- providers/dns/pdns/pdns.go | 22 ++-------------------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/providers/dns/pdns/client.go b/providers/dns/pdns/client.go index 154dbc26..2c98ca78 100644 --- a/providers/dns/pdns/client.go +++ b/providers/dns/pdns/client.go @@ -28,6 +28,7 @@ type hostedZone struct { ID string `json:"id"` Name string `json:"name"` URL string `json:"url"` + Kind string `json:"kind"` RRSets []rrSet `json:"rrsets"` // pre-v1 API @@ -137,14 +138,16 @@ func (d *DNSProvider) getAPIVersion() (int, error) { return latestVersion, err } -func (d *DNSProvider) notify(zoneURL string) error { - if d.apiVersion >= 1 { - p := path.Join(zoneURL, "/notify") - _, err := d.sendRequest(http.MethodPut, p, nil) - if err != nil { - return err - } +func (d *DNSProvider) notify(zone *hostedZone) error { + if d.apiVersion < 1 || zone.Kind != "Master" && zone.Kind != "Slave" { + return nil } + + _, err := d.sendRequest(http.MethodPut, path.Join(zone.URL, "/notify"), nil) + if err != nil { + return err + } + return nil } diff --git a/providers/dns/pdns/pdns.go b/providers/dns/pdns/pdns.go index e73b4072..fa57c86b 100644 --- a/providers/dns/pdns/pdns.go +++ b/providers/dns/pdns/pdns.go @@ -173,16 +173,7 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { return fmt.Errorf("pdns: %w", err) } - if d.apiVersion < 1 { - return nil - } - - err = d.notify(zone.URL) - if err != nil { - return fmt.Errorf("pdns: %w", err) - } - - return nil + return d.notify(zone) } // CleanUp removes the TXT record matching the specified parameters. @@ -221,14 +212,5 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { return fmt.Errorf("pdns: %w", err) } - if d.apiVersion < 1 { - return nil - } - - err = d.notify(zone.URL) - if err != nil { - return fmt.Errorf("pdns: %w", err) - } - - return nil + return d.notify(zone) }