-
Notifications
You must be signed in to change notification settings - Fork 0
/
zpa_posture_profile.go
91 lines (78 loc) · 3.53 KB
/
zpa_posture_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
package postureprofile
import (
"fmt"
"net/http"
"strings"
"github.com/SecurityGeekIO/zscaler-sdk-go/v2/zpa/services/common"
)
const (
mgmtConfig = "/mgmtconfig/v2/admin/customers/"
postureProfileEndpoint = "/posture"
)
// PostureProfile ...
type PostureProfile struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
ApplyToMachineTunnelEnabled bool `json:"applyToMachineTunnelEnabled"`
CRLCheckEnabled bool `json:"crlCheckEnabled"`
NonExportablePrivateKeyEnabled bool `json:"nonExportablePrivateKeyEnabled"`
Platform string `json:"platform,omitempty"`
CreationTime string `json:"creationTime,omitempty"`
Domain string `json:"domain,omitempty"`
MasterCustomerID string `json:"masterCustomerId,omitempty"`
ModifiedBy string `json:"modifiedBy,omitempty"`
ModifiedTime string `json:"modifiedTime,omitempty"`
PostureType string `json:"postureType,omitempty"`
PostureudID string `json:"postureUdid,omitempty"`
RootCert string `json:"rootCert,omitempty"`
ZscalerCloud string `json:"zscalerCloud,omitempty"`
ZscalerCustomerID string `json:"zscalerCustomerId,omitempty"`
}
func (service *Service) Get(id string) (*PostureProfile, *http.Response, error) {
v := new(PostureProfile)
relativeURL := fmt.Sprintf("%s/%s", mgmtConfig+service.Client.Config.CustomerID+postureProfileEndpoint, id)
resp, err := service.Client.NewRequestDo("GET", relativeURL, nil, nil, &v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
func (service *Service) GetByPostureUDID(postureUDID string) (*PostureProfile, *http.Response, error) {
relativeURL := fmt.Sprintf(mgmtConfig + service.Client.Config.CustomerID + postureProfileEndpoint)
list, resp, err := common.GetAllPagesGeneric[PostureProfile](service.Client, relativeURL, "")
if err != nil {
return nil, nil, err
}
for _, postureProfile := range list {
if postureProfile.PostureudID == postureUDID {
return &postureProfile, resp, nil
}
}
return nil, resp, fmt.Errorf("no posture profile with postureUDID '%s' was found", postureUDID)
}
func (service *Service) GetByName(postureName string) (*PostureProfile, *http.Response, error) {
adaptedPostureName := common.RemoveCloudSuffix(postureName)
relativeURL := mgmtConfig + service.Client.Config.CustomerID + postureProfileEndpoint
// Set up custom filters for pagination
filters := common.Filter{Search: adaptedPostureName} // Using the adapted posture name for searching
// Use the custom pagination function with custom filters
list, resp, err := common.GetAllPagesGenericWithCustomFilters[PostureProfile](service.Client, relativeURL, filters)
if err != nil {
return nil, nil, err
}
// Iterate through the list and find the posture profile by its name
for _, postureProfile := range list {
if strings.EqualFold(common.RemoveCloudSuffix(postureProfile.Name), adaptedPostureName) {
return &postureProfile, resp, nil
}
}
return nil, resp, fmt.Errorf("no posture profile named '%s' was found", postureName)
}
func (service *Service) GetAll() ([]PostureProfile, *http.Response, error) {
relativeURL := mgmtConfig + service.Client.Config.CustomerID + postureProfileEndpoint
list, resp, err := common.GetAllPagesGeneric[PostureProfile](service.Client, relativeURL, "")
if err != nil {
return nil, nil, err
}
return list, resp, nil
}