forked from barnybug/cli53
-
Notifications
You must be signed in to change notification settings - Fork 0
/
awsrr.go
172 lines (141 loc) · 3.66 KB
/
awsrr.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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
package cli53
import (
"errors"
"fmt"
"github.com/miekg/dns"
)
const ClassAWS = 253
const TypeALIAS = 0x0F99
type ALIASRdata struct {
Type string
Target string
ZoneId string
EvaluateTargetHealth bool
}
func (rd *ALIASRdata) Copy(dest dns.PrivateRdata) error {
d := dest.(*ALIASRdata)
d.Type = rd.Type
d.Target = rd.Target
d.ZoneId = rd.ZoneId
d.EvaluateTargetHealth = rd.EvaluateTargetHealth
return nil
}
func (rd *ALIASRdata) Len() int {
return 0
}
func (rd *ALIASRdata) Parse(txt []string) error {
if len(txt) != 4 {
return errors.New("4 parts required for ALIAS: type target zoneid evaluateTargetHealth")
}
rd.Type = txt[0]
rd.Target = txt[1]
rd.ZoneId = txt[2]
rd.EvaluateTargetHealth = (txt[3] == "true")
return nil
}
func (rd *ALIASRdata) Pack(buf []byte) (int, error) {
return 0, nil
}
func (rd *ALIASRdata) Unpack(buf []byte) (int, error) {
return 0, nil
}
func (rr *ALIASRdata) String() string {
return fmt.Sprintf("%s %s %s %v",
rr.Type,
rr.Target,
rr.ZoneId,
rr.EvaluateTargetHealth,
)
}
func NewALIASRdata() dns.PrivateRdata { return new(ALIASRdata) }
func init() {
dns.StringToClass["AWS"] = ClassAWS
dns.ClassToString[ClassAWS] = "AWS"
dns.PrivateHandle("ALIAS", TypeALIAS, NewALIASRdata)
}
type AWSRoute interface {
String() string
Parse(KeyValues)
}
type AWSRR struct {
dns.RR
Route AWSRoute
HealthCheckId *string
Identifier string
}
func (rr *AWSRR) String() string {
var kvs KeyValues
if rr.HealthCheckId != nil {
kvs = append(kvs, "healthCheckId", *rr.HealthCheckId)
}
kvs = append(kvs, "identifier", rr.Identifier)
return fmt.Sprintf("%s ; AWS %s %s",
rr.RR,
rr.Route,
kvs,
)
}
type FailoverRoute struct {
Failover string
}
func (f *FailoverRoute) String() string {
return KeyValues{"routing", "FAILOVER", "failover", f.Failover}.String()
}
func (f *FailoverRoute) Parse(kvs KeyValues) {
f.Failover = kvs.GetString("failover")
}
type GeoLocationRoute struct {
CountryCode *string
ContinentCode *string
SubdivisionCode *string
}
func (f *GeoLocationRoute) String() string {
args := KeyValues{"routing", "GEOLOCATION"}
if f.CountryCode != nil {
args = append(args, "countryCode", *f.CountryCode)
}
if f.ContinentCode != nil {
args = append(args, "continentCode", *f.ContinentCode)
}
if f.SubdivisionCode != nil {
args = append(args, "subdivisionCode", *f.SubdivisionCode)
}
return args.String()
}
func (f *GeoLocationRoute) Parse(kvs KeyValues) {
f.CountryCode = kvs.GetOptString("countryCode")
f.ContinentCode = kvs.GetOptString("continentCode")
f.SubdivisionCode = kvs.GetOptString("subdivisonCode")
}
type LatencyRoute struct {
Region string
}
func (f *LatencyRoute) String() string {
return KeyValues{"routing", "LATENCY", "region", f.Region}.String()
}
func (f *LatencyRoute) Parse(kvs KeyValues) {
f.Region = kvs.GetString("region")
}
type WeightedRoute struct {
Weight int64
}
func (f *WeightedRoute) String() string {
return KeyValues{"routing", "WEIGHTED", "weight", f.Weight}.String()
}
func (f *WeightedRoute) Parse(kvs KeyValues) {
f.Weight = int64(kvs.GetInt("weight"))
}
type MultiValueAnswerRoute struct {
}
func (f *MultiValueAnswerRoute) String() string {
return KeyValues{"routing", "MULTIVALUE"}.String()
}
func (f *MultiValueAnswerRoute) Parse(kvs KeyValues) {
}
var RoutingTypes = map[string]func() AWSRoute{
"FAILOVER": func() AWSRoute { return &FailoverRoute{} },
"GEOLOCATION": func() AWSRoute { return &GeoLocationRoute{} },
"LATENCY": func() AWSRoute { return &LatencyRoute{} },
"WEIGHTED": func() AWSRoute { return &WeightedRoute{} },
"MULTIVALUE": func() AWSRoute { return &MultiValueAnswerRoute{} },
}