lego/certificate/authorization.go

70 lines
1.6 KiB
Go
Raw Normal View History

2019-03-11 16:56:48 +00:00
package certificate
import (
"time"
2020-09-02 01:20:01 +00:00
"github.com/go-acme/lego/v4/acme"
"github.com/go-acme/lego/v4/log"
)
func (c *Certifier) getAuthorizations(order acme.ExtendedOrder) ([]acme.Authorization, error) {
resc, errc := make(chan acme.Authorization), make(chan domainError)
delay := time.Second / time.Duration(c.overallRequestLimit)
for _, authzURL := range order.Authorizations {
time.Sleep(delay)
go func(authzURL string) {
authz, err := c.core.Authorizations.Get(authzURL)
if err != nil {
errc <- domainError{Domain: authz.Identifier.Value, Error: err}
return
}
resc <- authz
}(authzURL)
}
var responses []acme.Authorization
2023-08-19 16:05:33 +00:00
failures := newObtainError()
2024-03-20 19:30:35 +00:00
for range len(order.Authorizations) {
select {
case res := <-resc:
responses = append(responses, res)
case err := <-errc:
2023-08-19 16:05:33 +00:00
failures.Add(err.Domain, err.Error)
}
}
for i, auth := range order.Authorizations {
log.Infof("[%s] AuthURL: %s", order.Identifiers[i].Value, auth)
}
close(resc)
close(errc)
2023-08-19 16:05:33 +00:00
return responses, failures.Join()
}
func (c *Certifier) deactivateAuthorizations(order acme.ExtendedOrder, force bool) {
for _, authzURL := range order.Authorizations {
auth, err := c.core.Authorizations.Get(authzURL)
if err != nil {
log.Infof("Unable to get the authorization for: %s", authzURL)
continue
}
if auth.Status == acme.StatusValid && !force {
log.Infof("Skipping deactivating of valid auth: %s", authzURL)
continue
}
log.Infof("Deactivating auth: %s", authzURL)
if c.core.Authorizations.Deactivate(authzURL) != nil {
log.Infof("Unable to deactivate the authorization: %s", authzURL)
}
}
}