This repository has been archived by the owner on Mar 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathacl.go
65 lines (52 loc) · 1.71 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
/*** Copyright (c) 2016, The BioTeam, Inc. ***
*** For more information please refer to the LICENSE.md file ***/
package gorods
// #include "wrapper.h"
import "C"
import (
"fmt"
"time"
)
// AccessObject is an interface for Users and Groups, used within ACL slices to denote the access level of a DataObj or Collection
type AccessObject interface {
Name() string
Zone() *Zone
Comment() (string, error)
CreateTime() (time.Time, error)
ModifyTime() (time.Time, error)
Id() (int, error)
Type() int
Con() *Connection
}
// ACL is used to describe the access level that a particular AccessObject (User/Group) has on a DataObj or Collection
type ACL struct {
AccessObject AccessObject
AccessLevel int
Type int
}
// ACLs is a slice of ACL pointers
type ACLs []*ACL
// User is a shortcut to cast the AccessObject as it's underlying data structure type (*User)
func (acl *ACL) User() *User {
if acl.Type == UserType || acl.Type == AdminType || acl.Type == GroupAdminType {
return acl.AccessObject.(*User)
}
return nil
}
// Group is a shortcut to cast the AccessObject as it's underlying data structure type (*Group)
func (acl *ACL) Group() *Group {
if acl.Type == GroupType {
return acl.AccessObject.(*Group)
}
return nil
}
// AccessLevelString gets the string represenation of the AccessLevel
func (acl *ACL) AccessLevelString() string {
return getTypeString(acl.AccessLevel)
}
// String returns a formatted string describing the ACL struct
// example: g:designers#tempZone:read
func (acl *ACL) String() string {
typeString := getTypeString(acl.Type)
return fmt.Sprintf("%v:%v#%v:%v", typeString, acl.AccessObject.Name(), acl.AccessObject.Zone().Name(), getTypeString(acl.AccessLevel))
}