refactor: extract resolveCNAME

This commit is contained in:
Fernandez Ludovic 2026-02-26 08:46:03 +01:00
commit d8f2938799
2 changed files with 15 additions and 7 deletions

View file

@ -2,6 +2,7 @@ package dns01
import (
"context"
"fmt"
"log/slog"
"github.com/go-acme/lego/v5/challenge/internal"
@ -9,6 +10,19 @@ import (
"github.com/miekg/dns"
)
func (c *Client) resolveCNAME(ctx context.Context, fqdn string) (string, error) {
r, err := c.sendQuery(ctx, fqdn, dns.TypeTXT, true)
if err != nil {
return "", fmt.Errorf("initial recursive nameserver: %w", err)
}
if r.Rcode == dns.RcodeSuccess {
fqdn = updateDomainWithCName(r, fqdn)
}
return fqdn, nil
}
func (c *Client) lookupCNAME(ctx context.Context, fqdn string) string {
// recursion counter so it doesn't spin out of control
for range 50 {

View file

@ -3,8 +3,6 @@ package dns01
import (
"context"
"fmt"
"github.com/miekg/dns"
)
// PreCheckFunc checks DNS propagation before notifying ACME that the DNS challenge is ready.
@ -53,15 +51,11 @@ func (p preCheck) checkDNSPropagation(ctx context.Context, fqdn, value string) (
client := DefaultClient()
// Initial attempt to resolve at the recursive NS (require getting CNAME)
r, err := client.sendQuery(ctx, fqdn, dns.TypeTXT, true)
fqdn, err := client.resolveCNAME(ctx, fqdn)
if err != nil {
return false, fmt.Errorf("initial recursive nameserver: %w", err)
}
if r.Rcode == dns.RcodeSuccess {
fqdn = updateDomainWithCName(r, fqdn)
}
if p.requireRecursiveNssPropagation {
_, err = client.checkRecursiveNameserversPropagation(ctx, fqdn, value)
if err != nil {