-
Notifications
You must be signed in to change notification settings - Fork 1
/
security_policy_settings.go
82 lines (72 loc) · 1.95 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
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 {
White []string `json:"whitelistUrls,omitempty"`
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
}