NS1: use the authoritative zone and not the domain name (#463)

This commit is contained in:
Steve Coursen 2018-07-14 06:31:57 -04:00 committed by Ludovic Fernandez
parent 255296ec82
commit 771679fe3d

View file

@ -5,6 +5,7 @@ package ns1
import ( import (
"fmt" "fmt"
"net/http" "net/http"
"strings"
"time" "time"
"github.com/xenolf/lego/acme" "github.com/xenolf/lego/acme"
@ -75,7 +76,12 @@ func (d *DNSProvider) CleanUp(domain, token, keyAuth string) error {
} }
func (d *DNSProvider) getHostedZone(domain string) (*dns.Zone, error) { func (d *DNSProvider) getHostedZone(domain string) (*dns.Zone, error) {
zone, _, err := d.client.Zones.Get(domain) authZone, err := getAuthZone(domain)
if err != nil {
return nil, err
}
zone, _, err := d.client.Zones.Get(authZone)
if err != nil { if err != nil {
return nil, err return nil, err
} }
@ -83,6 +89,19 @@ func (d *DNSProvider) getHostedZone(domain string) (*dns.Zone, error) {
return zone, nil return zone, nil
} }
func getAuthZone(fqdn string) (string, error) {
authZone, err := acme.FindZoneByFqdn(fqdn, acme.RecursiveNameservers)
if err != nil {
return "", err
}
if strings.HasSuffix(authZone, ".") {
authZone = authZone[:len(authZone)-len(".")]
}
return authZone, err
}
func (d *DNSProvider) newTxtRecord(zone *dns.Zone, fqdn, value string, ttl int) *dns.Record { func (d *DNSProvider) newTxtRecord(zone *dns.Zone, fqdn, value string, ttl int) *dns.Record {
name := acme.UnFqdn(fqdn) name := acme.UnFqdn(fqdn)