Skip to content

Commit

Permalink
More logging about account loading/creation
Browse files Browse the repository at this point in the history
  • Loading branch information
mholt committed Jun 4, 2024
1 parent ed73243 commit a1e1bd6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
8 changes: 8 additions & 0 deletions account.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,23 @@ import (
"sync"

"github.com/mholt/acmez/v2/acme"
"go.uber.org/zap"
)

// getAccount either loads or creates a new account, depending on if
// an account can be found in storage for the given CA + email combo.
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
}

Expand Down
8 changes: 8 additions & 0 deletions acmeclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit a1e1bd6

Please sign in to comment.