From 7cfa075581991478504d4716ab9eda1e7c4c0653 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=BCrgen=20Brunink?= <1129998+jbrunink@users.noreply.github.com> Date: Tue, 11 Oct 2022 14:40:00 +0200 Subject: [PATCH] hurricane: fix CNAME support (#1734) Co-authored-by: Fernandez Ludovic --- providers/dns/hurricane/hurricane.go | 10 ++++++---- providers/dns/hurricane/internal/client.go | 4 ++-- providers/dns/hurricane/internal/client_test.go | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/providers/dns/hurricane/hurricane.go b/providers/dns/hurricane/hurricane.go index 3427e600..34d38d63 100644 --- a/providers/dns/hurricane/hurricane.go +++ b/providers/dns/hurricane/hurricane.go @@ -86,9 +86,9 @@ func NewDNSProviderConfig(config *Config) (*DNSProvider, error) { // Present updates a TXT record to fulfill the dns-01 challenge. func (d *DNSProvider) Present(domain, _, keyAuth string) error { - _, txtRecord := dns01.GetRecord(domain, keyAuth) + fqdn, txtRecord := dns01.GetRecord(domain, keyAuth) - err := d.client.UpdateTxtRecord(context.Background(), domain, txtRecord) + err := d.client.UpdateTxtRecord(context.Background(), dns01.UnFqdn(fqdn), txtRecord) if err != nil { return fmt.Errorf("hurricane: %w", err) } @@ -97,8 +97,10 @@ func (d *DNSProvider) Present(domain, _, keyAuth string) error { } // CleanUp updates the TXT record matching the specified parameters. -func (d *DNSProvider) CleanUp(domain, _, _ string) error { - err := d.client.UpdateTxtRecord(context.Background(), domain, ".") +func (d *DNSProvider) CleanUp(domain, _, keyAuth string) error { + fqdn, _ := dns01.GetRecord(domain, keyAuth) + + err := d.client.UpdateTxtRecord(context.Background(), dns01.UnFqdn(fqdn), ".") if err != nil { return fmt.Errorf("hurricane: %w", err) } diff --git a/providers/dns/hurricane/internal/client.go b/providers/dns/hurricane/internal/client.go index 81b863cc..e5848112 100644 --- a/providers/dns/hurricane/internal/client.go +++ b/providers/dns/hurricane/internal/client.go @@ -51,8 +51,8 @@ func NewClient(credentials map[string]string) *Client { } // UpdateTxtRecord updates a TXT record. -func (c *Client) UpdateTxtRecord(ctx context.Context, domain string, txt string) error { - hostname := fmt.Sprintf("_acme-challenge.%s", domain) +func (c *Client) UpdateTxtRecord(ctx context.Context, hostname string, txt string) error { + domain := strings.TrimPrefix(hostname, "_acme-challenge.") c.credMu.Lock() token, ok := c.credentials[domain] diff --git a/providers/dns/hurricane/internal/client_test.go b/providers/dns/hurricane/internal/client_test.go index b4869d69..f68d9b73 100644 --- a/providers/dns/hurricane/internal/client_test.go +++ b/providers/dns/hurricane/internal/client_test.go @@ -75,7 +75,7 @@ func TestClient_UpdateTxtRecord(t *testing.T) { client := NewClient(map[string]string{"example.com": "secret"}) client.baseURL = server.URL - err := client.UpdateTxtRecord(context.Background(), "example.com", "foo") + err := client.UpdateTxtRecord(context.Background(), "_acme-challenge.example.com", "foo") test.expected(t, err) }) }