-
Notifications
You must be signed in to change notification settings - Fork 14
/
dnsdomains.go
325 lines (292 loc) · 10.7 KB
/
dnsdomains.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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
package glesys
import (
"context"
)
// DNSDomainService provides functions to interact with dns domains
type DNSDomainService struct {
client clientInterface
}
// DNSDomain represents a domain
type DNSDomain struct {
Name string `json:"domainname"`
Available bool `json:"available,omitempty"`
CreateTime string `json:"createtime,omitempty"`
DisplayName string `json:"displayname,omitempty"`
Expire int `json:"expire,omitempty"`
Minimum int `json:"minimum,omitempty"`
Prices []DNSDomainPrice `json:"prices,omitempty"`
PrimaryNameServer string `json:"primarynameserver,omitempty"`
RecordCount int `json:"recordcount,omitempty"`
Refresh int `json:"refresh,omitempty"`
RegistrarInfo RegistrarInfo `json:"registrarinfo,omitempty"`
ResponsiblePerson string `json:"responsibleperson,omitempty"`
Retry int `json:"retry,omitempty"`
TTL int `json:"ttl,omitempty"`
UsingGlesysNameserver string `json:"usingglesysnameserver,omitempty"`
}
// DNSDomainPrice represents the price for a single domain
type DNSDomainPrice struct {
Amount float64 `json:"amount"`
Currency string `json:"currency"`
Years int `json:"years"`
}
// AddDNSDomainParams - used for adding existing domains to GleSYS
// use CreateRecords = false to not create additional records.
type AddDNSDomainParams struct {
Name string `json:"domainname"`
CreateRecords string `json:"createrecords,omitempty"`
Expire int `json:"expire,omitempty"`
Minimum int `json:"minimum,omitempty"`
PrimaryNameServer string `json:"primarynameserver,omitempty"`
Refresh int `json:"refresh,omitempty"`
ResponsiblePerson string `json:"responsibleperson,omitempty"`
Retry int `json:"retry,omitempty"`
TTL int `json:"ttl,omitempty"`
}
// EditDNSDomainParams - used when editing domain parameters
type EditDNSDomainParams struct {
Name string `json:"domainname"`
Expire int `json:"expire,omitempty"`
Minimum int `json:"minimum,omitempty"`
PrimaryNameServer string `json:"primarynameserver,omitempty"`
Refresh int `json:"refresh,omitempty"`
ResponsiblePerson string `json:"responsibleperson,omitempty"`
Retry int `json:"retry,omitempty"`
TTL int `json:"ttl,omitempty"`
}
// RegistrarInfo contains information about the registrar for the domain
type RegistrarInfo struct {
AutoRenew string `json:"autorenew"`
State string `json:"state"`
StateDescription string `json:"statedescription,omitempty"`
Expire string `json:"expire,omitempty"`
TLD string `json:"tld,omitempty"`
InvoiceNumber string `json:"invoicenumber,omitempty"`
}
// RegisterDNSDomainParams - parameters used when registering a domain
type RegisterDNSDomainParams struct {
Name string `json:"domainname"`
Address string `json:"address"`
City string `json:"city"`
Country string `json:"country"`
Email string `json:"email"`
Firstname string `json:"firstname"`
Lastname string `json:"lastname"`
NationalID int `json:"nationalid"`
Organization string `json:"organization"`
PhoneNumber string `json:"phonenumber"`
ZipCode string `json:"zipcode"`
FaxNumber string `json:"fax,omitempty"`
NumYears int `json:"numyears,omitempty"`
}
// DeleteDNSDomainParams - parameters for deleting a domain from the dns system.
// Set ForceDeleteEmail to true, to delete a domain AND email accounts for the domain.
type DeleteDNSDomainParams struct {
Name string `json:"domainname"`
ForceDeleteEmail string `json:"forcedeleteemail,omitempty"`
}
// RenewDNSDomainParams - parameters to send when renewing a domain.
type RenewDNSDomainParams struct {
Name string `json:"domainname"`
NumYears int `json:"numyears"`
}
// SetAutoRenewParams - parameters to send for renewing a domain automatically.
type SetAutoRenewParams struct {
Name string `json:"domainname"`
SetAutoRenew string `json:"setautorenew"`
}
// DNSDomainRecord - data in the domain
type DNSDomainRecord struct {
DomainName string `json:"domainname"`
Data string `json:"data"`
Host string `json:"host"`
RecordID int `json:"recordid"`
TTL int `json:"ttl"`
Type string `json:"type"`
}
// AddRecordParams - parameters for updating domain records
type AddRecordParams struct {
DomainName string `json:"domainname"`
Data string `json:"data"`
Host string `json:"host"`
Type string `json:"type"`
TTL int `json:"ttl,omitempty"`
}
// UpdateRecordParams - parameters for updating domain records
type UpdateRecordParams struct {
RecordID int `json:"recordid"`
Data string `json:"data,omitempty"`
Host string `json:"host,omitempty"`
Type string `json:"type,omitempty"`
TTL int `json:"ttl,omitempty"`
}
// ChangeNameserverParams - parameters for updating the nameservers for domain
type ChangeNameserverParams struct {
DomainName string `json:"domainname"`
NS1 string `json:"NS1"`
NS2 string `json:"NS2"`
NS3 string `json:"NS3,omitempty"`
NS4 string `json:"NS4,omitempty"`
}
// Available - checks if the domain is available
func (s *DNSDomainService) Available(context context.Context, search string) (*[]DNSDomain, error) {
data := struct {
Response struct {
Domain []DNSDomain
}
}{}
err := s.client.post(context, "domain/available", &data, search)
return &data.Response.Domain, err
}
// AddDNSDomain - add an existing domain to your GleSYS account
func (s *DNSDomainService) AddDNSDomain(context context.Context, params AddDNSDomainParams) (*DNSDomain, error) {
data := struct {
Response struct {
Domain DNSDomain
}
}{}
err := s.client.post(context, "domain/add", &data, params)
return &data.Response.Domain, err
}
// Delete - deletes a domain from the dns system
func (s *DNSDomainService) Delete(context context.Context, params DeleteDNSDomainParams) error {
return s.client.post(context, "domain/delete", nil, params)
}
// Details - return details about the domain
func (s *DNSDomainService) Details(context context.Context, domainname string) (*DNSDomain, error) {
data := struct {
Response struct {
Domain DNSDomain
}
}{}
err := s.client.post(context, "domain/details", &data, struct {
Name string `json:"domainname"`
}{domainname})
return &data.Response.Domain, err
}
// Edit - edit domain parameters
func (s *DNSDomainService) Edit(context context.Context, params EditDNSDomainParams) (*DNSDomain, error) {
data := struct {
Response struct {
Domain DNSDomain
}
}{}
err := s.client.post(context, "domain/edit", &data, params)
return &data.Response.Domain, err
}
// Export - return the zonefile for the domain
func (s *DNSDomainService) Export(context context.Context, domainname string) (string, error) {
data := struct {
Response struct {
Zonefile string
}
}{}
err := s.client.post(context, "domain/export", &data, struct {
Name string `json:"domainname"`
}{domainname})
return data.Response.Zonefile, err
}
// List - return a list of all domains in your account
func (s *DNSDomainService) List(context context.Context) (*[]DNSDomain, error) {
data := struct {
Response struct {
Domains []DNSDomain
}
}{}
err := s.client.get(context, "domain/list", &data)
return &data.Response.Domains, err
}
// GenerateAuthCode - return a authcode for the domain
func (s *DNSDomainService) GenerateAuthCode(context context.Context, domainname string) (string, error) {
data := struct {
Response struct {
Authcode string
}
}{}
err := s.client.post(context, "domain/generateauthcode", &data, struct {
Name string `json:"domainname"`
}{domainname})
return data.Response.Authcode, err
}
// Register - Register a domain
func (s *DNSDomainService) Register(context context.Context, params RegisterDNSDomainParams) (*DNSDomain, error) {
data := struct {
Response struct {
Domain DNSDomain
}
}{}
err := s.client.post(context, "domain/register", &data, params)
return &data.Response.Domain, err
}
// Renew - Renew a domain
func (s *DNSDomainService) Renew(context context.Context, params RenewDNSDomainParams) (*DNSDomain, error) {
data := struct {
Response struct {
Domain DNSDomain
}
}{}
err := s.client.post(context, "domain/renew", &data, params)
return &data.Response.Domain, err
}
// SetAutoRenew - Set a domain to renew automatically
func (s *DNSDomainService) SetAutoRenew(context context.Context, params SetAutoRenewParams) (*DNSDomain, error) {
data := struct {
Response struct {
Domain DNSDomain
}
}{}
err := s.client.post(context, "domain/setautorenew", &data, params)
return &data.Response.Domain, err
}
// Transfer - Transfer a domain
func (s *DNSDomainService) Transfer(context context.Context, params RegisterDNSDomainParams) (*DNSDomain, error) {
data := struct {
Response struct {
Domain DNSDomain
}
}{}
err := s.client.post(context, "domain/transfer", &data, params)
return &data.Response.Domain, err
}
// ListRecords - return a list of all records for domain
func (s *DNSDomainService) ListRecords(context context.Context, domainname string) (*[]DNSDomainRecord, error) {
data := struct {
Response struct {
Records []DNSDomainRecord
}
}{}
err := s.client.post(context, "domain/listrecords", &data, struct {
Name string `json:"domainname"`
}{domainname})
return &data.Response.Records, err
}
// AddRecord - add a domain record
func (s *DNSDomainService) AddRecord(context context.Context, params AddRecordParams) (*DNSDomainRecord, error) {
data := struct {
Response struct {
Record DNSDomainRecord
}
}{}
err := s.client.post(context, "domain/addrecord", &data, params)
return &data.Response.Record, err
}
// UpdateRecord - update a domain record
func (s *DNSDomainService) UpdateRecord(context context.Context, params UpdateRecordParams) (*DNSDomainRecord, error) {
data := struct {
Response struct {
Record DNSDomainRecord
}
}{}
err := s.client.post(context, "domain/updaterecord", &data, params)
return &data.Response.Record, err
}
// DeleteRecord deletes a record
func (s *DNSDomainService) DeleteRecord(context context.Context, recordID int) error {
return s.client.post(context, "domain/deleterecord", nil, struct {
RecordID int `json:"recordid"`
}{recordID})
}
// ChangeNameservers - change the nameservers for domain
func (s *DNSDomainService) ChangeNameservers(context context.Context, params ChangeNameserverParams) error {
return s.client.post(context, "domain/changenameservers", nil, params)
}