forked from infobloxopen/infoblox-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
objects.go
314 lines (253 loc) · 7.29 KB
/
objects.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
package ibclient
import (
"bytes"
"encoding/json"
"reflect"
)
const MACADDR_ZERO = "00:00:00:00:00:00"
type Bool bool
type EA map[string]interface{}
type EASearch map[string]interface{}
type EADefListValue string
type IBBase struct {
objectType string `json:"-"`
returnFields []string `json:"-"`
eaSearch EASearch `json:"-"`
}
type IBObject interface {
ObjectType() string
ReturnFields() []string
EaSearch() EASearch
}
func (obj *IBBase) ObjectType() string {
return obj.objectType
}
func (obj *IBBase) ReturnFields() []string {
return obj.returnFields
}
func (obj *IBBase) EaSearch() EASearch {
return obj.eaSearch
}
type NetworkView struct {
IBBase `json:"-"`
Ref string `json:"_ref,omitempty"`
Name string `json:"name,omitempty"`
Ea EA `json:"extattrs,omitempty"`
}
func NewNetworkView(nv NetworkView) *NetworkView {
res := nv
res.objectType = "networkview"
res.returnFields = []string{"extattrs", "name"}
return &res
}
type Network struct {
IBBase
Ref string `json:"_ref,omitempty"`
NetviewName string `json:"network_view,omitempty"`
Cidr string `json:"network,omitempty"`
Ea EA `json:"extattrs,omitempty"`
}
func NewNetwork(nw Network) *Network {
res := nw
res.objectType = "network"
res.returnFields = []string{"extattrs", "network", "network_view"}
return &res
}
type NetworkContainer struct {
IBBase `json:"-"`
Ref string `json:"_ref,omitempty"`
NetviewName string `json:"network_view,omitempty"`
Cidr string `json:"network,omitempty"`
Ea EA `json:"extattrs,omitempty"`
}
func NewNetworkContainer(nc NetworkContainer) *NetworkContainer {
res := nc
res.objectType = "networkcontainer"
res.returnFields = []string{"extattrs", "network", "network_view"}
return &res
}
type FixedAddress struct {
IBBase `json:"-"`
Ref string `json:"_ref,omitempty"`
NetviewName string `json:"network_view,omitempty"`
Cidr string `json:"network,omitempty"`
IPAddress string `json:"ipv4addr,omitempty"`
Mac string `json:"mac,omitempty"`
Ea EA `json:"extattrs,omitempty"`
}
func NewFixedAddress(fixedAddr FixedAddress) *FixedAddress {
res := fixedAddr
res.objectType = "fixedaddress"
res.returnFields = []string{"extattrs", "ipv4addr", "mac", "network", "network_view"}
return &res
}
type EADefinition struct {
IBBase `json:"-"`
Ref string `json:"_ref,omitempty"`
Comment string `json:"comment,omitempty"`
Flags string `json:"flags,omitempty"`
ListValues []EADefListValue `json:"list_values,omitempty"`
Name string `json:"name,omitempty"`
Type string `json:"type,omitempty"`
AllowedObjectTypes []string `json:"allowed_object_types,omitempty"`
}
func NewEADefinition(eadef EADefinition) *EADefinition {
res := eadef
res.objectType = "extensibleattributedef"
res.returnFields = []string{"allowed_object_types", "comment", "flags", "list_values", "name", "type"}
return &res
}
type UserProfile struct {
IBBase `json:"-"`
Ref string `json:"_ref,omitempty"`
Name string `json:"name,omitempty"`
}
func NewUserProfile(userprofile UserProfile) *UserProfile {
res := userprofile
res.objectType = "userprofile"
res.returnFields = []string{"name"}
return &res
}
type RecordA struct {
IBBase `json:"-"`
Ref string `json:"_ref,omitempty"`
Ipv4Addr string `json:"ipv4addr,omitempty"`
Name string `json:"name,omitempty"`
View string `json:"view,omitempty"`
Zone string `json:"zone,omitempty"`
Ea EA `json:"extattrs,omitempty"`
}
func NewRecordA(ra RecordA) *RecordA {
res := ra
res.objectType = "record:a"
res.returnFields = []string{"extattrs", "ipv4addr", "name", "view", "zone"}
return &res
}
type RecordCNAME struct {
IBBase `json:"-"`
Ref string `json:"_ref,omitempty"`
Canonical string `json:"canonical,omitempty"`
Name string `json:"name,omitempty"`
View string `json:"view,omitempty"`
Zone string `json:"zone,omitempty"`
Ea EA `json:"extattrs,omitempty"`
}
func NewRecordCNAME(rc RecordCNAME) *RecordCNAME {
res := rc
res.objectType = "record:cname"
res.returnFields = []string{"extattrs", "canonical", "name", "view", "zone"}
return &res
}
type RecordTXT struct {
IBBase `json:"-"`
Ref string `json:"_ref,omitempty"`
Name string `json:"name,omitempty"`
Text string `json:"text,omitempty"`
View string `json:"view,omitempty"`
Zone string `json:"zone,omitempty"`
Ea EA `json:"extattrs,omitempty"`
}
func NewRecordTXT(rt RecordTXT) *RecordTXT {
res := rt
res.objectType = "record:txt"
res.returnFields = []string{"extattrs", "name", "text", "view", "zone"}
return &res
}
type ZoneAuth struct {
IBBase `json:"-"`
Ref string `json:"_ref,omitempty"`
Fqdn string `json:"fqdn,omitempty"`
View string `json:"view,omitempty"`
Ea EA `json:"extattrs,omitempty"`
}
func NewZoneAuth(za ZoneAuth) *ZoneAuth {
res := za
res.objectType = "zone_auth"
res.returnFields = []string{"extattrs", "fqdn", "view"}
return &res
}
func (ea EA) MarshalJSON() ([]byte, error) {
m := make(map[string]interface{})
for k, v := range ea {
value := make(map[string]interface{})
value["value"] = v
m[k] = value
}
return json.Marshal(m)
}
func (eas EASearch) MarshalJSON() ([]byte, error) {
m := make(map[string]interface{})
for k, v := range eas {
m["*"+k] = v
}
return json.Marshal(m)
}
func (val EADefListValue) MarshalJSON() ([]byte, error) {
m := make(map[string]string)
m["value"] = string(val)
return json.Marshal(m)
}
func (b Bool) MarshalJSON() ([]byte, error) {
if b {
return json.Marshal("True")
}
return json.Marshal("False")
}
func (ea *EA) UnmarshalJSON(b []byte) (err error) {
var m map[string]map[string]interface{}
decoder := json.NewDecoder(bytes.NewBuffer(b))
decoder.UseNumber()
err = decoder.Decode(&m)
if err != nil {
return
}
*ea = make(EA)
for k, v := range m {
val := v["value"]
if reflect.TypeOf(val).String() == "json.Number" {
var i64 int64
i64, err = val.(json.Number).Int64()
val = int(i64)
} else if val.(string) == "True" {
val = Bool(true)
} else if val.(string) == "False" {
val = Bool(false)
}
(*ea)[k] = val
}
return
}
func (v *EADefListValue) UnmarshalJSON(b []byte) (err error) {
var m map[string]string
err = json.Unmarshal(b, &m)
if err != nil {
return
}
*v = EADefListValue(m["value"])
return
}
type RequestBody struct {
Data map[string]interface{} `json:"data,omitempty"`
Args map[string]string `json:"args,omitempty"`
Method string `json:"method"`
Object string `json:"object,omitempty"`
EnableSubstitution bool `json:"enable_substitution,omitempty"`
AssignState map[string]string `json:"assign_state,omitempty"`
Discard bool `json:"discard,omitempty"`
}
type SingleRequest struct {
IBBase `json:"-"`
Body *RequestBody
}
type MultiRequest struct {
IBBase `json:"-"`
Body []*RequestBody
}
func (r *MultiRequest) MarshalJSON() ([]byte, error) {
return json.Marshal(r.Body)
}
func NewMultiRequest(body []*RequestBody) *MultiRequest {
req := &MultiRequest{Body: body}
req.objectType = "request"
return req
}