acme: add Client.WaitAuthorization for polling
It is quite often the case users need to poll an authorization until it reaches a final state. This change adds a handy method to do exactly that, as well as updating autocert.Manager to use the new method. Change-Id: I4d25e4ee751731815b77980caab6da98d3440b5d Reviewed-on: https://go-review.googlesource.com/27431 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
This commit is contained in:
@@ -453,29 +453,8 @@ func (m *Manager) verify(ctx context.Context, domain string) error {
|
||||
return err
|
||||
}
|
||||
// wait for the CA to validate
|
||||
for {
|
||||
a, err := client.GetAuthz(ctx, authz.URI)
|
||||
if err == nil {
|
||||
if a.Status == acme.StatusValid {
|
||||
break
|
||||
}
|
||||
if a.Status == acme.StatusInvalid {
|
||||
return fmt.Errorf("acme/autocert: validation for domain %q failed", domain)
|
||||
}
|
||||
}
|
||||
// still pending
|
||||
d := time.Second
|
||||
if ae, ok := err.(*acme.Error); ok {
|
||||
d = retryAfter(ae.Header.Get("retry-after"))
|
||||
}
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return ctx.Err()
|
||||
case <-time.After(d):
|
||||
// retry
|
||||
}
|
||||
}
|
||||
return nil
|
||||
_, err = client.WaitAuthorization(ctx, authz.URI)
|
||||
return err
|
||||
}
|
||||
|
||||
// certState returns existing state or creates a new one locked for read/write.
|
||||
|
||||
Reference in New Issue
Block a user