-
Notifications
You must be signed in to change notification settings - Fork 119
/
acl.go
80 lines (68 loc) · 2.03 KB
/
acl.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
package yt
import "golang.org/x/xerrors"
// TODO(dakovalkov): create a different type for Permission
type Permission = string
const (
PermissionRead Permission = "read"
PermissionWrite Permission = "write"
PermissionUse Permission = "use"
PermissionAdminister Permission = "administer"
PermissionCreate Permission = "create"
PermissionRemove Permission = "remove"
PermissionMount Permission = "mount"
PermissionManage Permission = "manage"
PermissionModifyChildren Permission = "modify_children"
PermissionRegisterQueueConsumer Permission = "register_queue_consumer"
)
type SecurityAction string
const (
ActionAllow SecurityAction = "allow"
ActionDeny SecurityAction = "deny"
)
type ACE struct {
Action SecurityAction `yson:"action,omitempty"`
Subjects []string `yson:"subjects,omitempty"`
Permissions []Permission `yson:"permissions,omitempty"`
InheritanceMode string `yson:"inheritance_mode,omitempty"`
Columns []string `yson:"columns,omitempty"`
Vital *bool `yson:"vital,omitempty"`
SubjectTagFilter string `yson:"subject_tag_filter,omitempty"`
}
func ConvertPermissionType(typ *Permission) (*int32, error) {
if typ == nil {
return nil, nil
}
var ret int32
switch *typ {
case PermissionRead:
ret = 0x0001
case PermissionWrite:
ret = 0x0002
case PermissionUse:
ret = 0x0004
case PermissionAdminister:
ret = 0x0008
case PermissionCreate:
ret = 0x0100
case PermissionRemove:
ret = 0x0200
case PermissionMount:
ret = 0x0400
case PermissionManage:
ret = 0x0800
case PermissionModifyChildren:
ret = 0x1000
case PermissionRegisterQueueConsumer:
ret = 0x0010
default:
return nil, xerrors.Errorf("unexpected permission type %q", *typ)
}
return &ret, nil
}
func MustConvertPermissionType(typ *Permission) *int32 {
code, err := ConvertPermissionType(typ)
if err != nil {
panic(err)
}
return code
}