-
-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added multiple DNS provider support #331
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -69,13 +69,13 @@ func DNS01Record(domain, keyAuth string) (fqdn string, value string, ttl int) { | |
type dnsChallenge struct { | ||
jws *jws | ||
validate validateFunc | ||
provider ChallengeProvider | ||
providers []ChallengeProvider | ||
} | ||
|
||
func (s *dnsChallenge) Solve(chlng challenge, domain string) error { | ||
logf("[INFO][%s] acme: Trying to solve DNS-01", domain) | ||
|
||
if s.provider == nil { | ||
if s.providers == nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Don't check for nil here, a slice will not be nil but have a len() of zero. |
||
return errors.New("No DNS Provider configured") | ||
} | ||
|
||
|
@@ -85,14 +85,22 @@ func (s *dnsChallenge) Solve(chlng challenge, domain string) error { | |
return err | ||
} | ||
|
||
err = s.provider.Present(domain, chlng.Token, keyAuth) | ||
if err != nil { | ||
return fmt.Errorf("Error presenting token: %s", err) | ||
for _, v := range s.providers { | ||
err = v.Present(domain, chlng.Token, keyAuth) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This would try to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I didn't thought about this use case. But normally you have one or more DNS provider per Domain. I designed the function that way. This means if you want to validate something.url.com, and you have two DNS providers, you can add both to set the right TXT record. With the old system, it was not possible to know which DNS provider will serve the answer and validation could be invalid. I'm not sure if we want to provide a mapping per domain and DNS provider. Actually I don't see such a use case. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @ManuelGysin I see where you are coming from. But I also see the use case where people want to add domains to a SAN certificate which are hosted by different DNS providers. |
||
|
||
if err != nil { | ||
return fmt.Errorf("Error presenting token: %s", err) | ||
} | ||
} | ||
|
||
defer func() { | ||
err := s.provider.CleanUp(domain, chlng.Token, keyAuth) | ||
if err != nil { | ||
log.Printf("Error cleaning up %s: %v ", domain, err) | ||
|
||
for _, v := range s.providers { | ||
err := v.CleanUp(domain, chlng.Token, keyAuth) | ||
|
||
if err != nil { | ||
log.Printf("Error cleaning up %s: %v ", domain, err) | ||
} | ||
} | ||
}() | ||
|
||
|
@@ -101,16 +109,30 @@ func (s *dnsChallenge) Solve(chlng challenge, domain string) error { | |
logf("[INFO][%s] Checking DNS record propagation using %+v", domain, RecursiveNameservers) | ||
|
||
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 | ||
|
||
for _, v := range s.providers { | ||
var tiou, inter time.Duration | ||
|
||
switch provider := v.(type) { | ||
case ChallengeProviderTimeout: | ||
tiou, inter = provider.Timeout() | ||
default: | ||
tiou, inter = 60*time.Second, 2*time.Second | ||
} | ||
|
||
// Check if interval or timeout is greater, we take the highest number | ||
if timeout < tiou { | ||
timeout = tiou | ||
} | ||
if interval < inter { | ||
interval = inter | ||
} | ||
} | ||
|
||
err = WaitFor(timeout, interval, func() (bool, error) { | ||
return PreCheckDNS(fqdn, value) | ||
}) | ||
|
||
if err != nil { | ||
return err | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add a comment to exported functions. Also use plural as we're possibly setting multiple providers?