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;
}
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));
}
Aggregations