Skip to content

pdns: improve error messages #2526

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 9, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 31 additions & 24 deletions providers/dns/pdns/pdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,18 +121,18 @@ 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)
if err != nil {
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
Expand All @@ -144,61 +144,63 @@ 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,

// pre-v1 API
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)
if err != nil {
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)
}
Expand All @@ -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 {
Expand Down