-
Notifications
You must be signed in to change notification settings - Fork 1
/
zpa_inspection_custom_controls.go
134 lines (115 loc) · 5.12 KB
/
zpa_inspection_custom_controls.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
package inspection_custom_controls
import (
"encoding/json"
"fmt"
"net/http"
"strings"
"github.com/zscaler/zscaler-sdk-go/zpa/services/common"
)
const (
mgmtConfig = "/mgmtconfig/v1/admin/customers/"
customControlsEndpoint = "/inspectionControls/custom"
)
type InspectionCustomControl struct {
ID string `json:"id,omitempty"`
Action string `json:"action,omitempty"`
ActionValue string `json:"actionValue,omitempty"`
AssociatedInspectionProfileNames []AssociatedProfileNames `json:"associatedInspectionProfileNames,omitempty"`
Rules []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"`
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 Rules struct {
Conditions []Conditions `json:"conditions,omitempty"`
Names []string `json:"names,omitempty"`
Type string `json:"type,omitempty"`
}
type Conditions struct {
LHS string `json:"lhs,omitempty"`
OP string `json:"op,omitempty"`
RHS string `json:"rhs,omitempty"`
}
type AssociatedProfileNames struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
}
func unmarshalRulesJson(rulesJsonStr string) ([]Rules, error) {
var rules []Rules
err := json.Unmarshal([]byte(rulesJsonStr), &rules)
return rules, err
}
func (service *Service) Get(customID string) (*InspectionCustomControl, *http.Response, error) {
v := new(InspectionCustomControl)
relativeURL := fmt.Sprintf("%s/%s", mgmtConfig+service.Client.Config.CustomerID+customControlsEndpoint, customID)
resp, err := service.Client.NewRequestDo("GET", relativeURL, nil, nil, &v)
if err != nil {
return nil, nil, err
}
rules, err := unmarshalRulesJson(v.ControlRuleJson)
v.Rules = rules
return v, resp, err
}
func (service *Service) GetByName(controlName string) (*InspectionCustomControl, *http.Response, error) {
var v struct {
List []InspectionCustomControl `json:"list"`
}
relativeURL := mgmtConfig + service.Client.Config.CustomerID + customControlsEndpoint
resp, err := service.Client.NewRequestDo("GET", relativeURL, common.Pagination{PageSize: common.DefaultPageSize, Search: controlName}, nil, &v)
if err != nil {
return nil, nil, err
}
for _, control := range v.List {
if strings.EqualFold(control.Name, controlName) {
rules, err := unmarshalRulesJson(control.ControlRuleJson)
control.Rules = rules
return &control, resp, err
}
}
return nil, resp, fmt.Errorf("no custom inspection control named '%s' was found", controlName)
}
func (service *Service) Create(customControls InspectionCustomControl) (*InspectionCustomControl, *http.Response, error) {
v := new(InspectionCustomControl)
resp, err := service.Client.NewRequestDo("POST", mgmtConfig+service.Client.Config.CustomerID+customControlsEndpoint, nil, customControls, &v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
func (service *Service) Update(customID string, customControls *InspectionCustomControl) (*http.Response, error) {
relativeURL := fmt.Sprintf("%s/%s", mgmtConfig+service.Client.Config.CustomerID+customControlsEndpoint, customID)
resp, err := service.Client.NewRequestDo("PUT", relativeURL, nil, customControls, nil)
if err != nil {
return nil, err
}
return resp, err
}
func (service *Service) Delete(customID string) (*http.Response, error) {
relativeURL := fmt.Sprintf("%s/%s", mgmtConfig+service.Client.Config.CustomerID+customControlsEndpoint, customID)
resp, err := service.Client.NewRequestDo("DELETE", relativeURL, nil, nil, nil)
if err != nil {
return nil, err
}
return resp, nil
}
func (service *Service) GetAll() ([]InspectionCustomControl, *http.Response, error) {
var v struct {
List []InspectionCustomControl `json:"list"`
}
relativeURL := mgmtConfig + service.Client.Config.CustomerID + customControlsEndpoint
resp, err := service.Client.NewRequestDo("GET", relativeURL, common.Pagination{PageSize: common.DefaultPageSize}, nil, &v)
if err != nil {
return nil, nil, err
}
return v.List, resp, nil
}