-
Notifications
You must be signed in to change notification settings - Fork 88
/
object_manager_srv-record.go
184 lines (153 loc) · 3.6 KB
/
object_manager_srv-record.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
package ibclient
import (
"fmt"
)
func validateSrvRecArgs(
name string,
priority uint32,
weight uint32,
port uint32,
target string) error {
if name == "" {
return fmt.Errorf("'name' must not be empty")
}
if err := ValidateSrvRecName(name); err != nil {
return err
}
if err := CheckIntRange("priority", int(priority), 0, 65535); err != nil {
return err
}
if err := CheckIntRange("port", int(port), 0, 65535); err != nil {
return err
}
if err := CheckIntRange("weight", int(weight), 0, 65535); err != nil {
return err
}
if target == "" {
return fmt.Errorf("'target' value must not be empty")
}
if err := ValidateDomainName(target); err != nil {
return fmt.Errorf("validation of 'target' value failed: %s", err)
}
return nil
}
// CreateSRVRecord creates an SRV-record.
//
// Also, it preforms validation of input parameters: name, priority, weight, port and target.
func (objMgr *ObjectManager) CreateSRVRecord(
dnsView string,
name string,
priority uint32,
weight uint32,
port uint32,
target string,
ttl uint32,
useTtl bool,
comment string,
eas EA) (*RecordSRV, error) {
err := validateSrvRecArgs(
name,
priority,
weight,
port,
target)
if err != nil {
return nil, err
}
if dnsView == "" {
dnsView = "default"
}
recordSRV := NewRecordSRV(RecordSRV{
View: dnsView,
Name: &name,
Priority: &priority,
Weight: &weight,
Port: &port,
Target: &target,
Ttl: &ttl,
UseTtl: &useTtl,
Comment: &comment,
Ea: eas,
})
ref, err := objMgr.connector.CreateObject(recordSRV)
if err != nil {
return nil, err
}
recordSRV.Ref = ref
return recordSRV, nil
}
func (objMgr *ObjectManager) GetSRVRecord(dnsView string, name string, target string, port uint32) (*RecordSRV, error) {
if dnsView == "" || name == "" {
return nil, fmt.Errorf("'DNS view' and 'name' are required to retrieve a unique srv record")
}
var res []RecordSRV
recordSRV := NewEmptyRecordSRV()
sf := map[string]string{
"view": dnsView,
"name": name,
"target": fmt.Sprintf("%s", target),
"port": fmt.Sprintf("%d", port),
}
queryParams := NewQueryParams(false, sf)
err := objMgr.connector.GetObject(recordSRV, "", queryParams, &res)
if err != nil {
return nil, err
}
if res == nil || len(res) == 0 {
return nil, NewNotFoundError(
fmt.Sprintf(
"SRV record with name '%s' in DNS view '%s' is not found",
name, dnsView))
}
return &res[0], nil
}
func (objMgr *ObjectManager) GetSRVRecordByRef(ref string) (*RecordSRV, error) {
recordSRV := NewRecordSRV(RecordSRV{})
err := objMgr.connector.GetObject(recordSRV, ref, NewQueryParams(false, nil), &recordSRV)
return recordSRV, err
}
// UpdateSRVRecord updates the SRV-record.
//
// Also, it preforms validation of input parameters: name, priority, weight, port and target.
func (objMgr *ObjectManager) UpdateSRVRecord(
ref string,
name string,
priority uint32,
weight uint32,
port uint32,
target string,
ttl uint32,
useTtl bool,
comment string,
eas EA) (*RecordSRV, error) {
err := validateSrvRecArgs(
name,
priority,
weight,
port,
target)
if err != nil {
return nil, err
}
recordSRV := NewRecordSRV(RecordSRV{
Ref: ref,
Name: &name,
Priority: &priority,
Weight: &weight,
Port: &port,
Target: &target,
Ttl: &ttl,
UseTtl: &useTtl,
Comment: &comment,
Ea: eas,
})
nw_ref, err := objMgr.connector.UpdateObject(recordSRV, ref)
if err != nil {
return nil, err
}
recordSRV.Ref = nw_ref
return recordSRV, nil
}
func (objMgr *ObjectManager) DeleteSRVRecord(ref string) (string, error) {
return objMgr.connector.DeleteObject(ref)
}