Skip to content

Commit

Permalink
Merge pull request #148 from xi2/challenge-provider-custom-timeout
Browse files Browse the repository at this point in the history
Add ChallengeProviderTimeout type to acme package
  • Loading branch information
xenolf committed Mar 17, 2016
2 parents f00bb8b + 8aa797f commit faed8af
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
10 changes: 9 additions & 1 deletion acme/dns_challenge.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions acme/provider.go
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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)
}

0 comments on commit faed8af

Please sign in to comment.