Search in sources :

Example 1 with IamRole

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;
}
Also used : HashMap(java.util.HashMap) RoleBindingList(bio.terra.workspace.model.RoleBindingList) IamRole(bio.terra.workspace.model.IamRole) ArrayList(java.util.ArrayList)

Aggregations

IamRole (bio.terra.workspace.model.IamRole)1 RoleBindingList (bio.terra.workspace.model.RoleBindingList)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1