-
Notifications
You must be signed in to change notification settings - Fork 0
/
security_policy_settings.go
85 lines (74 loc) · 2.45 KB
/
security_policy_settings.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
package security_policy_settings
const (
securityEndpoint = "/security"
securityAdvancedEndpoint = "/security/advanced"
)
// TODO: because there isn't an endpoint to get all Urls, we need to have all action types here.
var AddRemoveURLFromList []string = []string{
"ADD_TO_LIST",
"REMOVE_FROM_LIST",
}
type ListUrls struct {
// Allowlist URLs whose contents will not be scanned. Allows up to 255 URLs. There may be trusted websites the content of which might be blocked due to anti-virus, anti-spyware, or anti-malware policies. Enter the URLs of sites you do not want scanned. The service allows users to download content from these URLs without inspecting the traffic. The allowlist applies to the Malware Protection, Advanced Threats Protection, and Sandbox policies.
White []string `json:"whitelistUrls,omitempty"`
// URLs on the denylist for your organization. Allow up to 25000 URLs.
Black []string `json:"blacklistUrls,omitempty"`
}
func (service *Service) GetListUrls() (*ListUrls, error) {
whitelist, err := service.GetWhiteListUrls()
if err != nil {
return nil, err
}
blacklist, err := service.GetBlackListUrls()
if err != nil {
return nil, err
}
return &ListUrls{
White: whitelist.White,
Black: blacklist.Black,
}, nil
}
func (service *Service) UpdateListUrls(listUrls ListUrls) (*ListUrls, error) {
whitelist, err := service.UpdateWhiteListUrls(ListUrls{White: listUrls.White})
if err != nil {
return nil, err
}
blacklist, err := service.UpdateBlackListUrls(ListUrls{Black: listUrls.Black})
if err != nil {
return nil, err
}
return &ListUrls{
White: whitelist.White,
Black: blacklist.Black,
}, nil
}
func (service *Service) UpdateWhiteListUrls(list ListUrls) (*ListUrls, error) {
_, err := service.Client.UpdateWithPut(securityEndpoint, list)
if err != nil {
return nil, err
}
return &list, nil
}
func (service *Service) UpdateBlackListUrls(list ListUrls) (*ListUrls, error) {
_, err := service.Client.UpdateWithPut(securityAdvancedEndpoint, list)
if err != nil {
return nil, err
}
return &list, nil
}
func (service *Service) GetWhiteListUrls() (*ListUrls, error) {
var whitelist ListUrls
err := service.Client.Read(securityEndpoint, &whitelist)
if err != nil {
return nil, err
}
return &whitelist, nil
}
func (service *Service) GetBlackListUrls() (*ListUrls, error) {
var blacklist ListUrls
err := service.Client.Read(securityAdvancedEndpoint, &blacklist)
if err != nil {
return nil, err
}
return &blacklist, nil
}