-
Notifications
You must be signed in to change notification settings - Fork 2
/
policy.go
62 lines (48 loc) · 1.23 KB
/
policy.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
package raiden
import (
"regexp"
"strings"
)
type (
Acl struct {
Roles []string
Check *string
Using string
}
AclTag struct {
Read Acl
Write Acl
}
)
func UnmarshalAclTag(tag string) AclTag {
var aclTag AclTag
aclTagMap := make(map[string]string)
// Regular expression to match key-value pairs
re := regexp.MustCompile(`(\w+):"([^"]*)"`)
// Find all matches
matches := re.FindAllStringSubmatch(tag, -1)
// Loop through matches and add to result map
for _, match := range matches {
if len(match) == 3 {
key := match[1]
value := match[2]
aclTagMap[key] = value
}
}
if readTag, exist := aclTagMap["read"]; exist && len(readTag) > 0 {
aclTag.Read.Roles = strings.Split(readTag, ",")
}
if writeTag, exist := aclTagMap["write"]; exist && len(writeTag) > 0 {
aclTag.Write.Roles = strings.Split(writeTag, ",")
}
if readTagUsing, exist := aclTagMap["readUsing"]; exist && len(readTagUsing) > 0 {
aclTag.Read.Using = readTagUsing
}
if writeTagCheck, exist := aclTagMap["writeCheck"]; exist && len(writeTagCheck) > 0 {
aclTag.Write.Check = &writeTagCheck
}
if writeTagUsing, exist := aclTagMap["writeUsing"]; exist && len(writeTagUsing) > 0 {
aclTag.Write.Using = writeTagUsing
}
return aclTag
}