Skip to content

Commit

Permalink
pdns: notify secondary servers after updates (#1679)
Browse files Browse the repository at this point in the history
Co-authored-by: Fernandez Ludovic <[email protected]>
  • Loading branch information
esclear and ldez authored Sep 17, 2022
1 parent 60bd1c2 commit 0bcada7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
11 changes: 11 additions & 0 deletions providers/dns/pdns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,17 @@ 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
}
}
return nil
}

func (d *DNSProvider) sendRequest(method, uri string, body io.Reader) (json.RawMessage, error) {
req, err := d.makeRequest(method, uri, body)
if err != nil {
Expand Down
20 changes: 20 additions & 0 deletions providers/dns/pdns/pdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,16 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error {
if err != nil {
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
}

Expand Down Expand Up @@ -210,5 +220,15 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
if err != nil {
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
}

0 comments on commit 0bcada7

Please sign in to comment.