...
1 package jwk
2
3 import "regexp"
4
5
6
7
8
9 type InsecureWhitelist struct{}
10
11 func (InsecureWhitelist) IsAllowed(string) bool {
12 return true
13 }
14
15
16
17
18 type RegexpWhitelist struct {
19 patterns []*regexp.Regexp
20 }
21
22 func NewRegexpWhitelist() *RegexpWhitelist {
23 return &RegexpWhitelist{}
24 }
25
26 func (w *RegexpWhitelist) Add(pat *regexp.Regexp) *RegexpWhitelist {
27 w.patterns = append(w.patterns, pat)
28 return w
29 }
30
31
32
33 func (w *RegexpWhitelist) IsAllowed(u string) bool {
34 for _, pat := range w.patterns {
35 if pat.MatchString(u) {
36 return true
37 }
38 }
39 return false
40 }
41
42
43
44 type MapWhitelist struct {
45 store map[string]struct{}
46 }
47
48 func NewMapWhitelist() *MapWhitelist {
49 return &MapWhitelist{store: make(map[string]struct{})}
50 }
51
52 func (w *MapWhitelist) Add(pat string) *MapWhitelist {
53 w.store[pat] = struct{}{}
54 return w
55 }
56
57 func (w *MapWhitelist) IsAllowed(u string) bool {
58 _, b := w.store[u]
59 return b
60 }
61
62
63
64
65 type WhitelistFunc func(string) bool
66
67 func (w WhitelistFunc) IsAllowed(u string) bool {
68 return w(u)
69 }
70
View as plain text