forked from pulse-vadc/go-vtm
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config_persistence.go
126 lines (109 loc) · 3.95 KB
/
config_persistence.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
// 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"
)
type Persistence struct {
connector *vtmConnector
PersistenceProperties `json:"properties"`
}
func (vtm VirtualTrafficManager) GetPersistence(name string) (*Persistence, *vtmErrorResponse) {
if name == "" {
panic("Provided an empty \"name\" parameter to VirtualTrafficManager.GetPersistence(name)")
}
conn := vtm.connector.getChildConnector("/tm/5.2/config/active/persistence/" + name)
data, ok := conn.get()
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return nil, object
}
object := new(Persistence)
object.connector = conn
if err := json.NewDecoder(data).Decode(object); err != nil {
panic(err)
}
return object, nil
}
func (object Persistence) Apply() (*Persistence, *vtmErrorResponse) {
marshalled, err := json.Marshal(object)
if err != nil {
panic(err)
}
data, ok := object.connector.put(string(marshalled), STANDARD_OBJ)
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return nil, object
}
if err := json.NewDecoder(data).Decode(&object); err != nil {
panic(err)
}
return &object, nil
}
func (vtm VirtualTrafficManager) NewPersistence(name string) *Persistence {
object := new(Persistence)
conn := vtm.connector.getChildConnector("/tm/5.2/config/active/persistence/" + name)
object.connector = conn
return object
}
func (vtm VirtualTrafficManager) DeletePersistence(name string) *vtmErrorResponse {
conn := vtm.connector.getChildConnector("/tm/5.2/config/active/persistence/" + name)
data, ok := conn.delete()
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return object
}
return nil
}
func (vtm VirtualTrafficManager) ListPersistences() (*[]string, *vtmErrorResponse) {
conn := vtm.connector.getChildConnector("/tm/5.2/config/active/persistence")
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
}
type PersistenceProperties struct {
Basic struct {
// The cookie name to use for tracking session persistence.
Cookie *string `json:"cookie,omitempty"`
// Whether or not the session should be deleted when a session failure
// occurs. (Note, setting a failure mode of 'choose a new node'
// implicitly deletes the session.)
Delete *bool `json:"delete,omitempty"`
// The action the pool should take if the session data is invalid
// or it cannot contact the node specified by the session.
FailureMode *string `json:"failure_mode,omitempty"`
// A description of the session persistence class.
Note *string `json:"note,omitempty"`
// When using IP-based session persistence, ensure all requests
// from this IPv4 subnet, specified as a prefix length, are sent
// to the same node. If set to 0, requests from different IPv4 addresses
// will be load-balanced individually.
SubnetPrefixLengthV4 *int `json:"subnet_prefix_length_v4,omitempty"`
// When using IP-based session persistence, ensure all requests
// from this IPv6 subnet, specified as a prefix length, are sent
// to the same node. If set to 0, requests from different IPv6 addresses
// will be load-balanced individually.
SubnetPrefixLengthV6 *int `json:"subnet_prefix_length_v6,omitempty"`
// The type of session persistence to use.
Type *string `json:"type,omitempty"`
// The redirect URL to send clients to if the session persistence
// is configured to redirect users when a node dies.
Url *string `json:"url,omitempty"`
} `json:"basic"`
}