forked from pulse-vadc/go-vtm
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config_rule.go
69 lines (63 loc) · 1.9 KB
/
config_rule.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
// Copyright (C) 2018-2019, Pulse Secure, LLC.
// Licensed under the terms of the MPL 2.0. See LICENSE file for details.
// Go library for Pulse Virtual Traffic Manager REST version 5.2.
package vtm
import (
"encoding/json"
"io/ioutil"
)
func (vtm VirtualTrafficManager) ListRules() (*[]string, *vtmErrorResponse) {
conn := vtm.connector.getChildConnector("/tm/5.2/config/active/rules")
data, ok := conn.get()
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return nil, object
}
objectList := new(vtmObjectChildren)
if err := json.NewDecoder(data).Decode(objectList); err != nil {
panic(err)
}
var stringList []string
for _, obj := range objectList.Children {
stringList = append(stringList, obj.Name)
}
return &stringList, nil
}
func (vtm VirtualTrafficManager) GetRule(name string) (string, *vtmErrorResponse) {
if name == "" {
panic("Provided an empty \"name\" parameter to VirtualTrafficManager.GetRule(name)")
}
conn := vtm.connector.getChildConnector("/tm/5.2/config/active/rules/" + name)
data, ok := conn.get()
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return "", object
}
bodyText, err := ioutil.ReadAll(data)
if err != nil {
panic(err)
}
return string(bodyText), nil
}
func (vtm VirtualTrafficManager) SetRule(name, content string) *vtmErrorResponse {
conn := vtm.connector.getChildConnector("/tm/5.2/config/active/rules/" + name)
data, ok := conn.put(content, TEXT_ONLY_OBJ)
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return object
}
return nil
}
func (vtm VirtualTrafficManager) DeleteRule(name string) *vtmErrorResponse {
conn := vtm.connector.getChildConnector("/tm/5.2/config/active/rules/" + name)
data, ok := conn.delete()
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return object
}
return nil
}