Skip to content

Commit

Permalink
powerdns: several improvements (#1374)
Browse files Browse the repository at this point in the history
  • Loading branch information
pieterlexis authored Mar 17, 2021
1 parent ee0b4bd commit 83c626d
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 3 deletions.
1 change: 1 addition & 0 deletions cmd/zz_gen_cmd_dnshelp.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
1 change: 1 addition & 0 deletions docs/content/dns/zz_gen_pdns.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 7 additions & 3 deletions providers/dns/pdns/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
}

Expand All @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
}
3 changes: 3 additions & 0 deletions providers/dns/pdns/pdns.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
},
Expand Down
1 change: 1 addition & 0 deletions providers/dns/pdns/pdns.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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/"

0 comments on commit 83c626d

Please sign in to comment.