-
Notifications
You must be signed in to change notification settings - Fork 2
/
schema.go
111 lines (92 loc) · 2.34 KB
/
schema.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
package caskin
import (
"encoding/json"
)
type DirectorySearchType = string
type ObjectType = string
type Action = string
type User interface {
idInterface
codeInterface
}
type Domain interface {
idInterface
codeInterface
}
type Role interface {
ObjectData
codeInterface
}
type Object interface {
idInterface
codeInterface
parentInterface
domainInterface
GetObjectType() string
}
type ObjectData interface {
idInterface
domainInterface
// GetObjectID get object
GetObjectID() uint64
// SetObjectID set object
SetObjectID(uint64)
}
type IDirectory interface {
Search(uint64, DirectorySearchType) []*Directory
}
func ID[E idInterface](in []E) []uint64 {
var m []uint64
for _, v := range in {
m = append(m, v.GetID())
}
return m
}
func IDMap[E idInterface](in []E) map[uint64]E {
m := map[uint64]E{}
for _, v := range in {
m[v.GetID()] = v
}
return m
}
// Policy tuple of role-object-domain-action
type Policy struct {
Role Role `json:"role"`
Object Object `json:"object"`
Domain Domain `json:"domain"`
Action Action `json:"action"`
}
// Key get the unique identify of the policy
func (p *Policy) Key() string {
s := []string{p.Role.Encode(), p.Object.Encode(), p.Domain.Encode(), p.Action}
b, _ := json.Marshal(s)
return string(b)
}
// UserRolePair pair of user and role
type UserRolePair struct {
User User `json:"user"`
Role Role `json:"role"`
}
type Directory struct {
Object
AllDirectoryCount uint64 `json:"all_directory_count"`
AllItemCount uint64 `json:"all_item_count"`
TopDirectoryCount uint64 `json:"top_directory_count"`
TopItemCount uint64 `json:"top_item_count"`
}
type DirectoryRequest struct {
To uint64 `json:"to,omitempty"`
ID []uint64 `json:"id,omitempty"`
Type string `json:"type,omitempty"`
Policy string `json:"policy,omitempty"`
SearchType string `json:"search_type,omitempty"`
CountDirectory func([]uint64) (map[uint64]uint64, error)
ActionDirectory func([]uint64) error
}
type CountDirectoryItem = func([]uint64) (map[uint64]uint64, error)
type DirectoryResponse struct {
DoneDirectoryCount uint64 `json:"done_directory_count,omitempty"`
DoneItemCount uint64 `json:"done_item_count,omitempty"`
ToDoDirectoryCount uint64 `json:"to_do_directory_count,omitempty"`
ToDoItemCount uint64 `json:"to_do_item_count,omitempty"`
}