-
Notifications
You must be signed in to change notification settings - Fork 6
/
fs_usergroup.go
120 lines (97 loc) · 2.58 KB
/
fs_usergroup.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
112
113
114
115
116
117
118
119
120
package fs
import (
irods_fs "github.com/cyverse/go-irodsclient/irods/fs"
"github.com/cyverse/go-irodsclient/irods/types"
)
// ListGroupUsers lists all users in a group
func (fs *FileSystem) ListGroupUsers(group string) ([]*types.IRODSUser, error) {
// check cache first
cachedUsers := fs.cache.GetGroupUsersCache(group)
if cachedUsers != nil {
return cachedUsers, nil
}
// otherwise, retrieve it and add it to cache
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return nil, err
}
defer fs.metaSession.ReturnConnection(conn)
users, err := irods_fs.ListGroupUsers(conn, group)
if err != nil {
return nil, err
}
// cache it
fs.cache.AddGroupUsersCache(group, users)
return users, nil
}
// ListGroups lists all groups
func (fs *FileSystem) ListGroups() ([]*types.IRODSUser, error) {
// check cache first
cachedGroups := fs.cache.GetGroupsCache()
if cachedGroups != nil {
return cachedGroups, nil
}
// otherwise, retrieve it and add it to cache
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return nil, err
}
defer fs.metaSession.ReturnConnection(conn)
groups, err := irods_fs.ListGroups(conn)
if err != nil {
return nil, err
}
// cache it
fs.cache.AddGroupsCache(groups)
return groups, nil
}
// ListUserGroups lists all groups that a user belongs to
func (fs *FileSystem) ListUserGroups(user string) ([]*types.IRODSUser, error) {
// check cache first
cachedGroups := fs.cache.GetUserGroupsCache(user)
if cachedGroups != nil {
return cachedGroups, nil
}
// otherwise, retrieve it and add it to cache
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return nil, err
}
defer fs.metaSession.ReturnConnection(conn)
groupNames, err := irods_fs.ListUserGroupNames(conn, user)
if err != nil {
return nil, err
}
groups := []*types.IRODSUser{}
for _, groupName := range groupNames {
group, err := irods_fs.GetGroup(conn, groupName)
if err != nil {
return nil, err
}
groups = append(groups, group)
}
// cache it
fs.cache.AddUserGroupsCache(user, groups)
return groups, nil
}
// ListUsers lists all users
func (fs *FileSystem) ListUsers() ([]*types.IRODSUser, error) {
// check cache first
cachedUsers := fs.cache.GetUsersCache()
if cachedUsers != nil {
return cachedUsers, nil
}
// otherwise, retrieve it and add it to cache
conn, err := fs.metaSession.AcquireConnection()
if err != nil {
return nil, err
}
defer fs.metaSession.ReturnConnection(conn)
users, err := irods_fs.ListUsers(conn)
if err != nil {
return nil, err
}
// cache it
fs.cache.AddUsersCache(users)
return users, nil
}