pdns: fix usage of notify only when zone kind is Master or Slave (#1781)

Co-authored-by: Fernandez Ludovic <ldez@users.noreply.github.com>
This commit is contained in:
Melchior NOGUES 2023-01-08 15:12:06 +01:00 committed by GitHub
parent 091e03f071
commit 7f8305e8d8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 27 deletions

View file

@ -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
}

View file

@ -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)
}