-
Notifications
You must be signed in to change notification settings - Fork 1
/
zpa_segment_group.go
128 lines (116 loc) · 5.61 KB
/
zpa_segment_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
package segmentgroup
import (
"fmt"
"net/http"
"strings"
"github.com/zscaler/zscaler-sdk-go/v2/zpa/services/common"
)
const (
mgmtConfig = "/mgmtconfig/v1/admin/customers/"
segmentGroupEndpoint = "/segmentGroup"
)
type SegmentGroup struct {
Applications []Application `json:"applications"`
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"`
PolicyMigrated bool `json:"policyMigrated"`
TcpKeepAliveEnabled string `json:"tcpKeepAliveEnabled,omitempty"`
MicroTenantID string `json:"microtenantId,omitempty"`
MicroTenantName string `json:"microtenantName,omitempty"`
}
type Application struct {
BypassType string `json:"bypassType,omitempty"`
ConfigSpace string `json:"configSpace,omitempty"`
CreationTime string `json:"creationTime,omitempty"`
DefaultIdleTimeout string `json:"defaultIdleTimeout,omitempty"`
DefaultMaxAge string `json:"defaultMaxAge,omitempty"`
Description string `json:"description,omitempty"`
DomainName string `json:"domainName,omitempty"`
DomainNames []string `json:"domainNames,omitempty"`
DoubleEncrypt bool `json:"doubleEncrypt"`
Enabled bool `json:"enabled"`
HealthCheckType string `json:"healthCheckType,omitempty"`
ID string `json:"id,omitempty"`
IPAnchored bool `json:"ipAnchored"`
LogFeatures []string `json:"logFeatures,omitempty"`
ModifiedBy string `json:"modifiedBy,omitempty"`
ModifiedTime string `json:"modifiedTime,omitempty"`
Name string `json:"name"`
PassiveHealthEnabled bool `json:"passiveHealthEnabled"`
ServerGroup []AppServerGroup `json:"serverGroups,omitempty"`
TCPPortRanges interface{} `json:"tcpPortRanges,omitempty"`
TCPPortsIn interface{} `json:"tcpPortsIn,omitempty"`
TCPPortsOut interface{} `json:"tcpPortsOut,omitempty"`
UDPPortRanges interface{} `json:"udpPortRangesg,omitempty"`
}
type AppServerGroup 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"`
}
func (service *Service) Get(segmentGroupID string) (*SegmentGroup, *http.Response, error) {
v := new(SegmentGroup)
relativeURL := fmt.Sprintf("%s/%s", mgmtConfig+service.Client.Config.CustomerID+segmentGroupEndpoint, segmentGroupID)
resp, err := service.Client.NewRequestDo("GET", relativeURL, common.Filter{MicroTenantID: service.microTenantID}, nil, v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
func (service *Service) GetByName(segmentName string) (*SegmentGroup, *http.Response, error) {
relativeURL := mgmtConfig + service.Client.Config.CustomerID + segmentGroupEndpoint
list, resp, err := common.GetAllPagesGenericWithCustomFilters[SegmentGroup](service.Client, relativeURL, common.Filter{Search: segmentName, MicroTenantID: service.microTenantID})
if err != nil {
return nil, nil, err
}
for _, app := range list {
if strings.EqualFold(app.Name, segmentName) {
return &app, resp, nil
}
}
return nil, resp, fmt.Errorf("no application named '%s' was found", segmentName)
}
func (service *Service) Create(segmentGroup *SegmentGroup) (*SegmentGroup, *http.Response, error) {
v := new(SegmentGroup)
resp, err := service.Client.NewRequestDo("POST", mgmtConfig+service.Client.Config.CustomerID+segmentGroupEndpoint, common.Filter{MicroTenantID: service.microTenantID}, segmentGroup, &v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
func (service *Service) Update(segmentGroupId string, segmentGroupRequest *SegmentGroup) (*http.Response, error) {
path := fmt.Sprintf("%v/%v", mgmtConfig+service.Client.Config.CustomerID+segmentGroupEndpoint, segmentGroupId)
resp, err := service.Client.NewRequestDo("PUT", path, common.Filter{MicroTenantID: service.microTenantID}, segmentGroupRequest, nil)
if err != nil {
return nil, err
}
return resp, err
}
func (service *Service) Delete(segmentGroupId string) (*http.Response, error) {
path := fmt.Sprintf("%v/%v", mgmtConfig+service.Client.Config.CustomerID+segmentGroupEndpoint, segmentGroupId)
resp, err := service.Client.NewRequestDo("DELETE", path, common.Filter{MicroTenantID: service.microTenantID}, nil, nil)
if err != nil {
return nil, err
}
return resp, err
}
func (service *Service) GetAll() ([]SegmentGroup, *http.Response, error) {
relativeURL := mgmtConfig + service.Client.Config.CustomerID + segmentGroupEndpoint
list, resp, err := common.GetAllPagesGenericWithCustomFilters[SegmentGroup](service.Client, relativeURL, common.Filter{MicroTenantID: service.microTenantID})
if err != nil {
return nil, nil, err
}
return list, resp, nil
}