-
Notifications
You must be signed in to change notification settings - Fork 32
/
route53.go
157 lines (147 loc) · 3.58 KB
/
route53.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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
package route53
import (
"strconv"
"time"
"github.com/libdns/route53"
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
)
// Provider wraps the provider implementation as a Caddy module.
type Provider struct{ *route53.Provider }
func init() {
caddy.RegisterModule(Provider{})
}
// CaddyModule returns the Caddy module information.
func (Provider) CaddyModule() caddy.ModuleInfo {
return caddy.ModuleInfo{
ID: "dns.providers.route53",
New: func() caddy.Module {
return &Provider{new(route53.Provider)}
},
}
}
// Provision implements the Provisioner interface to initialize the AWS Client
func (p *Provider) Provision(ctx caddy.Context) error {
repl := caddy.NewReplacer()
p.Provider.Profile = repl.ReplaceAll(p.Provider.Profile, "")
p.Provider.AWSProfile = repl.ReplaceAll(p.Provider.AWSProfile, "")
p.Provider.AccessKeyId = repl.ReplaceAll(p.Provider.AccessKeyId, "")
p.Provider.SecretAccessKey = repl.ReplaceAll(p.Provider.SecretAccessKey, "")
p.Provider.Token = repl.ReplaceAll(p.Provider.Token, "")
p.Provider.SessionToken = repl.ReplaceAll(p.Provider.SessionToken, "")
p.Provider.Region = repl.ReplaceAll(p.Provider.Region, "")
return nil
}
// UnmarshalCaddyfile sets up the DNS provider from Caddyfile tokens. Syntax:
//
// route53 {
// region <string>
// profile <string>
// access_key_id <string>
// secret_access_key <string>
// session_token <string>
// max_retries <int>
// max_wait_dur <int>
// wait_for_propagation <bool>
// hosted_zone_id <string>
// }
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 "wait_for_propagation":
if d.NextArg() {
if wait, err := strconv.ParseBool(d.Val()); err == nil {
p.Provider.WaitForPropagation = wait
}
}
if d.NextArg() {
return d.ArgErr()
}
case "max_wait_dur":
if d.NextArg() {
if dur, err := strconv.ParseInt(d.Val(), 10, 64); err == nil {
p.Provider.MaxWaitDur = time.Duration(dur)
}
}
if d.NextArg() {
return d.ArgErr()
}
case "max_retries":
if d.NextArg() {
p.Provider.MaxRetries, _ = strconv.Atoi(d.Val())
}
if d.NextArg() {
return d.ArgErr()
}
case "profile":
if d.NextArg() {
p.Provider.Profile = d.Val()
}
if d.NextArg() {
return d.ArgErr()
}
case "aws_profile":
if d.NextArg() {
p.Provider.AWSProfile = d.Val()
}
if d.NextArg() {
return d.ArgErr()
}
case "access_key_id":
if d.NextArg() {
p.Provider.AccessKeyId = d.Val()
}
if d.NextArg() {
return d.ArgErr()
}
case "secret_access_key":
if d.NextArg() {
p.Provider.SecretAccessKey = d.Val()
}
if d.NextArg() {
return d.ArgErr()
}
case "session_token":
if d.NextArg() {
p.Provider.SessionToken = d.Val()
}
if d.NextArg() {
return d.ArgErr()
}
case "token":
if d.NextArg() {
p.Provider.Token = d.Val()
}
if d.NextArg() {
return d.ArgErr()
}
case "region":
if d.NextArg() {
p.Provider.Region = d.Val()
}
if d.NextArg() {
return d.ArgErr()
}
case "hosted_zone_id":
if d.NextArg() {
p.Provider.HostedZoneID = d.Val()
}
if d.NextArg() {
return d.ArgErr()
}
default:
return d.Errf("unrecognized subdirective '%s'", d.Val())
}
}
}
return nil
}
// Interface guards
var (
_ caddyfile.Unmarshaler = (*Provider)(nil)
_ caddy.Provisioner = (*Provider)(nil)
)