forked from pulse-vadc/go-vtm
/
config_cloud_api_credential.go
120 lines (104 loc) · 3.76 KB
/
config_cloud_api_credential.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
// 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 6.0.
package vtm
import (
"encoding/json"
)
type CloudApiCredential struct {
connector *vtmConnector
CloudApiCredentialProperties `json:"properties"`
}
func (vtm VirtualTrafficManager) GetCloudApiCredential(name string) (*CloudApiCredential, *vtmErrorResponse) {
if name == "" {
panic("Provided an empty \"name\" parameter to VirtualTrafficManager.GetCloudApiCredential(name)")
}
conn := vtm.connector.getChildConnector("/tm/6.0/config/active/cloud_api_credentials/" + name)
data, ok := conn.get()
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return nil, object
}
object := new(CloudApiCredential)
object.connector = conn
if err := json.NewDecoder(data).Decode(object); err != nil {
panic(err)
}
return object, nil
}
func (object CloudApiCredential) Apply() (*CloudApiCredential, *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) NewCloudApiCredential(name string) *CloudApiCredential {
object := new(CloudApiCredential)
conn := vtm.connector.getChildConnector("/tm/6.0/config/active/cloud_api_credentials/" + name)
object.connector = conn
return object
}
func (vtm VirtualTrafficManager) DeleteCloudApiCredential(name string) *vtmErrorResponse {
conn := vtm.connector.getChildConnector("/tm/6.0/config/active/cloud_api_credentials/" + name)
data, ok := conn.delete()
if ok != true {
object := new(vtmErrorResponse)
json.NewDecoder(data).Decode(object)
return object
}
return nil
}
func (vtm VirtualTrafficManager) ListCloudApiCredentials() (*[]string, *vtmErrorResponse) {
conn := vtm.connector.getChildConnector("/tm/6.0/config/active/cloud_api_credentials")
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 CloudApiCredentialProperties struct {
Basic struct {
// The vCenter server hostname or IP address.
ApiServer *string `json:"api_server,omitempty"`
// The traffic manager creates and destroys nodes via API calls.
// This setting specifies (in seconds) how long to wait for such
// calls to complete.
CloudApiTimeout *int `json:"cloud_api_timeout,omitempty"`
// The first part of the credentials for the cloud user. Typically
// this is some variation on the username concept.
Cred1 *string `json:"cred1,omitempty"`
// The second part of the credentials for the cloud user. Typically
// this is some variation on the password concept.
Cred2 *string `json:"cred2,omitempty"`
// The third part of the credentials for the cloud user. Typically
// this is some variation on the authentication token concept.
Cred3 *string `json:"cred3,omitempty"`
// The script to call for communication with the cloud API.
Script *string `json:"script,omitempty"`
// The traffic manager will periodically check the status of the
// cloud through an API call. This setting specifies the interval
// between such updates.
UpdateInterval *int `json:"update_interval,omitempty"`
} `json:"basic"`
}