-
Notifications
You must be signed in to change notification settings - Fork 1
/
zpa_gateways.go
141 lines (111 loc) · 4.38 KB
/
zpa_gateways.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
package zpa_gateways
import (
"errors"
"fmt"
"net/http"
"strings"
"github.com/zscaler/zscaler-sdk-go/v2/zia/services/common"
)
const (
zpaGatewaysEndpoint = "/zpaGateways"
)
type ZPAGateways struct {
// A unique identifier assigned to the ZPA gateway
ID int `json:"id"`
// The name of the ZPA gateway
Name string `json:"name,omitempty"`
// Additional details about the ZPA gateway
Description string `json:"description,omitempty"`
// The ZPA Server Group that is configured for Source IP Anchoring
ZPAServerGroup ZPAServerGroup `json:"zpaServerGroup,omitempty"`
// All the Application Segments that are associated with the selected ZPA Server Group for which Source IP Anchoring is enabled
ZPAAppSegments []ZPAAppSegments `json:"zpaAppSegments,omitempty"`
// The ID of the ZPA tenant where Source IP Anchoring is configured
ZPATenantId int `json:"zpaTenantId,omitempty"`
// Information about the admin user that last modified the ZPA gateway
LastModifiedBy *common.IDNameExtensions `json:"lastModifiedBy,omitempty"`
// Timestamp when the ZPA gateway was last modified
LastModifiedTime int `json:"lastModifiedTime,omitempty"`
// Indicates whether the ZPA gateway is configured for Zscaler Internet Access (using option ZPA) or Zscaler Cloud Connector (using option ECZPA)
// Supported Values: "ZPA", "ECZPA"
Type string `json:"type"`
}
// The ZPA Server Group that is configured for Source IP Anchoring
type ZPAServerGroup struct {
// Identifier that uniquely identifies an entity
ID int `json:"id,omitempty"`
// The name of the Application Segment
Name string `json:"name,omitempty"`
// An external identifier used for an entity that is managed outside of ZIA.
// Examples include zpaServerGroup and zpaAppSegments.
// This field is not applicable to ZIA-managed entities.
ExternalID string `json:"externalId,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}
// All the Application Segments that are associated with the selected ZPA Server Group for which Source IP Anchoring is enabled
type ZPAAppSegments struct {
// Identifier that uniquely identifies an entity
ID int `json:"id,omitempty"`
// The name of the Application Segment
Name string `json:"name,omitempty"`
// An external identifier used for an entity that is managed outside of ZIA.
// Examples include zpaServerGroup and zpaAppSegments.
// This field is not applicable to ZIA-managed entities.
ExternalID string `json:"externalId,omitempty"`
Extensions map[string]interface{} `json:"extensions,omitempty"`
}
func (service *Service) Get(ruleID int) (*ZPAGateways, error) {
var rule ZPAGateways
err := service.Client.Read(fmt.Sprintf("%s/%d", zpaGatewaysEndpoint, ruleID), &rule)
if err != nil {
return nil, err
}
service.Client.Logger.Printf("[DEBUG]Returning zpa gateway from Get: %d", rule.ID)
return &rule, nil
}
func (service *Service) GetByName(ruleName string) (*ZPAGateways, error) {
var rules []ZPAGateways
err := common.ReadAllPages(service.Client, zpaGatewaysEndpoint, &rules)
if err != nil {
return nil, err
}
for _, rule := range rules {
if strings.EqualFold(rule.Name, ruleName) {
return &rule, nil
}
}
return nil, fmt.Errorf("no zpa gateway found with name: %s", ruleName)
}
func (service *Service) Create(rule *ZPAGateways) (*ZPAGateways, error) {
resp, err := service.Client.Create(zpaGatewaysEndpoint, *rule)
if err != nil {
return nil, err
}
createdRules, ok := resp.(*ZPAGateways)
if !ok {
return nil, errors.New("object returned from api was not a rule Pointer")
}
service.Client.Logger.Printf("[DEBUG]returning zpa gateway from create: %d", createdRules.ID)
return createdRules, nil
}
func (service *Service) Update(ruleID int, rules *ZPAGateways) (*ZPAGateways, error) {
resp, err := service.Client.UpdateWithPut(fmt.Sprintf("%s/%d", zpaGatewaysEndpoint, ruleID), *rules)
if err != nil {
return nil, err
}
updatedRules, _ := resp.(*ZPAGateways)
service.Client.Logger.Printf("[DEBUG]returning zpa gateway from update: %d", updatedRules.ID)
return updatedRules, nil
}
func (service *Service) Delete(ruleID int) (*http.Response, error) {
err := service.Client.Delete(fmt.Sprintf("%s/%d", zpaGatewaysEndpoint, ruleID))
if err != nil {
return nil, err
}
return nil, nil
}
func (service *Service) GetAll() ([]ZPAGateways, error) {
var rules []ZPAGateways
err := common.ReadAllPages(service.Client, zpaGatewaysEndpoint, &rules)
return rules, err
}