diff --git a/providers/dns/pdns/pdns.go b/providers/dns/pdns/pdns.go index c2f780ba85..ec0ae2a70d 100644 --- a/providers/dns/pdns/pdns.go +++ b/providers/dns/pdns/pdns.go @@ -121,6 +121,8 @@ func (d *DNSProvider) Timeout() (timeout, interval time.Duration) { // Present creates a TXT record to fulfill the dns-01 challenge. func (d *DNSProvider) Present(domain, token, keyAuth string) error { + ctx := context.Background() + info := dns01.GetChallengeInfo(domain, keyAuth) authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN) @@ -128,11 +130,9 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { return fmt.Errorf("pdns: could not find zone for domain %q: %w", domain, err) } - ctx := context.Background() - zone, err := d.client.GetHostedZone(ctx, authZone) if err != nil { - return fmt.Errorf("pdns: %w", err) + return fmt.Errorf("pdns: get hosted zone for %s: %w", authZone, err) } name := info.EffectiveFQDN @@ -144,13 +144,12 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { // Look for existing records. existingRRSet := findTxtRecord(zone, info.EffectiveFQDN) - // merge the existing and new records var records []internal.Record if existingRRSet != nil { records = existingRRSet.Records } - rec := internal.Record{ + records = append(records, internal.Record{ Content: strconv.Quote(info.Value), Disabled: false, @@ -158,31 +157,36 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { Type: "TXT", Name: name, TTL: d.config.TTL, - } + }) rrSets := internal.RRSets{ - RRSets: []internal.RRSet{ - { - Name: name, - ChangeType: "REPLACE", - Type: "TXT", - Kind: "Master", - TTL: d.config.TTL, - Records: append(records, rec), - }, - }, + RRSets: []internal.RRSet{{ + Name: name, + ChangeType: "REPLACE", + Type: "TXT", + Kind: "Master", + TTL: d.config.TTL, + Records: records, + }}, } err = d.client.UpdateRecords(ctx, zone, rrSets) if err != nil { - return fmt.Errorf("pdns: %w", err) + return fmt.Errorf("pdns: update records: %w", err) } - return d.client.Notify(ctx, zone) + err = d.client.Notify(ctx, zone) + if err != nil { + return fmt.Errorf("pdns: notify: %w", err) + } + + return nil } // CleanUp removes the TXT record matching the specified parameters. func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { + ctx := context.Background() + info := dns01.GetChallengeInfo(domain, keyAuth) authZone, err := dns01.FindZoneByFqdn(info.EffectiveFQDN) @@ -190,15 +194,13 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { return fmt.Errorf("pdns: could not find zone for domain %q: %w", domain, err) } - ctx := context.Background() - zone, err := d.client.GetHostedZone(ctx, authZone) if err != nil { - return fmt.Errorf("pdns: %w", err) + return fmt.Errorf("pdns: get hosted zone for %s: %w", authZone, err) } + // Look for existing records. set := findTxtRecord(zone, info.EffectiveFQDN) - if set == nil { return fmt.Errorf("pdns: no existing record found for %s", info.EffectiveFQDN) } @@ -225,10 +227,15 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { err = d.client.UpdateRecords(ctx, zone, internal.RRSets{RRSets: []internal.RRSet{rrSet}}) if err != nil { - return fmt.Errorf("pdns: %w", err) + return fmt.Errorf("pdns: update records: %w", err) } - return d.client.Notify(ctx, zone) + err = d.client.Notify(ctx, zone) + if err != nil { + return fmt.Errorf("pdns: notify: %w", err) + } + + return nil } func findTxtRecord(zone *internal.HostedZone, fqdn string) *internal.RRSet {