/
helper.go
53 lines (39 loc) · 1.25 KB
/
helper.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
package metathings_identityd2_policy
import (
"fmt"
storage "github.com/nayotta/metathings/pkg/identityd2/storage"
)
func ConvertGroup(grp *storage.Group) string {
return fmt.Sprintf("dom.%s.grp.%s", *grp.DomainId, *grp.Id)
}
func ConvertSubject(sub *storage.Entity) string {
return fmt.Sprintf("sub.%s", *sub.Id)
}
func ConvertObject(obj *storage.Entity) string {
return fmt.Sprintf("obj.%s", *obj.Id)
}
func ConvertEntity(ent *storage.Entity) string {
return fmt.Sprintf("ent.%s", *ent.Id)
}
func ConvertRoleForObject(grp *storage.Group) string {
return fmt.Sprintf("dom.%s.grp.%s.data", *grp.DomainId, *grp.Id)
}
func ConvertRoleForSubject(grp *storage.Group, rol *storage.Role) string {
return fmt.Sprintf("dom.%s.grp.%s.rol.%s", *grp.DomainId, *grp.Id, *rol.Name)
}
func ConvertRolesForSubject(grp *storage.Group) []string {
var ys []string
for _, r := range grp.Roles {
ys = append(ys, ConvertRoleForSubject(grp, r))
}
return ys
}
func ConvertRole(grp *storage.Group, rol *storage.Role) string {
return fmt.Sprintf("dom.%s.grp.%s.rol.%s", *grp.DomainId, *grp.Id, *rol.Name)
}
func ConvertUngroupingRole(rol *storage.Role) string {
return fmt.Sprintf("rol.%s", *rol.Name)
}
func ConvertAction(act *storage.Action) string {
return *act.Name
}