powerdns: several improvements (#1374)

This commit is contained in:
Pieter Lexis 2021-03-17 09:53:38 +01:00 committed by GitHub
parent ee0b4bd0b3
commit 83c626d9a1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 13 additions and 3 deletions

View file

@ -1480,6 +1480,7 @@ func displayDNSHelp(name string) error {
ew.writeln(` - "PDNS_HTTP_TIMEOUT": API request timeout`)
ew.writeln(` - "PDNS_POLLING_INTERVAL": Time between DNS propagation check`)
ew.writeln(` - "PDNS_PROPAGATION_TIMEOUT": Maximum waiting time for DNS propagation`)
ew.writeln(` - "PDNS_SERVER_NAME": Name of the server in the URL, 'localhost' by default`)
ew.writeln(` - "PDNS_TTL": The TTL of the TXT record used for the DNS challenge`)
ew.writeln()

View file

@ -47,6 +47,7 @@ More information [here](/lego/dns/#configuration-and-credentials).
| `PDNS_HTTP_TIMEOUT` | API request timeout |
| `PDNS_POLLING_INTERVAL` | Time between DNS propagation check |
| `PDNS_PROPAGATION_TIMEOUT` | Maximum waiting time for DNS propagation |
| `PDNS_SERVER_NAME` | Name of the server in the URL, 'localhost' by default |
| `PDNS_TTL` | The TTL of the TXT record used for the DNS challenge |
The environment variable names can be suffixed by `_FILE` to reference a file instead of a value.

View file

@ -39,7 +39,7 @@ type rrSet struct {
Type string `json:"type"`
Kind string `json:"kind"`
ChangeType string `json:"changetype"`
Records []Record `json:"records"`
Records []Record `json:"records,omitempty"`
TTL int `json:"ttl,omitempty"`
}
@ -66,7 +66,7 @@ func (d *DNSProvider) getHostedZone(fqdn string) (*hostedZone, error) {
return nil, err
}
p := path.Join("/servers/localhost/zones/", dns.Fqdn(authZone))
p := path.Join("/servers", d.config.ServerName, "/zones/", dns.Fqdn(authZone))
result, err := d.sendRequest(http.MethodGet, p, nil)
if err != nil {
@ -151,7 +151,7 @@ func (d *DNSProvider) sendRequest(method, uri string, body io.Reader) (json.RawM
defer resp.Body.Close()
if resp.StatusCode != http.StatusUnprocessableEntity && (resp.StatusCode < 200 || resp.StatusCode >= 300) {
return nil, fmt.Errorf("unexpected HTTP status code %d when fetching '%s'", resp.StatusCode, req.URL)
return nil, fmt.Errorf("unexpected HTTP status code %d when %sing '%s'", resp.StatusCode, req.Method, req.URL)
}
var msg json.RawMessage
@ -198,5 +198,9 @@ func (d *DNSProvider) makeRequest(method, uri string, body io.Reader) (*http.Req
req.Header.Set("X-API-Key", d.config.APIKey)
if method != http.MethodGet && method != http.MethodDelete {
req.Header.Set("Content-Type", "application/json")
}
return req, nil
}

View file

@ -26,12 +26,14 @@ const (
EnvPropagationTimeout = envNamespace + "PROPAGATION_TIMEOUT"
EnvPollingInterval = envNamespace + "POLLING_INTERVAL"
EnvHTTPTimeout = envNamespace + "HTTP_TIMEOUT"
EnvServerName = envNamespace + "SERVER_NAME"
)
// Config is used to configure the creation of the DNSProvider.
type Config struct {
APIKey string
Host *url.URL
ServerName string
PropagationTimeout time.Duration
PollingInterval time.Duration
TTL int
@ -44,6 +46,7 @@ func NewDefaultConfig() *Config {
TTL: env.GetOrDefaultInt(EnvTTL, dns01.DefaultTTL),
PropagationTimeout: env.GetOrDefaultSecond(EnvPropagationTimeout, 120*time.Second),
PollingInterval: env.GetOrDefaultSecond(EnvPollingInterval, 2*time.Second),
ServerName: env.GetOrDefaultString(EnvServerName, "localhost"),
HTTPClient: &http.Client{
Timeout: env.GetOrDefaultSecond(EnvHTTPTimeout, 30*time.Second),
},

View file

@ -29,6 +29,7 @@ PowerDNS Notes:
PDNS_PROPAGATION_TIMEOUT = "Maximum waiting time for DNS propagation"
PDNS_TTL = "The TTL of the TXT record used for the DNS challenge"
PDNS_HTTP_TIMEOUT = "API request timeout"
PDNS_SERVER_NAME = "Name of the server in the URL, 'localhost' by default"
[Links]
API = "https://doc.powerdns.com/md/httpapi/README/"