-
Notifications
You must be signed in to change notification settings - Fork 1
/
zpa_inspection_profile.go
205 lines (180 loc) · 9.63 KB
/
zpa_inspection_profile.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
package inspection_profile
import (
"fmt"
"net/http"
"strings"
"github.com/zscaler/zscaler-sdk-go/zpa/services/common"
)
const (
mgmtConfig = "/mgmtconfig/v1/admin/customers/"
inspectionProfileEndpoint = "/inspectionProfile"
defaultVersion = "OWASP_CRS/3.3.0"
)
type PatchQuery struct {
Version string `json:"version,omitempty" url:"version,omitempty"`
}
type InspectionProfile struct {
ID string `json:"id,omitempty"`
CommonGlobalOverrideActionsConfig map[string]interface{} `json:"commonGlobalOverrideActionsConfig,omitempty"`
CreationTime string `json:"creationTime,omitempty"`
Description string `json:"description,omitempty"`
GlobalControlActions []string `json:"globalControlActions,omitempty"`
IncarnationNumber string `json:"incarnationNumber,omitempty"`
ModifiedBy string `json:"modifiedBy,omitempty"`
ModifiedTime string `json:"modifiedTime,omitempty"`
Name string `json:"name,omitempty"`
ParanoiaLevel string `json:"paranoiaLevel,omitempty"`
PredefinedControlsVersion string `json:"predefinedControlsVersion,omitempty"`
ControlInfoResource []ControlInfoResource `json:"controlsInfo,omitempty"`
CustomControls []InspectionCustomControl `json:"customControls"`
PredefinedControls []CustomCommonControls `json:"predefinedControls"`
WebSocketControls []CustomCommonControls `json:"websocketControls"`
}
type ControlInfoResource struct {
ControlType string `json:"controlType,omitempty"`
Count string `json:"count,omitempty"`
}
type InspectionCustomControl struct {
Action string `json:"action,omitempty"`
ActionValue string `json:"actionValue,omitempty"`
AssociatedInspectionProfileNames []AssociatedProfileNames `json:"associatedInspectionProfileNames,omitempty"`
Rules []common.Rules `json:"rules,omitempty"`
ControlNumber string `json:"controlNumber,omitempty"`
ControlRuleJson string `json:"controlRuleJson,omitempty"`
CreationTime string `json:"creationTime,omitempty"`
DefaultAction string `json:"defaultAction,omitempty"`
DefaultActionValue string `json:"defaultActionValue,omitempty"`
Description string `json:"description,omitempty"`
ID string `json:"id,omitempty"`
ModifiedBy string `json:"modifiedBy,omitempty"`
ModifiedTime string `json:"modifiedTime,omitempty"`
Name string `json:"name,omitempty"`
ParanoiaLevel string `json:"paranoiaLevel,omitempty"`
Severity string `json:"severity,omitempty"`
Type string `json:"type,omitempty"`
Version string `json:"version,omitempty"`
}
type CustomCommonControls struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Action string `json:"action,omitempty"`
ActionValue string `json:"actionValue,omitempty"`
AssociatedInspectionProfileNames []AssociatedProfileNames `json:"associatedInspectionProfileNames,omitempty"`
Attachment string `json:"attachment,omitempty"`
ControlGroup string `json:"controlGroup,omitempty"`
ControlNumber string `json:"controlNumber,omitempty"`
ControlType string `json:"controlType,omitempty"`
CreationTime string `json:"creationTime,omitempty"`
DefaultAction string `json:"defaultAction,omitempty"`
DefaultActionValue string `json:"defaultActionValue,omitempty"`
Description string `json:"description,omitempty"`
ModifiedBy string `json:"modifiedBy,omitempty"`
ModifiedTime string `json:"modifiedTime,omitempty"`
ParanoiaLevel string `json:"paranoiaLevel,omitempty"`
ProtocolType string `json:"protocolType,omitempty"`
Severity string `json:"severity,omitempty"`
Version string `json:"version,omitempty"`
}
type AssociatedProfileNames struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}
func (service *Service) Get(profileID string) (*InspectionProfile, *http.Response, error) {
v := new(InspectionProfile)
relativeURL := fmt.Sprintf("%s/%s", mgmtConfig+service.Client.Config.CustomerID+inspectionProfileEndpoint, profileID)
resp, err := service.Client.NewRequestDo("GET", relativeURL, nil, nil, &v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
func setVersion(inspectionProfile *InspectionProfile) {
// make sure to set version
if inspectionProfile.PredefinedControlsVersion == "" {
found := false
for _, control := range inspectionProfile.PredefinedControls {
if control.Version != "" {
found = true
inspectionProfile.PredefinedControlsVersion = control.Version
break
}
}
if !found {
inspectionProfile.PredefinedControlsVersion = defaultVersion
}
}
}
func (service *Service) GetByName(profileName string) (*InspectionProfile, *http.Response, error) {
relativeURL := mgmtConfig + service.Client.Config.CustomerID + inspectionProfileEndpoint
list, resp, err := common.GetAllPagesGeneric[InspectionProfile](service.Client, relativeURL, "")
if err != nil {
return nil, nil, err
}
for _, inspection := range list {
if strings.EqualFold(inspection.Name, profileName) {
return &inspection, resp, nil
}
}
return nil, resp, fmt.Errorf("no inspection profile named '%s' was found", profileName)
}
func (service *Service) Create(inspectionProfile InspectionProfile) (*InspectionProfile, *http.Response, error) {
setVersion(&inspectionProfile)
v := new(InspectionProfile)
resp, err := service.Client.NewRequestDo("POST", mgmtConfig+service.Client.Config.CustomerID+inspectionProfileEndpoint, nil, inspectionProfile, &v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
func (service *Service) Update(profileID string, inspectionProfile *InspectionProfile) (*http.Response, error) {
setVersion(inspectionProfile)
relativeURL := fmt.Sprintf("%s/%s", mgmtConfig+service.Client.Config.CustomerID+inspectionProfileEndpoint, profileID)
resp, err := service.Client.NewRequestDo("PUT", relativeURL, nil, inspectionProfile, nil)
if err != nil {
return nil, err
}
return resp, err
}
func (service *Service) PutAssociate(profileID string, inspectionProfile *InspectionProfile) (*http.Response, error) {
setVersion(inspectionProfile)
relativeURL := fmt.Sprintf("%s/%s", mgmtConfig+service.Client.Config.CustomerID+inspectionProfileEndpoint, profileID+"/associateAllPredefinedControls")
resp, err := service.Client.NewRequestDo("PUT", relativeURL, PatchQuery{Version: inspectionProfile.PredefinedControlsVersion}, inspectionProfile, nil)
if err != nil {
return nil, err
}
return resp, err
}
func (service *Service) PutDeassociate(profileID string, inspectionProfile *InspectionProfile) (*http.Response, error) {
setVersion(inspectionProfile)
relativeURL := fmt.Sprintf("%s/%s", mgmtConfig+service.Client.Config.CustomerID+inspectionProfileEndpoint, profileID+"/deAssociateAllPredefinedControls")
resp, err := service.Client.NewRequestDo("PUT", relativeURL, PatchQuery{Version: inspectionProfile.PredefinedControlsVersion}, inspectionProfile, nil)
if err != nil {
return nil, err
}
return resp, err
}
func (service *Service) Patch(profileID string, inspectionProfile *InspectionProfile) (*http.Response, error) {
setVersion(inspectionProfile)
relativeURL := fmt.Sprintf("%s/%s/patch", mgmtConfig+service.Client.Config.CustomerID+inspectionProfileEndpoint, profileID)
resp, err := service.Client.NewRequestDo("PATCH", relativeURL, PatchQuery{Version: inspectionProfile.PredefinedControlsVersion}, inspectionProfile, nil)
if err != nil {
return nil, err
}
return resp, err
}
func (service *Service) Delete(profileID string) (*http.Response, error) {
relativeURL := fmt.Sprintf("%s/%s", mgmtConfig+service.Client.Config.CustomerID+inspectionProfileEndpoint, profileID)
resp, err := service.Client.NewRequestDo("DELETE", relativeURL, nil, nil, nil)
if err != nil {
return nil, err
}
return resp, nil
}
func (service *Service) GetAll() ([]InspectionProfile, *http.Response, error) {
relativeURL := mgmtConfig + service.Client.Config.CustomerID + inspectionProfileEndpoint
list, resp, err := common.GetAllPagesGeneric[InspectionProfile](service.Client, relativeURL, "")
if err != nil {
return nil, nil, err
}
return list, resp, nil
}