-
Notifications
You must be signed in to change notification settings - Fork 1
/
zpa_inspection_predefined-controls.go
108 lines (98 loc) · 4.6 KB
/
zpa_inspection_predefined-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
package inspection_predefined_controls
import (
"fmt"
"log"
"net/http"
"strings"
"github.com/zscaler/zscaler-sdk-go/zpa/services/common"
)
const (
mgmtConfig = "/mgmtconfig/v1/admin/customers/"
predControlsEndpoint = "/inspectionControls/predefined"
)
type PredefinedControls struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Action string `json:"action,omitempty"`
ActionValue string `json:"actionValue,omitempty"`
AssociatedInspectionProfileNames []common.AssociatedProfileNames `json:"associatedInspectionProfileNames,omitempty"`
Attachment string `json:"attachment,omitempty"`
ControlGroup string `json:"controlGroup,omitempty"`
ControlNumber string `json:"controlNumber,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"`
Severity string `json:"severity,omitempty"`
Version string `json:"version,omitempty"`
}
type ControlGroupItem struct {
ControlGroup string `json:"controlGroup,omitempty"`
PredefinedInspectionControls []PredefinedControls `json:"predefinedInspectionControls,omitempty"`
DefaultGroup bool `json:"defaultGroup,omitempty"`
}
// Get Predefined Controls by ID
// https://help.zscaler.com/zpa/api-reference#/inspection-control-controller/getPredefinedControlById
func (service *Service) Get(controlID string) (*PredefinedControls, *http.Response, error) {
v := new(PredefinedControls)
relativeURL := fmt.Sprintf("%s/%s", mgmtConfig+service.Client.Config.CustomerID+predControlsEndpoint, controlID)
resp, err := service.Client.NewRequestDo("GET", relativeURL, nil, nil, &v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
func (service *Service) GetAll(version string) ([]PredefinedControls, error) {
v := []ControlGroupItem{}
relativeURL := fmt.Sprintf(mgmtConfig + service.Client.Config.CustomerID + predControlsEndpoint)
_, err := service.Client.NewRequestDo("GET", relativeURL, struct {
Version string `url:"version"`
}{Version: version}, nil, &v)
if err != nil {
return nil, err
}
predefinedControls := []PredefinedControls{}
for _, group := range v {
predefinedControls = append(predefinedControls, group.PredefinedInspectionControls...)
}
return predefinedControls, nil
}
func (service *Service) GetByName(name, version string) (*PredefinedControls, *http.Response, error) {
v := []ControlGroupItem{}
relativeURL := fmt.Sprintf(mgmtConfig + service.Client.Config.CustomerID + predControlsEndpoint)
resp, err := service.Client.NewRequestDo("GET", relativeURL, struct {
Version string `url:"version"`
}{Version: version}, nil, &v)
if err != nil {
return nil, nil, err
}
for _, group := range v {
for _, control := range group.PredefinedInspectionControls {
if strings.EqualFold(control.Name, name) {
log.Printf("[INFO] got predefined controls:%#v", v)
return &control, resp, nil
}
}
}
log.Printf("[ERROR] no predefined control named '%s' found", name)
return nil, resp, fmt.Errorf("no predefined control named '%s' found", name)
}
func (service *Service) GetAllByGroup(version, groupName string) ([]PredefinedControls, error) {
v := []ControlGroupItem{}
relativeURL := fmt.Sprintf(mgmtConfig + service.Client.Config.CustomerID + predControlsEndpoint)
_, err := service.Client.NewRequestDo("GET", relativeURL, struct {
Version string `url:"version"`
}{Version: version}, nil, &v)
if err != nil {
return nil, err
}
for _, group := range v {
if strings.EqualFold(group.ControlGroup, groupName) {
return group.PredefinedInspectionControls, nil
}
}
return []PredefinedControls{}, nil
}