-
Notifications
You must be signed in to change notification settings - Fork 1
/
locationgroups.go
177 lines (136 loc) · 6.04 KB
/
locationgroups.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 locationgroups
import (
"errors"
"fmt"
"net/http"
"net/url"
"strings"
"github.com/zscaler/zscaler-sdk-go/zia/services/common"
)
const (
locationGroupEndpoint = "/locations/groups"
)
type LocationGroup struct {
// Unique identifier for the location group
ID int `json:"id,omitempty"`
// Location group name
Name string `json:"name,omitempty"`
// Indicates the location group was deleted
Deleted bool `json:"deleted,omitempty"`
// The location group's type (i.e., Static or Dynamic)
GroupType string `json:"groupType,omitempty"`
// A dynamic location group's criteria. This is ignored if the groupType is Static.
DynamicLocationGroupCriteria *DynamicLocationGroupCriteria `json:"dynamicLocationGroupCriteria,omitempty"`
// Additional information about the location group
Comments string `json:"comments"`
// The Name-ID pairs of the locations that are assigned to the static location group. This is ignored if the groupType is Dynamic.
Locations []common.IDNameExtensions `json:"locations"`
// Automatically populated with the current ZIA admin user, after a successful POST or PUT request.
LastModUser *LastModUser `json:"lastModUser"`
// Automatically populated with the current time, after a successful POST or PUT request.
LastModTime int `json:"lastModTime"`
Predefined bool `json:"predefined"`
}
type DynamicLocationGroupCriteria struct {
// A sub-string to match location name. Valid operators are contains, starts with, and ends with",
Name *Name `json:"name,omitempty"`
// One or more countries from a predefined set
Countries []string `json:"countries,omitempty"`
// A sub-string to match city. Valid operators are starts with, ends with, contains, and exact match operators.
City *City `json:"city,omitempty"`
// One or more values from a predefined set of SD-WAN partner list to display partner names.
ManagedBy []ManagedBy `json:"managedBy,omitempty"`
// Enforce Authentication. Required when ports are enabled, IP Surrogate is enabled, or Kerberos Authentication is enabled.
EnforceAuthentication bool `json:"enforceAuthentication"`
// Enable AUP. When set to true, AUP is enabled for the location.
EnforceAup bool `json:"enforceAup"`
// Enable Firewall. When set to true, Firewall is enabled for the location.
EnforceFirewallControl bool `json:"enforceFirewallControl"`
// Enable XFF Forwarding. When set to true, traffic is passed to Zscaler Cloud via the X-Forwarded-For (XFF) header.
EnableXffForwarding bool `json:"enableXffForwarding"`
// Enable Caution. When set to true, a caution notifcation is enabled for the location.
EnableCaution bool `json:"enableCaution"`
// Enable Bandwidth Control. When set to true, Bandwidth Control is enabled for the location.
EnableBandwidthControl bool `json:"enableBandwidthControl"`
// One or more location profiles from a predefined set
Profiles []string `json:"profiles"`
}
type Name struct {
// String value to be matched or partially matched
MatchString string `json:"matchString,omitempty"`
// Operator that performs match action
MatchType string `json:"matchType,omitempty"`
}
type City struct {
// String value to be matched or partially matched
MatchString string `json:"matchString,omitempty"`
// Operator that performs match action
MatchType string `json:"matchType,omitempty"`
}
type LastModUser struct {
// Identifier that uniquely identifies an entity
ID int `json:"id,omitempty"`
// The configured name of the entity
Name string `json:"name,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}
type ManagedBy struct {
ID int `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}
func (service *Service) GetLocationGroup(groupID int) (*LocationGroup, error) {
var locationGroup LocationGroup
err := service.Client.Read(fmt.Sprintf("%s/%d", locationGroupEndpoint, groupID), &locationGroup)
if err != nil {
return nil, err
}
service.Client.Logger.Printf("[DEBUG]returning location group from Get: %d", locationGroup.ID)
return &locationGroup, nil
}
func (service *Service) GetLocationGroupByName(locationGroupName string) (*LocationGroup, error) {
var locationGroups []LocationGroup
err := common.ReadAllPages(service.Client, fmt.Sprintf("%s?name=%s", locationGroupEndpoint, url.QueryEscape(locationGroupName)), &locationGroups)
if err != nil {
return nil, err
}
for _, locationGroup := range locationGroups {
if strings.EqualFold(locationGroup.Name, locationGroupName) {
return &locationGroup, nil
}
}
return nil, fmt.Errorf("no location group found with name: %s", locationGroupName)
}
func (service *Service) CreateLocationGroup(locationGroups *LocationGroup) (*LocationGroup, error) {
resp, err := service.Client.Create(locationGroupEndpoint, *locationGroups)
if err != nil {
return nil, err
}
createdLocationGroup, ok := resp.(*LocationGroup)
if !ok {
return nil, errors.New("object returned from api was not a location group pointer")
}
service.Client.Logger.Printf("[DEBUG]returning location group from create: %d", createdLocationGroup.ID)
return createdLocationGroup, nil
}
func (service *Service) UpdateLocationGroup(groupID int, locationGroups *LocationGroup) (*LocationGroup, *http.Response, error) {
resp, err := service.Client.UpdateWithPut(fmt.Sprintf("%s/%d", locationGroupEndpoint, groupID), *locationGroups)
if err != nil {
return nil, nil, err
}
updatedLocationGroup, _ := resp.(*LocationGroup)
service.Client.Logger.Printf("[DEBUG]returning location group from update: %d", updatedLocationGroup.ID)
return updatedLocationGroup, nil, nil
}
func (service *Service) DeleteLocationGroup(groupID int) (*http.Response, error) {
err := service.Client.Delete(fmt.Sprintf("%s/%d", locationGroupEndpoint, groupID))
if err != nil {
return nil, err
}
return nil, nil
}
func (service *Service) GetAll() ([]LocationGroup, error) {
var locationGroups []LocationGroup
err := common.ReadAllPages(service.Client, locationGroupEndpoint, &locationGroups)
return locationGroups, err
}