Search in sources :

Example 1 with RoleBindingList

use of bio.terra.workspace.model.RoleBindingList 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)

Example 2 with RoleBindingList

use of bio.terra.workspace.model.RoleBindingList in project terra-workspace-manager by DataBiosphere.

the class GetRoles method doUserJourney.

@Override
public void doUserJourney(TestUserSpecification testUser, WorkspaceApi workspaceApi) throws ApiException {
    // check granted roles
    final RoleBindingList roles = workspaceApi.getRoles(getWorkspaceId());
    logger.debug("For workspace id {}, retrieved role bindings:\n{}", getWorkspaceId().toString(), roles.toString());
    // our user should be in this list, with the correct role
    boolean isInList = ClientTestUtils.containsBinding(roles, testUser.userEmail, IAM_ROLE);
    assertThat(isInList, equalTo(true));
}
Also used : RoleBindingList(bio.terra.workspace.model.RoleBindingList)

Aggregations

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