From 52f09c1c2b0db948b2998710a0e366c884ddc17e Mon Sep 17 00:00:00 2001 From: Fernandez Ludovic Date: Fri, 16 Jan 2026 19:31:25 +0100 Subject: [PATCH] refactor: move Manual DNS provider implementation --- providers/dns/manual/manual.go | 60 ++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/providers/dns/manual/manual.go b/providers/dns/manual/manual.go index 34291c780..0806a7e17 100644 --- a/providers/dns/manual/manual.go +++ b/providers/dns/manual/manual.go @@ -1,11 +1,67 @@ package manual -import "github.com/go-acme/lego/v5/challenge/dns01" +import ( + "bufio" + "context" + "fmt" + "os" + "time" + + "github.com/go-acme/lego/v5/challenge/dnsnew" +) + +const ( + dnsTemplate = `%s %d IN TXT %q` +) // DNSProvider is an implementation of the ChallengeProvider interface. -type DNSProvider = dns01.DNSProviderManual +type DNSProvider struct{} // NewDNSProvider returns a DNSProvider instance. func NewDNSProvider() (*DNSProvider, error) { return &DNSProvider{}, nil } + +// Present prints instructions for manually creating the TXT record. +func (*DNSProvider) Present(domain, token, keyAuth string) error { + ctx := context.Background() + info := dnsnew.GetChallengeInfo(ctx, domain, keyAuth) + + authZone, err := dnsnew.DefaultClient().FindZoneByFqdn(ctx, info.EffectiveFQDN) + if err != nil { + return fmt.Errorf("manual: could not find zone: %w", err) + } + + fmt.Printf("lego: Please create the following TXT record in your %s zone:\n", authZone) + fmt.Printf(dnsTemplate+"\n", info.EffectiveFQDN, dnsnew.DefaultTTL, info.Value) + fmt.Printf("lego: Press 'Enter' when you are done\n") + + _, err = bufio.NewReader(os.Stdin).ReadBytes('\n') + if err != nil { + return fmt.Errorf("manual: %w", err) + } + + return nil +} + +// CleanUp prints instructions for manually removing the TXT record. +func (*DNSProvider) CleanUp(domain, token, keyAuth string) error { + ctx := context.Background() + info := dnsnew.GetChallengeInfo(ctx, domain, keyAuth) + + authZone, err := dnsnew.DefaultClient().FindZoneByFqdn(ctx, info.EffectiveFQDN) + if err != nil { + return fmt.Errorf("manual: could not find zone: %w", err) + } + + fmt.Printf("lego: You can now remove this TXT record from your %s zone:\n", authZone) + fmt.Printf(dnsTemplate+"\n", info.EffectiveFQDN, dnsnew.DefaultTTL, "...") + + return nil +} + +// Sequential All DNS challenges for this provider will be resolved sequentially. +// Returns the interval between each iteration. +func (d *DNSProvider) Sequential() time.Duration { + return dnsnew.DefaultPropagationTimeout +}