-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_authentication_settings.go
69 lines (61 loc) · 1.51 KB
/
user_authentication_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
package user_authentication_settings
import (
"fmt"
)
const (
exemptedUrlsEndpoint = "/authSettings/exemptedUrls"
)
type ExemptedUrls struct {
// Domains or URLs which are exempted from SSL Inspection
URLs []string `json:"urls"`
}
type QueryParameters struct {
ID string
}
func (service *Service) Get() (*ExemptedUrls, error) {
var urls ExemptedUrls
err := service.Client.Read(exemptedUrlsEndpoint, &urls)
if err != nil {
return nil, err
}
service.Client.Logger.Printf("[DEBUG]Returning exempted url rules from Get: %v", urls)
return &urls, nil
}
// return the new items that were added to slice1.
func difference(slice1 []string, slice2 []string) []string {
var diff []string
for _, s1 := range slice1 {
found := false
for _, s2 := range slice2 {
if s1 == s2 {
found = true
break
}
}
if !found {
diff = append(diff, s1)
}
}
return diff
}
func (service *Service) Update(urls ExemptedUrls) (*ExemptedUrls, error) {
currentUrsl, err := service.Get()
if err != nil {
return nil, err
}
newUrls := difference(urls.URLs, currentUrsl.URLs)
removedUrls := difference(currentUrsl.URLs, urls.URLs)
if len(newUrls) > 0 {
_, err := service.Client.Create(fmt.Sprintf("%s?action=ADD_TO_LIST", exemptedUrlsEndpoint), ExemptedUrls{newUrls})
if err != nil {
return nil, err
}
}
if len(removedUrls) > 0 {
_, err := service.Client.Create(fmt.Sprintf("%s?action=REMOVE_FROM_LIST", exemptedUrlsEndpoint), ExemptedUrls{removedUrls})
if err != nil {
return nil, err
}
}
return &urls, nil
}