More logging about account loading/creation
This commit is contained in:
parent
ed73243f8b
commit
a1e1bd6ab5
@ -33,6 +33,7 @@ import (
|
||||
"sync"
|
||||
|
||||
"github.com/mholt/acmez/v2/acme"
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
// getAccount either loads or creates a new account, depending on if
|
||||
@ -40,8 +41,15 @@ import (
|
||||
func (am *ACMEIssuer) getAccount(ctx context.Context, ca, email string) (acme.Account, error) {
|
||||
acct, err := am.loadAccount(ctx, ca, email)
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
am.Logger.Info("creating new account because no account for configured email is known to us",
|
||||
zap.String("email", email),
|
||||
zap.String("ca", ca),
|
||||
zap.Error(err))
|
||||
return am.newAccount(email)
|
||||
}
|
||||
am.Logger.Debug("using existing ACME account because key found in storage associated with email",
|
||||
zap.String("email", email),
|
||||
zap.String("ca", ca))
|
||||
return acct, err
|
||||
}
|
||||
|
||||
|
@ -53,6 +53,7 @@ func (iss *ACMEIssuer) newACMEClientWithAccount(ctx context.Context, useTestCA,
|
||||
// look up or create the ACME account
|
||||
var account acme.Account
|
||||
if iss.AccountKeyPEM != "" {
|
||||
iss.Logger.Info("using configured ACME account")
|
||||
account, err = iss.GetAccount(ctx, []byte(iss.AccountKeyPEM))
|
||||
} else {
|
||||
account, err = iss.getAccount(ctx, client.Directory, iss.getEmail())
|
||||
@ -63,6 +64,10 @@ func (iss *ACMEIssuer) newACMEClientWithAccount(ctx context.Context, useTestCA,
|
||||
|
||||
// register account if it is new
|
||||
if account.Status == "" {
|
||||
iss.Logger.Info("ACME account has empty status; registering account with ACME server",
|
||||
zap.Strings("contact", account.Contact),
|
||||
zap.String("location", account.Location))
|
||||
|
||||
if iss.NewAccountFunc != nil {
|
||||
// obtain lock here, since NewAccountFunc calls happen concurrently and they typically read and change the issuer
|
||||
iss.mu.Lock()
|
||||
@ -116,6 +121,9 @@ func (iss *ACMEIssuer) newACMEClientWithAccount(ctx context.Context, useTestCA,
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("registering account %v with server: %w", account.Contact, err)
|
||||
}
|
||||
iss.Logger.Info("new ACME account registered",
|
||||
zap.Strings("contact", account.Contact),
|
||||
zap.String("status", account.Status))
|
||||
|
||||
// persist the account to storage
|
||||
err = iss.saveAccount(ctx, client.Directory, account)
|
||||
|
Loading…
Reference in New Issue
Block a user