authorization.go raw
1 package certificate
2
3 import (
4 "time"
5
6 "github.com/go-acme/lego/v4/acme"
7 "github.com/go-acme/lego/v4/log"
8 )
9
10 func (c *Certifier) getAuthorizations(order acme.ExtendedOrder) ([]acme.Authorization, error) {
11 resc, errc := make(chan acme.Authorization), make(chan domainError)
12
13 delay := time.Second / time.Duration(c.overallRequestLimit)
14
15 for _, authzURL := range order.Authorizations {
16 time.Sleep(delay)
17
18 go func(authzURL string) {
19 authz, err := c.core.Authorizations.Get(authzURL)
20 if err != nil {
21 errc <- domainError{Domain: authz.Identifier.Value, Error: err}
22 return
23 }
24
25 resc <- authz
26 }(authzURL)
27 }
28
29 var responses []acme.Authorization
30
31 failures := newObtainError()
32
33 for range len(order.Authorizations) {
34 select {
35 case res := <-resc:
36 responses = append(responses, res)
37 case err := <-errc:
38 failures.Add(err.Domain, err.Error)
39 }
40 }
41
42 for i, auth := range order.Authorizations {
43 log.Infof("[%s] AuthURL: %s", order.Identifiers[i].Value, auth)
44 }
45
46 close(resc)
47 close(errc)
48
49 return responses, failures.Join()
50 }
51
52 func (c *Certifier) deactivateAuthorizations(order acme.ExtendedOrder, force bool) {
53 for _, authzURL := range order.Authorizations {
54 auth, err := c.core.Authorizations.Get(authzURL)
55 if err != nil {
56 log.Infof("Unable to get the authorization for %s: %v", authzURL, err)
57 continue
58 }
59
60 if auth.Status == acme.StatusValid && !force {
61 log.Infof("Skipping deactivating of valid auth: %s", authzURL)
62 continue
63 }
64
65 log.Infof("Deactivating auth: %s", authzURL)
66
67 if c.core.Authorizations.Deactivate(authzURL) != nil {
68 log.Infof("Unable to deactivate the authorization: %s", authzURL)
69 }
70 }
71 }
72