Skip to content

Commit 55be6d8

Browse files
committed
Rename ACMEManager -> ACMEIssuer, CertificateManager -> Manager
This is necessary to eliminate confusing naming conventions, since now we have Manager types, having an issuer called ACMEManager was confusing. CertificateManager is a redundant name as this package is called CertMagic, so that a Manager manages certificates should be obvious. It's also more succinct. Plus, it's consistent with Issuer which is not named CertificateIssuer.
1 parent ae2a5dd commit 55be6d8

14 files changed

+130
-130
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Note that Let's Encrypt imposes [strict rate limits](https://letsencrypt.org/doc
176176

177177
While developing your application and testing it, use [their staging endpoint](https://letsencrypt.org/docs/staging-environment/) which has much higher rate limits. Even then, don't hammer it: but it's much safer for when you're testing. When deploying, though, use their production CA because their staging CA doesn't issue trusted certificates.
178178

179-
To use staging, set `certmagic.DefaultACME.CA = certmagic.LetsEncryptStagingCA` or set `CA` of every `ACMEManager` struct.
179+
To use staging, set `certmagic.DefaultACME.CA = certmagic.LetsEncryptStagingCA` or set `CA` of every `ACMEIssuer` struct.
180180

181181

182182

@@ -256,7 +256,7 @@ magic := certmagic.New(cache, certmagic.Config{
256256
// any customizations you need go here
257257
})
258258

259-
myACME := certmagic.NewACMEManager(magic, certmagic.ACMEManager{
259+
myACME := certmagic.NewACMEIssuer(magic, certmagic.ACMEIssuer{
260260
CA: certmagic.LetsEncryptStagingCA,
261261
262262
Agreed: true,
@@ -344,7 +344,7 @@ If wrapping your handler is not a good solution, try this inside your `ServeHTTP
344344

345345
```go
346346
magic := certmagic.NewDefault()
347-
myACME := certmagic.NewACMEManager(magic, certmagic.DefaultACME)
347+
myACME := certmagic.NewACMEIssuer(magic, certmagic.DefaultACME)
348348

349349
func ServeHTTP(w http.ResponseWriter, req *http.Request) {
350350
if myACME.HandleHTTPChallenge(w, r) {
@@ -388,7 +388,7 @@ The DNS challenge is perhaps the most useful challenge because it allows you to
388388

389389
This challenge works by setting a special record in the domain's zone. To do this automatically, your DNS provider needs to offer an API by which changes can be made to domain names, and the changes need to take effect immediately for best results. CertMagic supports [all DNS providers with `libdns` implementations](https://github.com/libdns)! It always cleans up the temporary record after the challenge completes.
390390

391-
To enable it, just set the `DNS01Solver` field on a `certmagic.ACMEManager` struct, or set the default `certmagic.ACMEManager.DNS01Solver` variable. For example, if my domains' DNS was served by Cloudflare:
391+
To enable it, just set the `DNS01Solver` field on a `certmagic.ACMEIssuer` struct, or set the default `certmagic.ACMEIssuer.DNS01Solver` variable. For example, if my domains' DNS was served by Cloudflare:
392392

393393
```go
394394
import "github.com/libdns/cloudflare"
@@ -400,7 +400,7 @@ certmagic.DefaultACME.DNS01Solver = &certmagic.DNS01Solver{
400400
}
401401
```
402402

403-
Now the DNS challenge will be used by default, and I can obtain certificates for wildcard domains, too. Enabling the DNS challenge disables the other challenges for that `certmagic.ACMEManager` instance.
403+
Now the DNS challenge will be used by default, and I can obtain certificates for wildcard domains, too. Enabling the DNS challenge disables the other challenges for that `certmagic.ACMEIssuer` instance.
404404

405405

406406
## On-Demand TLS

account.go

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import (
3737

3838
// getAccount either loads or creates a new account, depending on if
3939
// an account can be found in storage for the given CA + email combo.
40-
func (am *ACMEManager) getAccount(ctx context.Context, ca, email string) (acme.Account, error) {
40+
func (am *ACMEIssuer) getAccount(ctx context.Context, ca, email string) (acme.Account, error) {
4141
acct, err := am.loadAccount(ctx, ca, email)
4242
if errors.Is(err, fs.ErrNotExist) {
4343
return am.newAccount(email)
@@ -46,7 +46,7 @@ func (am *ACMEManager) getAccount(ctx context.Context, ca, email string) (acme.A
4646
}
4747

4848
// loadAccount loads an account from storage, but does not create a new one.
49-
func (am *ACMEManager) loadAccount(ctx context.Context, ca, email string) (acme.Account, error) {
49+
func (am *ACMEIssuer) loadAccount(ctx context.Context, ca, email string) (acme.Account, error) {
5050
regBytes, err := am.config.Storage.Load(ctx, am.storageKeyUserReg(ca, email))
5151
if err != nil {
5252
return acme.Account{}, err
@@ -71,7 +71,7 @@ func (am *ACMEManager) loadAccount(ctx context.Context, ca, email string) (acme.
7171

7272
// newAccount generates a new private key for a new ACME account, but
7373
// it does not register or save the account.
74-
func (*ACMEManager) newAccount(email string) (acme.Account, error) {
74+
func (*ACMEIssuer) newAccount(email string) (acme.Account, error) {
7575
var acct acme.Account
7676
if email != "" {
7777
acct.Contact = []string{"mailto:" + email} // TODO: should we abstract the contact scheme?
@@ -87,7 +87,7 @@ func (*ACMEManager) newAccount(email string) (acme.Account, error) {
8787
// GetAccount first tries loading the account with the associated private key from storage.
8888
// If it does not exist in storage, it will be retrieved from the ACME server and added to storage.
8989
// The account must already exist; it does not create a new account.
90-
func (am *ACMEManager) GetAccount(ctx context.Context, privateKeyPEM []byte) (acme.Account, error) {
90+
func (am *ACMEIssuer) GetAccount(ctx context.Context, privateKeyPEM []byte) (acme.Account, error) {
9191
account, err := am.loadAccountByKey(ctx, privateKeyPEM)
9292
if errors.Is(err, fs.ErrNotExist) {
9393
account, err = am.lookUpAccount(ctx, privateKeyPEM)
@@ -98,7 +98,7 @@ func (am *ACMEManager) GetAccount(ctx context.Context, privateKeyPEM []byte) (ac
9898
// loadAccountByKey loads the account with the given private key from storage, if it exists.
9999
// If it does not exist, an error of type fs.ErrNotExist is returned. This is not very efficient
100100
// for lots of accounts.
101-
func (am *ACMEManager) loadAccountByKey(ctx context.Context, privateKeyPEM []byte) (acme.Account, error) {
101+
func (am *ACMEIssuer) loadAccountByKey(ctx context.Context, privateKeyPEM []byte) (acme.Account, error) {
102102
accountList, err := am.config.Storage.List(ctx, am.storageKeyUsersPrefix(am.CA), false)
103103
if err != nil {
104104
return acme.Account{}, err
@@ -118,7 +118,7 @@ func (am *ACMEManager) loadAccountByKey(ctx context.Context, privateKeyPEM []byt
118118

119119
// lookUpAccount looks up the account associated with privateKeyPEM from the ACME server.
120120
// If the account is found by the server, it will be saved to storage and returned.
121-
func (am *ACMEManager) lookUpAccount(ctx context.Context, privateKeyPEM []byte) (acme.Account, error) {
121+
func (am *ACMEIssuer) lookUpAccount(ctx context.Context, privateKeyPEM []byte) (acme.Account, error) {
122122
client, err := am.newACMEClient(false)
123123
if err != nil {
124124
return acme.Account{}, fmt.Errorf("creating ACME client: %v", err)
@@ -147,7 +147,7 @@ func (am *ACMEManager) lookUpAccount(ctx context.Context, privateKeyPEM []byte)
147147

148148
// saveAccount persists an ACME account's info and private key to storage.
149149
// It does NOT register the account via ACME or prompt the user.
150-
func (am *ACMEManager) saveAccount(ctx context.Context, ca string, account acme.Account) error {
150+
func (am *ACMEIssuer) saveAccount(ctx context.Context, ca string, account acme.Account) error {
151151
regBytes, err := json.MarshalIndent(account, "", "\t")
152152
if err != nil {
153153
return err
@@ -178,7 +178,7 @@ func (am *ACMEManager) saveAccount(ctx context.Context, ca string, account acme.
178178
// the consequences of an empty email.) This function MAY prompt
179179
// the user for input. If allowPrompts is false, the user
180180
// will NOT be prompted and an empty email may be returned.
181-
func (am *ACMEManager) getEmail(ctx context.Context, allowPrompts bool) error {
181+
func (am *ACMEIssuer) getEmail(ctx context.Context, allowPrompts bool) error {
182182
leEmail := am.Email
183183

184184
// First try package default email, or a discovered email address
@@ -227,7 +227,7 @@ func (am *ACMEManager) getEmail(ctx context.Context, allowPrompts bool) error {
227227
// be the empty string). If no error is returned, then Agreed
228228
// will also be set to true, since continuing through the
229229
// prompt signifies agreement.
230-
func (am *ACMEManager) promptUserForEmail() (string, error) {
230+
func (am *ACMEIssuer) promptUserForEmail() (string, error) {
231231
// prompt the user for an email address and terms agreement
232232
reader := bufio.NewReader(stdin)
233233
am.promptUserAgreement("")
@@ -246,7 +246,7 @@ func (am *ACMEManager) promptUserForEmail() (string, error) {
246246
// promptUserAgreement simply outputs the standard user
247247
// agreement prompt with the given agreement URL.
248248
// It outputs a newline after the message.
249-
func (am *ACMEManager) promptUserAgreement(agreementURL string) {
249+
func (am *ACMEIssuer) promptUserAgreement(agreementURL string) {
250250
userAgreementPrompt := `Your sites will be served over HTTPS automatically using an automated CA.
251251
By continuing, you agree to the CA's terms of service`
252252
if agreementURL == "" {
@@ -259,7 +259,7 @@ By continuing, you agree to the CA's terms of service`
259259
// askUserAgreement prompts the user to agree to the agreement
260260
// at the given agreement URL via stdin. It returns whether the
261261
// user agreed or not.
262-
func (am *ACMEManager) askUserAgreement(agreementURL string) bool {
262+
func (am *ACMEIssuer) askUserAgreement(agreementURL string) bool {
263263
am.promptUserAgreement(agreementURL)
264264
fmt.Print("Do you agree to the terms? (y/n): ")
265265

@@ -277,32 +277,32 @@ func storageKeyACMECAPrefix(issuerKey string) string {
277277
return path.Join(prefixACME, StorageKeys.Safe(issuerKey))
278278
}
279279

280-
func (am *ACMEManager) storageKeyCAPrefix(caURL string) string {
280+
func (am *ACMEIssuer) storageKeyCAPrefix(caURL string) string {
281281
return storageKeyACMECAPrefix(am.issuerKey(caURL))
282282
}
283283

284-
func (am *ACMEManager) storageKeyUsersPrefix(caURL string) string {
284+
func (am *ACMEIssuer) storageKeyUsersPrefix(caURL string) string {
285285
return path.Join(am.storageKeyCAPrefix(caURL), "users")
286286
}
287287

288-
func (am *ACMEManager) storageKeyUserPrefix(caURL, email string) string {
288+
func (am *ACMEIssuer) storageKeyUserPrefix(caURL, email string) string {
289289
if email == "" {
290290
email = emptyEmail
291291
}
292292
return path.Join(am.storageKeyUsersPrefix(caURL), StorageKeys.Safe(email))
293293
}
294294

295-
func (am *ACMEManager) storageKeyUserReg(caURL, email string) string {
295+
func (am *ACMEIssuer) storageKeyUserReg(caURL, email string) string {
296296
return am.storageSafeUserKey(caURL, email, "registration", ".json")
297297
}
298298

299-
func (am *ACMEManager) storageKeyUserPrivateKey(caURL, email string) string {
299+
func (am *ACMEIssuer) storageKeyUserPrivateKey(caURL, email string) string {
300300
return am.storageSafeUserKey(caURL, email, "private", ".key")
301301
}
302302

303303
// storageSafeUserKey returns a key for the given email, with the default
304304
// filename, and the filename ending in the given extension.
305-
func (am *ACMEManager) storageSafeUserKey(ca, email, defaultFilename, extension string) string {
305+
func (am *ACMEIssuer) storageSafeUserKey(ca, email, defaultFilename, extension string) string {
306306
if email == "" {
307307
email = emptyEmail
308308
}
@@ -317,7 +317,7 @@ func (am *ACMEManager) storageSafeUserKey(ca, email, defaultFilename, extension
317317

318318
// emailUsername returns the username portion of an email address (part before
319319
// '@') or the original input if it can't find the "@" symbol.
320-
func (*ACMEManager) emailUsername(email string) string {
320+
func (*ACMEIssuer) emailUsername(email string) string {
321321
at := strings.Index(email, "@")
322322
if at == -1 {
323323
return email
@@ -331,7 +331,7 @@ func (*ACMEManager) emailUsername(email string) string {
331331
// in storage. Since this is part of a complex sequence to get a user
332332
// account, errors here are discarded to simplify code flow in
333333
// the caller, and errors are not important here anyway.
334-
func (am *ACMEManager) mostRecentAccountEmail(ctx context.Context, caURL string) (string, bool) {
334+
func (am *ACMEIssuer) mostRecentAccountEmail(ctx context.Context, caURL string) (string, bool) {
335335
accountList, err := am.config.Storage.List(ctx, am.storageKeyUsersPrefix(caURL), false)
336336
if err != nil || len(accountList) == 0 {
337337
return "", false

account_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ import (
2626
)
2727

2828
func TestNewAccount(t *testing.T) {
29-
am := &ACMEManager{CA: dummyCA}
29+
am := &ACMEIssuer{CA: dummyCA}
3030
testConfig := &Config{
3131
Issuers: []Issuer{am},
3232
Storage: &FileStorage{Path: "./_testdata_tmp"},
@@ -53,7 +53,7 @@ func TestNewAccount(t *testing.T) {
5353
func TestSaveAccount(t *testing.T) {
5454
ctx := context.Background()
5555

56-
am := &ACMEManager{CA: dummyCA}
56+
am := &ACMEIssuer{CA: dummyCA}
5757
testConfig := &Config{
5858
Issuers: []Issuer{am},
5959
Storage: &FileStorage{Path: "./_testdata1_tmp"},
@@ -88,7 +88,7 @@ func TestSaveAccount(t *testing.T) {
8888
func TestGetAccountDoesNotAlreadyExist(t *testing.T) {
8989
ctx := context.Background()
9090

91-
am := &ACMEManager{CA: dummyCA}
91+
am := &ACMEIssuer{CA: dummyCA}
9292
testConfig := &Config{
9393
Issuers: []Issuer{am},
9494
Storage: &FileStorage{Path: "./_testdata_tmp"},
@@ -109,7 +109,7 @@ func TestGetAccountDoesNotAlreadyExist(t *testing.T) {
109109
func TestGetAccountAlreadyExists(t *testing.T) {
110110
ctx := context.Background()
111111

112-
am := &ACMEManager{CA: dummyCA}
112+
am := &ACMEIssuer{CA: dummyCA}
113113
testConfig := &Config{
114114
Issuers: []Issuer{am},
115115
Storage: &FileStorage{Path: "./_testdata2_tmp"},
@@ -163,7 +163,7 @@ func TestGetEmailFromPackageDefault(t *testing.T) {
163163
discoveredEmail = ""
164164
}()
165165

166-
am := &ACMEManager{CA: dummyCA}
166+
am := &ACMEIssuer{CA: dummyCA}
167167
testConfig := &Config{
168168
Issuers: []Issuer{am},
169169
Storage: &FileStorage{Path: "./_testdata2_tmp"},
@@ -184,7 +184,7 @@ func TestGetEmailFromPackageDefault(t *testing.T) {
184184
func TestGetEmailFromUserInput(t *testing.T) {
185185
ctx := context.Background()
186186

187-
am := &ACMEManager{CA: dummyCA}
187+
am := &ACMEIssuer{CA: dummyCA}
188188
testConfig := &Config{
189189
Issuers: []Issuer{am},
190190
Storage: &FileStorage{Path: "./_testdata3_tmp"},
@@ -218,7 +218,7 @@ func TestGetEmailFromUserInput(t *testing.T) {
218218
func TestGetEmailFromRecent(t *testing.T) {
219219
ctx := context.Background()
220220

221-
am := &ACMEManager{CA: dummyCA}
221+
am := &ACMEIssuer{CA: dummyCA}
222222
testConfig := &Config{
223223
Issuers: []Issuer{am},
224224
Storage: &FileStorage{Path: "./_testdata4_tmp"},

0 commit comments

Comments
 (0)