/
types.go
196 lines (162 loc) · 5.62 KB
/
types.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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
package dnsmadeeasy
import (
"strconv"
"github.com/StackExchange/dnscontrol/v4/models"
)
// DNS Made Easy does not allow the system name servers to be edited, and said records appear to always have a fixed TTL of 86400.
const fixedNameServerRecordTTL = 86400
type singleDomainResponse struct {
ID int `json:"id"`
Name string `json:"name"`
DelegateNameServers []string `json:"delegateNameServers"`
NameServers []singleDomainResponseNameServer `json:"nameServers"`
ProcessMulti bool `json:"processMulti"`
ActiveThirdParties []interface{} `json:"activeThirdParties"`
PendingActionID int `json:"pendingActionId"`
GtdEnabled bool `json:"gtdEnabled"`
Created int64 `json:"created"`
Updated int64 `json:"updated"`
}
type singleDomainResponseNameServer struct {
Fqdn string `json:"fqdn"`
Ipv4 string `json:"ipv4"`
Ipv6 string `json:"ipv6"`
}
type singleDomainRequestData struct {
Name string `json:"name"`
}
type multiDomainResponse struct {
TotalRecords int `json:"totalRecords"`
TotalPages int `json:"totalPages"`
Data []multiDomainResponseDataEntry `json:"data"`
Page int `json:"page"`
}
type multiDomainResponseDataEntry struct {
ID int `json:"id"`
Name string `json:"name"`
FolderID int `json:"folderId"`
GtdEnabled bool `json:"gtdEnabled"`
ProcessMulti bool `json:"processMulti"`
ActiveThirdParties []interface{} `json:"activeThirdParties"`
PendingActionID int `json:"pendingActionId"`
VanityID int `json:"vanityId,omitempty"`
Created int64 `json:"created"`
Updated int64 `json:"updated"`
}
type recordResponse struct {
TotalRecords int `json:"totalRecords"`
TotalPages int `json:"totalPages"`
Data []recordResponseDataEntry `json:"data"`
Page int `json:"page"`
}
type recordResponseDataEntry struct {
ID int `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Value string `json:"value"`
TTL int `json:"ttl"`
Source int `json:"source"`
SourceID int `json:"sourceId"`
DynamicDNS bool `json:"dynamicDns"`
Password string `json:"password"`
// A records
Monitor bool `json:"monitor"`
Failover bool `json:"failover"`
Failed bool `json:"failed"`
// Global Traffic Director
GtdLocation string `json:"gtdLocation"`
// HTTPRED records
Description string `json:"description"`
Keywords string `json:"keywords"`
Title string `json:"title"`
RedirectType string `json:"redirectType"`
HardLink bool `json:"hardLink"`
// MX records
MxLevel int `json:"mxLevel"`
// SRV records
Weight int `json:"weight"`
Priority int `json:"Priority"`
Port int `json:"port"`
// CAA records
CaaType string `json:"caaType"`
IssuerCritical int `json:"issuerCritical"`
}
type recordRequestData struct {
ID int `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Value string `json:"value"`
TTL int `json:"ttl"`
// Global Traffic Director
GtdLocation string `json:"gtdLocation"`
// MX records
MxLevel int `json:"mxLevel"`
// SRV records
Weight int `json:"weight,omitempty"`
Priority int `json:"priority,omitempty"`
Port int `json:"port,omitempty"`
// CAA records
CaaType string `json:"caaType"`
IssuerCritical int `json:"issuerCritical"`
}
func toRecordConfig(domain string, record *recordResponseDataEntry) *models.RecordConfig {
rc := &models.RecordConfig{
Type: record.Type,
TTL: uint32(record.TTL),
Original: record,
}
rc.SetLabel(record.Name, domain)
var err error
if record.Type == "MX" {
err = rc.SetTargetMX(uint16(record.MxLevel), record.Value)
} else if record.Type == "SRV" {
err = rc.SetTargetSRV(uint16(record.Priority), uint16(record.Weight), uint16(record.Port), record.Value)
} else if record.Type == "CAA" {
value, unquoteErr := strconv.Unquote(record.Value)
if unquoteErr != nil {
panic(unquoteErr)
}
err = rc.SetTargetCAA(uint8(record.IssuerCritical), record.CaaType, value)
} else {
err = rc.PopulateFromString(record.Type, record.Value, domain)
}
if err != nil {
panic(err)
}
return rc
}
func fromRecordConfig(rc *models.RecordConfig) *recordRequestData {
label := rc.GetLabel()
if label == "@" {
label = ""
}
record := &recordRequestData{
Type: rc.Type,
TTL: int(rc.TTL),
GtdLocation: "DEFAULT",
Name: label,
Value: rc.GetTargetCombined(),
}
if record.Type == "MX" {
record.MxLevel = int(rc.MxPreference)
record.Value = rc.GetTargetField()
} else if record.Type == "SRV" {
target := rc.GetTargetField()
if target == "." {
target += "."
}
record.Priority = int(rc.SrvPriority)
record.Weight = int(rc.SrvWeight)
record.Port = int(rc.SrvPort)
record.Value = target
} else if record.Type == "CAA" {
record.IssuerCritical = int(rc.CaaFlag)
record.CaaType = rc.CaaTag
record.Value = rc.GetTargetField()
}
return record
}
func systemNameServerToRecordConfig(domain string, nameServer string) *models.RecordConfig {
target := nameServer + "."
return toRecordConfig(domain, &recordResponseDataEntry{Type: "NS", Value: target, TTL: fixedNameServerRecordTTL})
}