Skip to content

Commit 145a526

Browse files
committed
Another fix for Caddy's documentation generator
Also improved module documentation.
1 parent 2761d20 commit 145a526

File tree

4 files changed

+35
-18
lines changed

4 files changed

+35
-18
lines changed

app.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,21 @@ func init() {
1616
caddy.RegisterModule(App{})
1717
}
1818

19-
// A Caddy application module that implements the dns01proxy server.
19+
// A proxy server for ACME DNS-01 challenges. Designed to work with acme.sh's
20+
// `acmeproxy`, lego's `httpreq`, and Caddy's `acmeproxy` DNS providers.
21+
//
22+
// This is a Caddy application module.
2023
type App struct {
2124
Handler
2225

2326
// The server's hostnames. Used for obtaining TLS certificates.
2427
Hostnames []string `json:"hostnames"`
2528

26-
// The sockets on which to listen.
29+
// The sockets on which to listen. For example, "127.0.0.1:9095" or ":443".
2730
Listen []string `json:"listen"`
2831

29-
// Configures the set of trusted proxies.
32+
// Configures the set of trusted proxies, for accurate logging of client IP
33+
// addresses.
3034
TrustedProxiesRaw json.RawMessage `json:"trusted_proxies,omitempty" caddy:"namespace=http.ip_sources inline_key=source"`
3135

3236
// The http module instance that implements this app.

client_policy.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,12 @@ type ClientPolicy struct {
1414
// Identifies the client to which this policy applies.
1515
UserID string `json:"user_id"`
1616

17+
// Determines the domains for which the user can get TLS certificates. This
18+
// largely follows Smallstep's domain name rules:
19+
// https://smallstep.com/docs/step-ca/policies/#domain-names
20+
//
21+
// Due to a limitation in ACME and DNS-01, allowing a domain alsow allows
22+
// wildcard certificates for that domain.
1723
AllowDomainsRaw []string `json:"allow_domains,omitempty"`
1824
DenyDomainsRaw []string `json:"deny_domains,omitempty"`
1925

dns_config.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,17 @@ import (
99
)
1010

1111
type DNSConfig struct {
12+
// The DNS provider for publishing DNS-01 responses.
1213
ProviderRaw json.RawMessage `json:"provider" caddy:"namespace=dns.providers inline_key=name"`
1314

1415
Provider certmagic.DNSProvider `json:"-"`
1516

16-
// The TTL to use for the DNS TXT records when answering challenges.
17-
//
18-
// XXX This should be an Optional[caddy.Duration], but Caddy's documentation
19-
// generator can handle neither generics nor types with custom JSON
20-
// representations.
17+
// The TTL to use in DNS TXT records when answering challenges. Optional. Not
18+
// usually needed.
2119
TTL *caddy.Duration `json:"ttl,omitempty"`
2220

23-
// Custom DNS resolvers to prefer over system/built-in defaults. Often
24-
// necessary to configure when using split-horizon DNS.
21+
// Custom DNS resolvers to prefer over system or built-in defaults. Set this
22+
// to a public resolver if you are using split-horizon DNS.
2523
Resolvers []string `json:"resolvers,omitempty"`
2624
}
2725

handler.go

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,17 @@ func init() {
2828
)
2929
}
3030

31-
// A Caddy `http.handlers` module that implements the dns01proxy API.
31+
// Implements an API for proxying ACME DNS-01 challenges.
32+
//
33+
// This is a Caddy `http.handlers` module.
3234
type Handler struct {
3335
DNS DNSConfig `json:"dns"`
3436

35-
// During provisioning, this is used to fill in [Authentication] and
36-
// [ClientRegistry].
37+
// Configures HTTP basic authentication and the domains for which each user
38+
// can get TLS certificates.
39+
//
40+
// (During provisioning, this is used to fill in [Authentication] and
41+
// [ClientRegistry].)
3742
AccountsRaw []RawAccount `json:"accounts"`
3843

3944
// Specifies how clients should be authenticated. If absent, then clients must
@@ -55,7 +60,11 @@ var _ caddyfile.Unmarshaler = (*Handler)(nil)
5560

5661
type RawAccount struct {
5762
ClientPolicy
58-
Password optionals.Optional[string] `json:"password"`
63+
64+
// The user's password, hashed using `caddy hash-password`. Optional. If
65+
// omitted, then clients must be authenticated by an
66+
// `http.handlers.authentication` instance earlier in the handler chain.
67+
Password *string `json:"password,omitempty"`
5968
}
6069

6170
func (Handler) CaddyModule() caddy.ModuleInfo {
@@ -79,10 +88,10 @@ func (h *Handler) Provision(ctx caddy.Context) error {
7988
// Provision Authentication from AccountsRaw.
8089
accountList := []caddyauth.Account{}
8190
for _, rawAccount := range h.AccountsRaw {
82-
if password, exists := rawAccount.Password.Get(); exists {
91+
if rawAccount.Password != nil {
8392
accountList = append(accountList, caddyauth.Account{
8493
Username: rawAccount.UserID,
85-
Password: password,
94+
Password: *rawAccount.Password,
8695
})
8796
}
8897
}
@@ -329,10 +338,10 @@ func (h *Handler) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
329338
if !d.AllArgs((&password)) {
330339
return d.ArgErr()
331340
}
332-
if account.Password.IsSome() {
341+
if account.Password != nil {
333342
return fmt.Errorf("cannot specify more than one password per user")
334343
}
335-
account.Password = optionals.Some(password)
344+
account.Password = &password
336345
continue
337346

338347
case "allow_domains":

0 commit comments

Comments
 (0)