-
Notifications
You must be signed in to change notification settings - Fork 88
/
object_manager_txt-record.go
81 lines (67 loc) · 1.97 KB
/
object_manager_txt-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
package ibclient
import "fmt"
// Creates TXT Record. Use TTL of 0 to inherit TTL from the Zone
func (objMgr *ObjectManager) CreateTXTRecord(
dnsView string,
recordName string,
text string,
ttl uint32,
useTtl bool,
comment string,
eas EA) (*RecordTXT, error) {
recordTXT := NewRecordTXT(dnsView, "", recordName, text, ttl, useTtl, comment, eas)
ref, err := objMgr.connector.CreateObject(recordTXT)
if err != nil {
return nil, err
}
recordTXT, err = objMgr.GetTXTRecordByRef(ref)
return recordTXT, err
}
func (objMgr *ObjectManager) GetTXTRecordByRef(ref string) (*RecordTXT, error) {
recordTXT := NewEmptyRecordTXT()
err := objMgr.connector.GetObject(
recordTXT, ref, NewQueryParams(false, nil), &recordTXT)
return recordTXT, err
}
func (objMgr *ObjectManager) GetTXTRecord(dnsview string, name string) (*RecordTXT, error) {
if dnsview == "" || name == "" {
return nil, fmt.Errorf("DNS view and name are required to retrieve a unique txt record")
}
var res []RecordTXT
recordTXT := NewEmptyRecordTXT()
sf := map[string]string{
"view": dnsview,
"name": name,
}
queryParams := NewQueryParams(false, sf)
err := objMgr.connector.GetObject(recordTXT, "", queryParams, &res)
if err != nil {
return nil, err
} else if res == nil || len(res) == 0 {
return nil, NewNotFoundError(
fmt.Sprintf(
"TXT record with name '%s' in DNS view '%s' is not found",
name, dnsview))
}
return &res[0], nil
}
func (objMgr *ObjectManager) UpdateTXTRecord(
ref string,
recordName string,
text string,
ttl uint32,
useTtl bool,
comment string,
eas EA) (*RecordTXT, error) {
recordTXT := NewRecordTXT("", "", recordName, text, ttl, useTtl, comment, eas)
recordTXT.Ref = ref
reference, err := objMgr.connector.UpdateObject(recordTXT, ref)
if err != nil {
return nil, err
}
recordTXT, err = objMgr.GetTXTRecordByRef(reference)
return recordTXT, err
}
func (objMgr *ObjectManager) DeleteTXTRecord(ref string) (string, error) {
return objMgr.connector.DeleteObject(ref)
}