Skip to content

Commit 029dc84

Browse files
committed
More changes for Caddy's documentation generator
It turns out that Caddy's documentation generator also looks at fields tagged with `json:"-"`, for which it doesn't generate documentation.
1 parent 145a526 commit 029dc84

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

client_policy.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ type ClientPolicy struct {
1818
// largely follows Smallstep's domain name rules:
1919
// https://smallstep.com/docs/step-ca/policies/#domain-names
2020
//
21-
// Due to a limitation in ACME and DNS-01, allowing a domain alsow allows
21+
// Due to a limitation in ACME and DNS-01, allowing a domain also allows
2222
// wildcard certificates for that domain.
2323
AllowDomainsRaw []string `json:"allow_domains,omitempty"`
2424
DenyDomainsRaw []string `json:"deny_domains,omitempty"`

client_registry.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"strings"
77

88
"github.com/caddyserver/caddy/v2"
9-
"github.com/liujed/goutil/maps"
109
"github.com/liujed/goutil/optionals"
1110
"github.com/smallstep/certificates/policy"
1211
)
@@ -36,29 +35,29 @@ const challengeDomainPrefix = "_acme-challenge."
3635
// A registry of known users and their corresponding policy configuration.
3736
type ClientRegistry struct {
3837
// Maps each client's user ID to its policy configuration.
39-
Clients maps.Map[string, *ClientPolicy]
38+
clients map[string]*ClientPolicy
4039
}
4140

4241
func (c *ClientRegistry) Provision(
4342
ctx caddy.Context,
4443
accountsRaw []RawAccount,
4544
) error {
4645
// Convert accountsRaw into a map keyed on user ID.
47-
c.Clients = maps.NewHashMap[string, *ClientPolicy]()
46+
c.clients = map[string]*ClientPolicy{}
4847
for i, rawAccount := range accountsRaw {
49-
if c.Clients.ContainsKey(rawAccount.UserID) {
48+
if _, containsKey := c.clients[rawAccount.UserID]; containsKey {
5049
return fmt.Errorf(
5150
"account %d: user ID is not unique: %q",
5251
i,
5352
rawAccount.UserID,
5453
)
5554
}
5655

57-
c.Clients.Put(rawAccount.UserID, &rawAccount.ClientPolicy)
56+
c.clients[rawAccount.UserID] = &rawAccount.ClientPolicy
5857
}
5958

6059
// Provision the ClientPolicy instances.
61-
for userID, ca := range c.Clients.Entries() {
60+
for userID, ca := range c.clients {
6261
err := ca.Provision(ctx)
6362
if err != nil {
6463
return fmt.Errorf(
@@ -88,7 +87,7 @@ func (r *ClientRegistry) AuthorizeUserChallengeDomain(
8887
fmt.Errorf("unable to determine user ID (is authentication configured?)")
8988
}
9089

91-
config, exists := r.Clients.Get(userID).Get()
90+
config, exists := r.clients[userID]
9291
if !exists {
9392
return optionals.Some(DenyUnknownUser), nil
9493
}

handler.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,10 @@ type Handler struct {
4444
// Specifies how clients should be authenticated. If absent, then clients must
4545
// be authenticated by an `http.handlers.authentication` instance earlier in
4646
// the handler chain. Derived from [AccountsRaw].
47-
Authentication optionals.Optional[*caddyauth.Authentication] `json:"-"`
47+
//
48+
// XXX This should be an Optional[*caddyauth.Authentication], but Caddy's
49+
// documentation generator doesn't work with generics.
50+
Authentication *caddyauth.Authentication `json:"-"`
4851

4952
// Identifies the domains at which each client is allowed to answer DNS-01
5053
// challenges. Derived from [AccountsRaw].
@@ -111,7 +114,7 @@ func (h *Handler) Provision(ctx caddy.Context) error {
111114
return fmt.Errorf("unable to provision authenticaiton: %w", err)
112115
}
113116

114-
h.Authentication = optionals.Some(auth)
117+
h.Authentication = auth
115118
}
116119

117120
// Normally, we expect either all users or no users to have a password
@@ -158,8 +161,8 @@ func (h *Handler) ServeHTTP(
158161
}
159162

160163
handlerImpl := jsonutil.WrapHandler(h.handleDNSRequest(mode))
161-
if auth, exists := h.Authentication.Get(); exists {
162-
return auth.ServeHTTP(w, req, handlerImpl)
164+
if h.Authentication != nil {
165+
return h.Authentication.ServeHTTP(w, req, handlerImpl)
163166
}
164167
return handlerImpl.ServeHTTP(w, req)
165168
}

0 commit comments

Comments
 (0)