-
Notifications
You must be signed in to change notification settings - Fork 0
/
cloudbrowserisolation.go
75 lines (61 loc) · 2.15 KB
/
cloudbrowserisolation.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
package cloudbrowserisolation
import (
"fmt"
"strings"
"github.com/SecurityGeekIO/zscaler-sdk-go/v2/zia/services/common"
)
const (
cbiProfileEndpoint = "/browserIsolation/profiles"
)
type IsolationProfile struct {
ID string `json:"id,omitempty"`
// Name of the browser isolation profile
Name string `json:"name,omitempty"`
// The browser isolation profile URL
URL string `json:"url,omitempty"`
// (Optional) Indicates whether this is a default browser isolation profile. Zscaler sets this field.
DefaultProfile bool `json:"defaultProfile,omitempty"`
}
// Updated Get function
func (service *Service) Get(profileID string) (*IsolationProfile, error) {
var cbiProfile IsolationProfile
err := service.Client.Read(fmt.Sprintf("%s/%s", cbiProfileEndpoint, profileID), &cbiProfile)
if err != nil {
return nil, checkNotSubscribedError(err)
}
service.Client.Logger.Printf("[DEBUG] Returning cloud browser isolation from Get: %s", cbiProfile.ID)
return &cbiProfile, nil
}
// Updated GetByName function
func (service *Service) GetByName(profileName string) (*IsolationProfile, error) {
var cbiProfiles []IsolationProfile
err := common.ReadAllPages(service.Client, cbiProfileEndpoint, &cbiProfiles)
if err != nil {
return nil, checkNotSubscribedError(err)
}
for _, cbi := range cbiProfiles {
if strings.EqualFold(cbi.Name, profileName) {
return &cbi, nil
}
}
return nil, fmt.Errorf("no cloud browser isolation profile found with name: %s", profileName)
}
// Updated GetAll function
func (service *Service) GetAll() ([]IsolationProfile, error) {
var cbiProfiles []IsolationProfile
err := common.ReadAllPages(service.Client, cbiProfileEndpoint, &cbiProfiles)
return cbiProfiles, checkNotSubscribedError(err)
}
type NotSubscribedError struct {
message string
}
func (e *NotSubscribedError) Error() string {
return e.message
}
// Helper function to check and wrap the "Not Subscribed" error
func checkNotSubscribedError(err error) error {
if err != nil && strings.Contains(err.Error(), "Cloud Browser Isolation subscription is required") {
return &NotSubscribedError{message: "NOT_SUBSCRIBED: Cloud Browser Isolation subscription is required"}
}
return err
}