diff --git a/providers/dns/rfc2136/rfc2136.go b/providers/dns/rfc2136/rfc2136.go index 1f1af790..dde42ddf 100644 --- a/providers/dns/rfc2136/rfc2136.go +++ b/providers/dns/rfc2136/rfc2136.go @@ -20,29 +20,32 @@ type DNSProvider struct { tsigAlgorithm string tsigKey string tsigSecret string + timeout time.Duration } // NewDNSProvider returns a DNSProvider instance configured for rfc2136 -// dynamic update. Credentials must be passed in environment variables: +// dynamic update. Configured with environment variables: // RFC2136_NAMESERVER: Network address in the form "host" or "host:port". // RFC2136_TSIG_ALGORITHM: Defaults to hmac-md5.sig-alg.reg.int. (HMAC-MD5). // See https://github.com/miekg/dns/blob/master/tsig.go for supported values. // RFC2136_TSIG_KEY: Name of the secret key as defined in DNS server configuration. // RFC2136_TSIG_SECRET: Secret key payload. +// RFC2136_TIMEOUT: DNS propagation timeout in time.ParseDuration format. (60s) // To disable TSIG authentication, leave the RFC2136_TSIG* variables unset. func NewDNSProvider() (*DNSProvider, error) { nameserver := os.Getenv("RFC2136_NAMESERVER") tsigAlgorithm := os.Getenv("RFC2136_TSIG_ALGORITHM") tsigKey := os.Getenv("RFC2136_TSIG_KEY") tsigSecret := os.Getenv("RFC2136_TSIG_SECRET") - return NewDNSProviderCredentials(nameserver, tsigAlgorithm, tsigKey, tsigSecret) + timeout := os.Getenv("RFC2136_TIMEOUT") + return NewDNSProviderCredentials(nameserver, tsigAlgorithm, tsigKey, tsigSecret, timeout) } // NewDNSProviderCredentials uses the supplied credentials to return a // DNSProvider instance configured for rfc2136 dynamic update. To disable TSIG // authentication, leave the TSIG parameters as empty strings. // nameserver must be a network address in the form "host" or "host:port". -func NewDNSProviderCredentials(nameserver, tsigAlgorithm, tsigKey, tsigSecret string) (*DNSProvider, error) { +func NewDNSProviderCredentials(nameserver, tsigAlgorithm, tsigKey, tsigSecret, timeout string) (*DNSProvider, error) { if nameserver == "" { return nil, fmt.Errorf("RFC2136 nameserver missing") } @@ -67,9 +70,27 @@ func NewDNSProviderCredentials(nameserver, tsigAlgorithm, tsigKey, tsigSecret st d.tsigSecret = tsigSecret } + if timeout == "" { + d.timeout = 60 * time.Second + } else { + t, err := time.ParseDuration(timeout) + if err != nil { + return nil, err + } else if t < 0 { + return nil, fmt.Errorf("Invalid/negative RFC2136_TIMEOUT: %v", timeout) + } else { + d.timeout = t + } + } + return d, nil } +// Returns the timeout configured with RFC2136_TIMEOUT, or 60s. +func (d *DNSProvider) Timeout() (timeout, interval time.Duration) { + return d.timeout, 2 * time.Second +} + // Present creates a TXT record using the specified parameters func (r *DNSProvider) Present(domain, token, keyAuth string) error { fqdn, value, ttl := acme.DNS01Record(domain, keyAuth) diff --git a/providers/dns/rfc2136/rfc2136_test.go b/providers/dns/rfc2136/rfc2136_test.go index a2515e99..f3ca65b3 100644 --- a/providers/dns/rfc2136/rfc2136_test.go +++ b/providers/dns/rfc2136/rfc2136_test.go @@ -61,7 +61,7 @@ func TestRFC2136ServerSuccess(t *testing.T) { } defer server.Shutdown() - provider, err := NewDNSProviderCredentials(addrstr, "", "", "") + provider, err := NewDNSProviderCredentials(addrstr, "", "", "", "") if err != nil { t.Fatalf("Expected NewDNSProviderCredentials() to return no error but the error was -> %v", err) } @@ -81,7 +81,7 @@ func TestRFC2136ServerError(t *testing.T) { } defer server.Shutdown() - provider, err := NewDNSProviderCredentials(addrstr, "", "", "") + provider, err := NewDNSProviderCredentials(addrstr, "", "", "", "") if err != nil { t.Fatalf("Expected NewDNSProviderCredentials() to return no error but the error was -> %v", err) } @@ -103,7 +103,7 @@ func TestRFC2136TsigClient(t *testing.T) { } defer server.Shutdown() - provider, err := NewDNSProviderCredentials(addrstr, "", rfc2136TestTsigKey, rfc2136TestTsigSecret) + provider, err := NewDNSProviderCredentials(addrstr, "", rfc2136TestTsigKey, rfc2136TestTsigSecret, "") if err != nil { t.Fatalf("Expected NewDNSProviderCredentials() to return no error but the error was -> %v", err) } @@ -135,7 +135,7 @@ func TestRFC2136ValidUpdatePacket(t *testing.T) { t.Fatalf("Error packing expect msg: %v", err) } - provider, err := NewDNSProviderCredentials(addrstr, "", "", "") + provider, err := NewDNSProviderCredentials(addrstr, "", "", "", "") if err != nil { t.Fatalf("Expected NewDNSProviderCredentials() to return no error but the error was -> %v", err) }