-
Notifications
You must be signed in to change notification settings - Fork 0
/
cbizpaprofile.go
61 lines (54 loc) · 1.82 KB
/
cbizpaprofile.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
package cbizpaprofile
import (
"fmt"
"net/http"
"strings"
)
const (
cbiConfig = "/cbiconfig/cbi/api/customers/"
zpaProfileEndpoint string = "/zpaprofiles"
)
type ZPAProfiles struct {
ID string `json:"id,omitempty"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Enabled bool `json:"enabled"`
CreationTime string `json:"creationTime,omitempty"`
ModifiedBy string `json:"modifiedBy,omitempty"`
ModifiedTime string `json:"modifiedTime,omitempty"`
CBITenantID string `json:"cbiTenantId,omitempty"`
CBIProfileID string `json:"cbiProfileId,omitempty"`
CBIURL string `json:"cbiUrl"`
}
// The current API does not seem to support search by ID
func (service *Service) Get(profileID string) (*ZPAProfiles, *http.Response, error) {
v := new(ZPAProfiles)
relativeURL := fmt.Sprintf("%s/%s", cbiConfig+service.Client.Config.CustomerID+zpaProfileEndpoint, profileID)
resp, err := service.Client.NewRequestDo("GET", relativeURL, nil, nil, &v)
if err != nil {
return nil, nil, err
}
return v, resp, nil
}
// The current API does not seem to support search by Name
func (service *Service) GetByName(profileName string) (*ZPAProfiles, *http.Response, error) {
list, resp, err := service.GetAll()
if err != nil {
return nil, nil, err
}
for _, app := range list {
if strings.EqualFold(app.Name, profileName) {
return &app, resp, nil
}
}
return nil, resp, fmt.Errorf("no zpa profile named '%s' was found", profileName)
}
func (service *Service) GetAll() ([]ZPAProfiles, *http.Response, error) {
relativeURL := cbiConfig + service.Client.Config.CustomerID + zpaProfileEndpoint
var list []ZPAProfiles
resp, err := service.Client.NewRequestDo("GET", relativeURL, nil, nil, &list)
if err != nil {
return nil, nil, err
}
return list, resp, nil
}