github.com/cyverse/go-irodsclient@v0.13.2/fs/fs_usergroup.go (about) 1 package fs 2 3 import ( 4 irods_fs "github.com/cyverse/go-irodsclient/irods/fs" 5 "github.com/cyverse/go-irodsclient/irods/types" 6 ) 7 8 // ListGroupUsers lists all users in a group 9 func (fs *FileSystem) ListGroupUsers(group string) ([]*types.IRODSUser, error) { 10 // check cache first 11 cachedUsers := fs.cache.GetGroupUsersCache(group) 12 if cachedUsers != nil { 13 return cachedUsers, nil 14 } 15 16 // otherwise, retrieve it and add it to cache 17 conn, err := fs.metaSession.AcquireConnection() 18 if err != nil { 19 return nil, err 20 } 21 defer fs.metaSession.ReturnConnection(conn) 22 23 users, err := irods_fs.ListGroupUsers(conn, group) 24 if err != nil { 25 return nil, err 26 } 27 28 // cache it 29 fs.cache.AddGroupUsersCache(group, users) 30 31 return users, nil 32 } 33 34 // ListGroups lists all groups 35 func (fs *FileSystem) ListGroups() ([]*types.IRODSUser, error) { 36 // check cache first 37 cachedGroups := fs.cache.GetGroupsCache() 38 if cachedGroups != nil { 39 return cachedGroups, nil 40 } 41 42 // otherwise, retrieve it and add it to cache 43 conn, err := fs.metaSession.AcquireConnection() 44 if err != nil { 45 return nil, err 46 } 47 defer fs.metaSession.ReturnConnection(conn) 48 49 groups, err := irods_fs.ListGroups(conn) 50 if err != nil { 51 return nil, err 52 } 53 54 // cache it 55 fs.cache.AddGroupsCache(groups) 56 57 return groups, nil 58 } 59 60 // ListUserGroups lists all groups that a user belongs to 61 func (fs *FileSystem) ListUserGroups(user string) ([]*types.IRODSUser, error) { 62 // check cache first 63 cachedGroups := fs.cache.GetUserGroupsCache(user) 64 if cachedGroups != nil { 65 return cachedGroups, nil 66 } 67 68 // otherwise, retrieve it and add it to cache 69 conn, err := fs.metaSession.AcquireConnection() 70 if err != nil { 71 return nil, err 72 } 73 defer fs.metaSession.ReturnConnection(conn) 74 75 groupNames, err := irods_fs.ListUserGroupNames(conn, user) 76 if err != nil { 77 return nil, err 78 } 79 80 groups := []*types.IRODSUser{} 81 for _, groupName := range groupNames { 82 group, err := irods_fs.GetGroup(conn, groupName) 83 if err != nil { 84 return nil, err 85 } 86 87 groups = append(groups, group) 88 } 89 90 // cache it 91 fs.cache.AddUserGroupsCache(user, groups) 92 93 return groups, nil 94 } 95 96 // ListUsers lists all users 97 func (fs *FileSystem) ListUsers() ([]*types.IRODSUser, error) { 98 // check cache first 99 cachedUsers := fs.cache.GetUsersCache() 100 if cachedUsers != nil { 101 return cachedUsers, nil 102 } 103 104 // otherwise, retrieve it and add it to cache 105 conn, err := fs.metaSession.AcquireConnection() 106 if err != nil { 107 return nil, err 108 } 109 defer fs.metaSession.ReturnConnection(conn) 110 111 users, err := irods_fs.ListUsers(conn) 112 if err != nil { 113 return nil, err 114 } 115 116 // cache it 117 fs.cache.AddUsersCache(users) 118 119 return users, nil 120 }