-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmodule.go
81 lines (69 loc) · 1.58 KB
/
module.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package caddy_dns_rfc2136
import (
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
"github.com/caddyserver/certmagic"
"github.com/libdns/rfc2136"
)
type Provider struct {
*rfc2136.Provider
}
func init() {
caddy.RegisterModule(Provider{})
}
func (Provider) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: "dns.providers.rfc2136",
New: func() caddy.Module { return &Provider{new(rfc2136.Provider)} },
}
}
func (p *Provider) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() {
for nesting := d.Nesting(); d.NextBlock(nesting); {
var dst *string
switch d.Val() {
case "key_name":
dst = &p.KeyName
case "key":
dst = &p.Key
case "key_alg":
dst = &p.KeyAlg
case "server":
dst = &p.Server
default:
return d.Errf("unrecognized subdirective '%s'", d.Val())
}
if d.NextArg() {
*dst = d.Val()
}
if d.NextArg() {
return d.ArgErr()
}
}
}
if p.Key == "" {
return d.Err("rfc2136: missing key")
}
if p.KeyName == "" {
return d.Err("rfc2136: missing key_name")
}
if p.KeyAlg == "" {
return d.Err("rfc2136: missing key_alg")
}
if p.Server == "" {
return d.Err("rfc2136: missing server")
}
return nil
}
func (p *Provider) Provision(_ caddy.Context) error {
repl := caddy.NewReplacer()
p.KeyName = repl.ReplaceAll(p.KeyName, "")
p.Key = repl.ReplaceAll(p.Key, "")
p.KeyAlg = repl.ReplaceAll(p.KeyAlg, "")
p.Server = repl.ReplaceAll(p.Server, "")
return nil
}
var (
_ caddyfile.Unmarshaler = (*Provider)(nil)
_ certmagic.DNSProvider = (*Provider)(nil)
)