pdns: get exact zone instead of all zones (#1296)

This commit is contained in:
Khanh Pham 2020-12-12 21:59:22 +07:00 committed by GitHub
parent cabd839feb
commit 4f7f557a5c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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