-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmodule.go
111 lines (100 loc) · 2.67 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package inwx
import (
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
libdnsinwx "github.com/libdns/inwx"
)
// Provider lets Caddy read and manipulate DNS records hosted by INWX.
type Provider struct{ *libdnsinwx.Provider }
func init() {
caddy.RegisterModule(Provider{})
}
// CaddyModule returns the Caddy module information.
func (Provider) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: "dns.providers.inwx",
New: func() caddy.Module { return &Provider{new(libdnsinwx.Provider)} },
}
}
// Before using the provider config, resolve placeholders.
// Implements caddy.Provisioner.
func (p *Provider) Provision(ctx caddy.Context) error {
p.Provider.Username = caddy.NewReplacer().ReplaceAll(p.Provider.Username, "")
p.Provider.Password = caddy.NewReplacer().ReplaceAll(p.Provider.Password, "")
p.Provider.SharedSecret = caddy.NewReplacer().ReplaceAll(p.Provider.SharedSecret, "")
p.Provider.EndpointURL = caddy.NewReplacer().ReplaceAll(p.Provider.EndpointURL, "")
return nil
}
// UnmarshalCaddyfile sets up the DNS provider from Caddyfile tokens. Syntax:
//
// inwx {
// username <username>
// password <password>
// shared_secret <shared_secret>
// endpoint_url <endpoint_url>
// }
func (p *Provider) UnmarshalCaddyfile(d *caddyfile.Dispenser) error {
for d.Next() {
if d.NextArg() {
return d.ArgErr()
}
for nesting := d.Nesting(); d.NextBlock(nesting); {
switch d.Val() {
case "username":
if p.Provider.Username != "" {
return d.Err("Username already set")
}
if d.NextArg() {
p.Provider.Username = d.Val()
}
if d.NextArg() {
return d.ArgErr()
}
case "password":
if p.Provider.Password != "" {
return d.Err("Password already set")
}
if d.NextArg() {
p.Provider.Password = d.Val()
}
if d.NextArg() {
return d.ArgErr()
}
case "shared_secret":
if p.Provider.SharedSecret != "" {
return d.Err("Shared secret already set")
}
if d.NextArg() {
p.Provider.SharedSecret = d.Val()
}
if d.NextArg() {
return d.ArgErr()
}
case "endpoint_url":
if p.Provider.EndpointURL != "" {
return d.Err("Endpoint URL already set")
}
if d.NextArg() {
p.Provider.EndpointURL = d.Val()
}
if d.NextArg() {
return d.ArgErr()
}
default:
return d.Errf("unrecognized subdirective '%s'", d.Val())
}
}
}
if p.Provider.Username == "" {
return d.Err("missing username")
}
if p.Provider.Password == "" {
return d.Err("missing password")
}
return nil
}
// Interface guards
var (
_ caddyfile.Unmarshaler = (*Provider)(nil)
_ caddy.Provisioner = (*Provider)(nil)
)