From deb0ffc5d9310b08a7179c61062bec99de791745 Mon Sep 17 00:00:00 2001 From: Ludovic Fernandez Date: Sat, 27 Jun 2020 23:21:31 +0200 Subject: [PATCH] stackpath: fix subdomain support. (#1204) --- providers/dns/stackpath/stackpath.go | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/providers/dns/stackpath/stackpath.go b/providers/dns/stackpath/stackpath.go index 2f91bd59..8caa20e2 100644 --- a/providers/dns/stackpath/stackpath.go +++ b/providers/dns/stackpath/stackpath.go @@ -119,10 +119,9 @@ func (d *DNSProvider) Present(domain, token, keyAuth string) error { } fqdn, value := dns01.GetRecord(domain, keyAuth) - parts := strings.Split(fqdn, ".") record := Record{ - Name: parts[0], + Name: extractRecordName(fqdn, zone.Domain), Type: "TXT", TTL: d.config.TTL, Data: value, @@ -139,9 +138,9 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { } fqdn, _ := dns01.GetRecord(domain, keyAuth) - parts := strings.Split(fqdn, ".") + recordName := extractRecordName(fqdn, zone.Domain) - records, err := d.getZoneRecords(parts[0], zone) + records, err := d.getZoneRecords(recordName, zone) if err != nil { return err } @@ -161,3 +160,11 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error { func (d *DNSProvider) Timeout() (timeout, interval time.Duration) { return d.config.PropagationTimeout, d.config.PollingInterval } + +func extractRecordName(fqdn, zone string) string { + name := dns01.UnFqdn(fqdn) + if idx := strings.Index(name, "."+zone); idx != -1 { + return name[:idx] + } + return name +}