forked from infobloxopen/infoblox-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
object_manager_forward_zone.go
209 lines (181 loc) · 5.02 KB
/
object_manager_forward_zone.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
package ibclient
import (
"encoding/json"
"fmt"
"reflect"
)
// Handle FORWARD_TO to be [] list
type NullForwardTo struct {
ForwardTo []NameServer
IsNull bool
}
func (nft NullForwardTo) MarshalJSON() ([]byte, error) {
if reflect.DeepEqual(nft.ForwardTo, []NameServer{}) {
return []byte("[]"), nil
}
return json.Marshal(nft.ForwardTo)
}
func (nft *NullForwardTo) UnmarshalJSON(data []byte) error {
if string(data) == "null" {
nft.IsNull = true
nft.ForwardTo = nil
return nil
}
nft.IsNull = false
return json.Unmarshal(data, &nft.ForwardTo)
}
// Forwarding Server to be [] list
type NullableForwardingServers struct {
Servers []*Forwardingmemberserver
IsNull bool // Indicates if the entire slice should be null
}
func (nfs NullableForwardingServers) MarshalJSON() ([]byte, error) {
if reflect.DeepEqual(nfs.Servers, []*Forwardingmemberserver{}) {
return []byte("[]"), nil
}
return json.Marshal(nfs.Servers)
}
func (nfs *NullableForwardingServers) UnmarshalJSON(data []byte) error {
if string(data) == "null" {
nfs.IsNull = true
nfs.Servers = nil
return nil
}
nfs.IsNull = false
return json.Unmarshal(data, &nfs.Servers)
}
func (objMgr *ObjectManager) CreateZoneForward(
comment string,
disable bool,
eas EA,
forwardTo NullForwardTo,
forwardersOnly bool,
forwardingServers *NullableForwardingServers,
fqdn string,
nsGroup string,
view string,
zoneFormat string,
externalNsGroup string) (*ZoneForward, error) {
// check if required fields are present
// Check for FQDN
if fqdn == "" {
return nil, fmt.Errorf("FQDN is required to create a forward zone")
}
if forwardingServers != nil && forwardingServers.Servers != nil {
forwardingServers = &NullableForwardingServers{Servers: forwardingServers.Servers}
} else {
forwardingServers = nil
}
zoneForward := NewZoneForward(comment, disable, eas, forwardTo, forwardersOnly, forwardingServers, fqdn, nsGroup, view, zoneFormat, "", externalNsGroup)
ref, err := objMgr.connector.CreateObject(zoneForward)
if err != nil {
return nil, err
}
zoneForward.Ref = ref
return zoneForward, nil
}
func (objMgr *ObjectManager) DeleteZoneForward(ref string) (string, error) {
return objMgr.connector.DeleteObject(ref)
}
func (objMgr *ObjectManager) GetZoneForwardByRef(ref string) (*ZoneForward, error) {
zoneForward := NewEmptyZoneForward()
err := objMgr.connector.GetObject(zoneForward, ref, NewQueryParams(false, nil), &zoneForward)
if err != nil {
return nil, err
}
return zoneForward, nil
}
func (objMgr *ObjectManager) GetZoneForwardFilters(queryParams *QueryParams) ([]ZoneForward, error) {
var res []ZoneForward
zoneForward := NewEmptyZoneForward()
err := objMgr.connector.GetObject(
zoneForward, "", queryParams, &res)
if err != nil {
return nil, err
}
return res, err
}
func (objMgr *ObjectManager) UpdateZoneForward(
ref string,
comment string,
disable bool,
eas EA,
forwardTo NullForwardTo,
forwardersOnly bool,
forwardingServers *NullableForwardingServers,
nsGroup string,
externlNsGroup string) (*ZoneForward, error) {
zoneForward := NewEmptyZoneForward()
zoneForward.Comment = &comment
zoneForward.Disable = &disable
zoneForward.Ea = eas
zoneForward.ForwardTo = forwardTo
zoneForward.ForwardersOnly = &forwardersOnly
if forwardingServers != nil && forwardingServers.Servers != nil {
zoneForward.ForwardingServers = &NullableForwardingServers{Servers: forwardingServers.Servers}
} else {
zoneForward.ForwardingServers = nil
}
if nsGroup != "" {
zoneForward.NsGroup = &nsGroup
} else {
zoneForward.NsGroup = nil
}
if externlNsGroup != "" {
zoneForward.ExternalNsGroup = &externlNsGroup
} else {
zoneForward.ExternalNsGroup = nil
}
new_ref, err := objMgr.connector.UpdateObject(zoneForward, ref)
if err != nil {
return nil, err
}
zoneForward.Ref = new_ref
return zoneForward, nil
}
func NewEmptyZoneForward() *ZoneForward {
zoneForward := &ZoneForward{}
zoneForward.SetReturnFields(append(zoneForward.ReturnFields(), "zone_format", "ns_group", "external_ns_group", "comment", "disable", "extattrs", "forwarders_only", "forwarding_servers"))
return zoneForward
}
func NewZoneForward(comment string,
disable bool,
eas EA,
forwardTo NullForwardTo,
forwardersOnly bool,
forwardingServers *NullableForwardingServers,
fqdn string,
nsGroup string,
view string,
zoneFormat string,
ref string,
externalNsGroup string) *ZoneForward {
zoneForward := NewEmptyZoneForward()
zoneForward.Comment = &comment
zoneForward.Disable = &disable
zoneForward.Ea = eas
zoneForward.ForwardTo = forwardTo
zoneForward.ForwardersOnly = &forwardersOnly
zoneForward.ForwardingServers = forwardingServers
zoneForward.Fqdn = fqdn
if nsGroup == "" {
zoneForward.NsGroup = nil
} else {
zoneForward.NsGroup = &nsGroup
}
if externalNsGroup == "" {
zoneForward.ExternalNsGroup = nil
} else {
zoneForward.ExternalNsGroup = &externalNsGroup
}
if view == "" {
view = "default"
}
zoneForward.View = &view
if zoneFormat == "" {
zoneFormat = "FORWARD"
}
zoneForward.ZoneFormat = zoneFormat
zoneForward.Ref = ref
return zoneForward
}