-
Notifications
You must be signed in to change notification settings - Fork 1
/
zpa_server_group.go
177 lines (162 loc) · 8.26 KB
/
zpa_server_group.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
package servergroup
import (
"fmt"
"net/http"
"strings"
"github.com/zscaler/zscaler-sdk-go/zpa/services/common"
)
const (
mgmtConfig = "/mgmtconfig/v1/admin/customers/"
serverGroupEndpoint = "/serverGroup"
)
type ServerGroup struct {
ID string `json:"id,omitempty"`
Enabled bool `json:"enabled"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
IpAnchored bool `json:"ipAnchored"`
ConfigSpace string `json:"configSpace,omitempty"`
DynamicDiscovery bool `json:"dynamicDiscovery"`
CreationTime string `json:"creationTime,omitempty"`
ModifiedBy string `json:"modifiedBy,omitempty"`
ModifiedTime string `json:"modifiedTime,omitempty"`
AppConnectorGroups []AppConnectorGroups `json:"appConnectorGroups"`
Servers []ApplicationServer `json:"servers"`
Applications []Applications `json:"applications"`
}
type Applications struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}
type AppConnectorGroups struct {
Citycountry string `json:"cityCountry,omitempty"`
CountryCode string `json:"countryCode,omitempty"`
CreationTime string `json:"creationTime,omitempty"`
Description string `json:"description,omitempty"`
DnsqueryType string `json:"dnsQueryType,omitempty"`
Enabled bool `json:"enabled"`
GeolocationID string `json:"geoLocationId,omitempty"`
ID string `json:"id,omitempty"`
Latitude string `json:"latitude,omitempty"`
Location string `json:"location,omitempty"`
Longitude string `json:"longitude,omitempty"`
ModifiedBy string `json:"modifiedBy,omitempty"`
ModifiedTime string `json:"modifiedTime,omitempty"`
Name string `json:"name"`
SiemAppconnectorGroup bool `json:"siemAppConnectorGroup"`
UpgradeDay string `json:"upgradeDay,omitempty"`
UpgradeTimeinSecs string `json:"upgradeTimeInSecs,omitempty"`
VersionProfileID string `json:"versionProfileId,omitempty"`
AppServerGroups []AppServerGroups `json:"serverGroups,omitempty"`
Connectors []Connectors `json:"connectors,omitempty"`
}
type Connectors struct {
ApplicationStartTime string `json:"applicationStartTime,omitempty"`
AppConnectorGroupID string `json:"appConnectorGroupId,omitempty"`
AppConnectorGroupName string `json:"appConnectorGroupName,omitempty"`
ControlChannelStatus string `json:"controlChannelStatus,omitempty"`
CreationTime string `json:"creationTime,omitempty"`
CtrlBrokerName string `json:"ctrlBrokerName,omitempty"`
CurrentVersion string `json:"currentVersion,omitempty"`
Description string `json:"description,omitempty"`
Enabled bool `json:"enabled"`
ExpectedUpgradeTime string `json:"expectedUpgradeTime,omitempty"`
ExpectedVersion string `json:"expectedVersion,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
ID string `json:"id,omitempty"`
IPACL []string `json:"ipAcl,omitempty"`
IssuedCertID string `json:"issuedCertId,omitempty"`
LastBrokerConnecttime string `json:"lastBrokerConnectTime,omitempty"`
LastBrokerDisconnectTime string `json:"lastBrokerDisconnectTime,omitempty"`
LastUpgradeTime string `json:"lastUpgradeTime,omitempty"`
Latitude float64 `json:"latitude,omitempty"`
Location string `json:"location,omitempty"`
Longitude float64 `json:"longitude,string,omitempty"`
ModifiedBy string `json:"modifiedBy,omitempty"`
ModifiedTime string `json:"modifiedTime,omitempty"`
Name string `json:"name"`
Platform string `json:"platform,omitempty"`
PreviousVersion string `json:"previousVersion,omitempty"`
PrivateIP string `json:"privateIp,omitempty"`
PublicIP string `json:"publicIp,omitempty"`
SigningCert map[string]interface{} `json:"signingCert,omitempty"`
UpgradeAttempt string `json:"upgradeAttempt,omitempty"`
UpgradeStatus string `json:"upgradeStatus,omitempty"`
}
type AppServerGroups struct {
ConfigSpace string `json:"configSpace,omitempty"`
CreationTime string `json:"creationTime,omitempty"`
Description string `json:"description,omitempty"`
Enabled bool `json:"enabled"`
ID string `json:"id,omitempty"`
DynamicDiscovery bool `json:"dynamicDiscovery"`
ModifiedBy string `json:"modifiedBy,omitempty"`
ModifiedTime string `json:"modifiedTime,omitempty"`
Name string `json:"name"`
}
type ApplicationServer struct {
Address string `json:"address,omitempty"`
AppServerGroupIds []string `json:"appServerGroupIds,omitempty"`
ConfigSpace string `json:"configSpace,omitempty"`
CreationTime string `json:"creationTime,omitempty"`
Description string `json:"description,omitempty"`
Enabled bool `json:"enabled"`
ID string `json:"id,omitempty"`
ModifiedBy string `json:"modifiedBy,omitempty"`
ModifiedTime string `json:"modifiedTime,omitempty"`
Name string `json:"name"`
}
func (service *Service) Get(groupID string) (*ServerGroup, *http.Response, error) {
v := new(ServerGroup)
relativeURL := fmt.Sprintf("%s/%s", mgmtConfig+service.Client.Config.CustomerID+serverGroupEndpoint, groupID)
resp, err := service.Client.NewRequestDo("GET", relativeURL, nil, nil, v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
func (service *Service) GetByName(serverGroupName string) (*ServerGroup, *http.Response, error) {
relativeURL := mgmtConfig + service.Client.Config.CustomerID + serverGroupEndpoint
list, resp, err := common.GetAllPagesGeneric[ServerGroup](service.Client, relativeURL, "")
if err != nil {
return nil, nil, err
}
for _, app := range list {
if strings.EqualFold(app.Name, serverGroupName) {
return &app, resp, nil
}
}
return nil, resp, fmt.Errorf("no server group named '%s' was found", serverGroupName)
}
func (service *Service) Create(serverGroup *ServerGroup) (*ServerGroup, *http.Response, error) {
v := new(ServerGroup)
resp, err := service.Client.NewRequestDo("POST", mgmtConfig+service.Client.Config.CustomerID+serverGroupEndpoint, nil, serverGroup, &v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
func (service *Service) Update(groupId string, serverGroup *ServerGroup) (*http.Response, error) {
path := fmt.Sprintf("%s/%s", mgmtConfig+service.Client.Config.CustomerID+serverGroupEndpoint, groupId)
resp, err := service.Client.NewRequestDo("PUT", path, nil, serverGroup, nil)
if err != nil {
return nil, err
}
return resp, err
}
func (service *Service) Delete(groupId string) (*http.Response, error) {
path := fmt.Sprintf("%s/%s", mgmtConfig+service.Client.Config.CustomerID+serverGroupEndpoint, groupId)
resp, err := service.Client.NewRequestDo("DELETE", path, nil, nil, nil)
if err != nil {
return nil, err
}
return resp, err
}
func (service *Service) GetAll() ([]ServerGroup, *http.Response, error) {
relativeURL := mgmtConfig + service.Client.Config.CustomerID + serverGroupEndpoint
list, resp, err := common.GetAllPagesGeneric[ServerGroup](service.Client, relativeURL, "")
if err != nil {
return nil, nil, err
}
return list, resp, nil
}