-
Notifications
You must be signed in to change notification settings - Fork 1
/
types.go
212 lines (182 loc) · 4.37 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
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
package autodns
import (
"fmt"
"strings"
)
type AutoDNSObject struct {
Type string `json:"type"`
Value string `json:"value"`
}
type AutoDNSUser struct {
Context int32 `json:"context"`
User string `json:"user"`
}
type RequestZone struct {
Domain string `json:"domain"`
}
type AutoDNSMessage struct {
Text string `json:"text"`
Objects []AutoDNSObject `json:"objects"`
Code string `json:"code"`
Status string `json:"status"`
}
type AutoDNSResponse struct {
STID string `json:"stid"`
Status struct {
Type string `json:"type"`
Code *string `json:"resultCode,omitempty"`
Text *string `json:"text,omitempty"`
} `json:"status"`
Object *AutoDNSObject `json:"object,omitempty"`
// potential error messages
Messages []*AutoDNSMessage `json:"messages,omitempty"`
}
type ResponseSearch struct {
AutoDNSResponse
Data []ResponseSearchItem `json:"data"`
}
type ResponseZone struct {
AutoDNSResponse
Data []ZoneItem `json:"data"`
}
// {
// "created": "2023-10-18T13:56:47.000+0200",
// "updated": "2024-10-25T13:16:43.000+0200",
// "origin": "something.example.org",
// "nameServerGroup": "ns14.net",
// "owner": {
// "context": 4,
// "user": "user"
// },
// "updater": {
// "context": 4,
// "user": "user"
// },
// "domainsafe": false,
// "wwwInclude": false,
// "virtualNameServer": "a.ns14.net"
// }
type ResponseSearchItem struct {
Created string `json:"created"`
Updated string `json:"updated"`
Origin string `json:"origin"`
NSGroup string `json:"nameServerGroup"`
Owner AutoDNSUser `json:"owner"`
Updater AutoDNSUser `json:"updater"`
DomainSafe bool `json:"domainsafe"`
WWWWInclude bool `json:"wwwInclude"`
Nameserver string `json:"virtualNameserver"`
}
// {
// "created": "2023-10-18T13:56:47.000+0200",
// "updated": "2024-10-25T13:16:43.000+0200",
// "origin": "something.example.org",
// "soa": {
// "refresh": 43200,
// "retry": 7200,
// "expire": 1209600,
// "ttl": 86400,
// "email": "do-not-reply@something.example.org"
// },
// "nameServerGroup": "ns14.net",
// "owner": {
// "context": 4,
// "user": "user"
// },
// "updater": {
// "context": 4,
// "user": "user"
// },
// "domainsafe": false,
// "purgeType": "DISABLED",
// "nameServers": [
// {
// "name": "a.ns14.net"
// },
// {
// "name": "b.ns14.net"
// },
// {
// "name": "c.ns14.net"
// },
// {
// "name": "d.ns14.net"
// }
// ],
// "main": {
// "address": "127.0.0.1"
// },
// "wwwInclude": false,
// "virtualNameServer": "a.ns14.net",
// "action": "COMPLETE",
// "resourceRecords": [
// {
// "name": "*",
// "type": "A",
// "value": "127.0.0.1"
// }
// ],
// "roid": 9149383
// }
//
// ]
type ZoneRecord struct {
Name string `json:"name"`
Type string `json:"type"`
Value string `json:"value"`
}
type ZoneItem struct {
Created string `json:"created"`
Updated string `json:"updated"`
Origin string `json:"origin"`
SOA struct {
Refresh int `json:"refresh"`
Retry int `json:"retry"`
Expire int `json:"expire"`
TTL int `json:"ttl"`
Email string `json:"email"`
} `json:"soa"`
NSGroup string `json:"nameServerGroup"`
Owner AutoDNSUser `json:"owner"`
Updater AutoDNSUser `json:"updater"`
DomainSafe bool `json:"domainsafe"`
PurgeType string `json:"purgeType"`
Nameservers []struct {
Name string `json:"name"`
} `json:"nameservers"`
Main struct {
Address string `json:"address"`
} `json:"main"`
WWWWInclude bool `json:"wwwInclude"`
Nameserver string `json:"virtualNameserver"`
Action string `json:"action"`
Records []ZoneRecord `json:"resourceRecords"`
ROID int `json:"roid"`
}
type AutoDNSError struct {
messages []*AutoDNSMessage
}
func (m *AutoDNSError) Error() string {
if m.messages == nil {
return "unknown error"
}
var errs []string
for _, m := range m.messages {
objects := []string{}
for _, o := range m.Objects {
objects = append(objects, "%s (type: %s)", o.Value, o.Type)
}
errs = append(errs, fmt.Sprintf("%s, code: %s, objects: %s",
m.Text, m.Code, strings.Join(objects, ", "),
))
}
return strings.Join(errs, "; ")
}
func (m *AutoDNSError) Messages() []*AutoDNSMessage {
return m.messages
}
func NewError(resp AutoDNSResponse) *AutoDNSError {
return &AutoDNSError{
messages: resp.Messages,
}
}