use of bio.terra.workspace.model.IamRole in project terra-cli by DataBiosphere.
the class WorkspaceUser method listUsersInMap.
/**
* Get the workspace users for a workspace in a map, to make it easy to lookup a particular user.
*
* @param workspace workspace to list users in
* @return a map of email -> workspace user object
*/
private static Map<String, WorkspaceUser> listUsersInMap(Workspace workspace) {
// call WSM to get the users + roles for the existing workspace
RoleBindingList roleBindings = WorkspaceManagerService.fromContext().getRoles(workspace.getId());
// convert the WSM objects (role -> list of emails) to CLI objects (email -> list of roles)
Map<String, WorkspaceUser> workspaceUsers = new HashMap<>();
roleBindings.forEach(roleBinding -> {
IamRole role = roleBinding.getRole();
for (String email : roleBinding.getMembers()) {
// lowercase the email so there is a consistent way of looking up the email address
// the email address casing in SAM may not match the case of what is provided by the
// user
String emailLowercase = email.toLowerCase();
WorkspaceUser workspaceUser = workspaceUsers.get(emailLowercase);
if (workspaceUser == null) {
workspaceUser = new WorkspaceUser(emailLowercase, new ArrayList<>());
workspaceUsers.put(emailLowercase, workspaceUser);
}
workspaceUser.roles.add(Role.fromWsmRole(role));
}
});
return workspaceUsers;
}
Aggregations