From 8aa797f49d8ae62385e570b8ebe8769f06a80dec Mon Sep 17 00:00:00 2001 From: Michael Cross Date: Sat, 12 Mar 2016 14:58:44 +0000 Subject: [PATCH] Add ChallengeProviderTimeout type to acme package This type allows for implementing DNS ChallengeProviders that require an unsually long timeout when checking for record propagation. --- acme/dns_challenge.go | 10 +++++++++- acme/provider.go | 18 ++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/acme/dns_challenge.go b/acme/dns_challenge.go index e5be0105..d9ff3e7e 100644 --- a/acme/dns_challenge.go +++ b/acme/dns_challenge.go @@ -69,7 +69,15 @@ func (s *dnsChallenge) Solve(chlng challenge, domain string) error { logf("[INFO][%s] Checking DNS record propagation...", domain) - err = WaitFor(60*time.Second, 2*time.Second, func() (bool, error) { + var timeout, interval time.Duration + switch provider := s.provider.(type) { + case ChallengeProviderTimeout: + timeout, interval = provider.Timeout() + default: + timeout, interval = 60*time.Second, 2*time.Second + } + + err = WaitFor(timeout, interval, func() (bool, error) { return preCheckDNS(fqdn, value) }) if err != nil { diff --git a/acme/provider.go b/acme/provider.go index 4db5e893..d177ff07 100644 --- a/acme/provider.go +++ b/acme/provider.go @@ -1,5 +1,7 @@ package acme +import "time" + // ChallengeProvider enables implementing a custom challenge // provider. Present presents the solution to a challenge available to // be solved. CleanUp will be called by the challenge if Present ends @@ -8,3 +10,19 @@ type ChallengeProvider interface { Present(domain, token, keyAuth string) error CleanUp(domain, token, keyAuth string) error } + +// ChallengeProviderTimeout allows for implementing a +// ChallengeProvider where an unusually long timeout is required when +// waiting for an ACME challenge to be satisfied, such as when +// checking for DNS record progagation. If an implementor of a +// ChallengeProvider provides a Timeout method, then the return values +// of the Timeout method will be used when appropriate by the acme +// package. The interval value is the time between checks. +// +// The default values used for timeout and interval are 60 seconds and +// 2 seconds respectively. These are used when no Timeout method is +// defined for the ChallengeProvider. +type ChallengeProviderTimeout interface { + ChallengeProvider + Timeout() (timeout, interval time.Duration) +}