From 4f7f557a5cd14a98fd4f86f36204aa268f64c4e2 Mon Sep 17 00:00:00 2001 From: Khanh Pham Date: Sat, 12 Dec 2020 21:59:22 +0700 Subject: [PATCH] pdns: get exact zone instead of all zones (#1296) --- providers/dns/pdns/client.go | 27 +++++---------------------- 1 file changed, 5 insertions(+), 22 deletions(-) diff --git a/providers/dns/pdns/client.go b/providers/dns/pdns/client.go index 2f685640..1467da63 100644 --- a/providers/dns/pdns/client.go +++ b/providers/dns/pdns/client.go @@ -11,6 +11,7 @@ import ( "strings" "github.com/go-acme/lego/v4/challenge/dns01" + "github.com/miekg/dns" ) type Record struct { @@ -60,37 +61,19 @@ type apiVersion struct { } func (d *DNSProvider) getHostedZone(fqdn string) (*hostedZone, error) { - var zone hostedZone authZone, err := dns01.FindZoneByFqdn(fqdn) if err != nil { return nil, err } - u := "/servers/localhost/zones" - result, err := d.sendRequest(http.MethodGet, u, nil) - if err != nil { - return nil, err - } - - var zones []hostedZone - err = json.Unmarshal(result, &zones) - if err != nil { - return nil, err - } - - u = "" - for _, zone := range zones { - if dns01.UnFqdn(zone.Name) == dns01.UnFqdn(authZone) { - u = zone.URL - break - } - } - - result, err = d.sendRequest(http.MethodGet, u, nil) + p := path.Join("/servers/localhost/zones/", dns.Fqdn(authZone)) + + result, err := d.sendRequest(http.MethodGet, p, nil) if err != nil { return nil, err } + var zone hostedZone err = json.Unmarshal(result, &zone) if err != nil { return nil, err