Skip to content

Commit

Permalink
pdns: fix usage of notify only when zone kind is Master or Slave (#1781)
Browse files Browse the repository at this point in the history
Co-authored-by: Fernandez Ludovic <[email protected]>
  • Loading branch information
melck and ldez authored Jan 8, 2023
1 parent 091e03f commit 7f8305e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
17 changes: 10 additions & 7 deletions providers/dns/pdns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand Down
22 changes: 2 additions & 20 deletions providers/dns/pdns/pdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
}

0 comments on commit 7f8305e

Please sign in to comment.