use of bio.terra.cli.serialization.userfacing.UFWorkspaceUser in project terra-cli by DataBiosphere.
the class CleanupTestUserWorkspaces method deleteWorkspaces.
/**
* List all workspaces the test user has access to and try to delete each one that the test user
* owns. Deletes up to 100 workspaces at a time.
*/
private static void deleteWorkspaces(TestUser testUser, boolean isDryRun) throws IOException {
System.out.println("Deleting workspaces for testuser " + testUser.email);
TestContext.clearGlobalContextDir();
testUser.login();
// `terra workspace list`
List<UFWorkspace> listWorkspaces = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
}, "workspace", "list", "--limit=100");
List<UFWorkspaceUser> listWorkspaceUsers;
for (UFWorkspace workspace : listWorkspaces) {
try {
// `terra workspace list-users`
listWorkspaceUsers = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
}, "workspace", "list-users", "--workspace=" + workspace.id);
// find the user in the list
Optional<UFWorkspaceUser> workspaceUser = listWorkspaceUsers.stream().filter(user -> user.email.equalsIgnoreCase(testUser.email)).findAny();
// skip deleting if the test user is not an owner
if (workspaceUser.isEmpty() || !workspaceUser.get().roles.contains(WorkspaceUser.Role.OWNER)) {
System.out.println("Skip deleting workspace because test user is not an owner: id=" + workspace.id + ", testuser=" + testUser.email);
continue;
}
System.out.println("Deleting workspace: id=" + workspace.id + ", testuser=" + testUser.email);
if (!isDryRun) {
// `terra workspace delete --workspace=$id`
TestCommand.runCommandExpectSuccess("workspace", "delete", "--workspace=" + workspace.id, "--quiet");
System.out.println("Cleaned up workspace: id=" + workspace.id + ", testuser=" + testUser.email);
}
deletedWorkspaces.add(workspace.id);
} catch (Throwable ex) {
System.out.println("Error deleting workspace: id=" + workspace.id + ", testuser=" + testUser.email);
ex.printStackTrace();
failedWorkspaces.add(workspace.id);
continue;
}
}
// `terra auth revoke`
TestCommand.runCommandExpectSuccess("auth", "revoke");
}
use of bio.terra.cli.serialization.userfacing.UFWorkspaceUser in project terra-cli by DataBiosphere.
the class WorkspaceOverride method workspaceUser.
@Test
@DisplayName("workspace user commands respect workspace override")
void workspaceUser() throws IOException {
// login as the workspace creator and select a test user to share the workspace with
workspaceCreator.login();
TestUser testUser = TestUser.chooseTestUserWhoIsNot(workspaceCreator);
// `terra workspace set --id=$id1`
TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + workspace1.id);
// `terra workspace add-user --email=$email --role=READER --workspace=$id2`
TestCommand.runCommandExpectSuccess("workspace", "add-user", "--email=" + testUser.email, "--role=READER", "--workspace=" + workspace2.id);
// check that the user exists in the list output for workspace 2, but not workspace 1
// `terra workspace list-users --email=$email --role=READER --workspace=$id2`
expectListedUserWithRoles(testUser.email, workspace2.id, WorkspaceUser.Role.READER);
// `terra workspace list-users --email=$email --role=READER`
Optional<UFWorkspaceUser> workspaceUser = workspaceListUsersWithEmail(testUser.email);
assertTrue(workspaceUser.isEmpty(), "test user is not in users list for workspace 1");
// `terra workspace remove-user --email=$email --role=READER --workspace=$id2`
TestCommand.runCommandExpectSuccess("workspace", "remove-user", "--email=" + testUser.email, "--role=READER", "--workspace=" + workspace2.id);
// `terra workspace list-users --email=$email --role=READER --workspace=$id2`
// check that the user no longer exists in the list output for workspace 2
workspaceUser = workspaceListUsersWithEmail(testUser.email, workspace2.id);
assertTrue(workspaceUser.isEmpty(), "test user is no longer in users list for workspace 2");
}
use of bio.terra.cli.serialization.userfacing.UFWorkspaceUser in project terra-cli by DataBiosphere.
the class WorkspaceUser method setupEachTime.
@BeforeEach
@Override
protected void setupEachTime() throws IOException {
workspaceCreator.login();
// `terra workspace set --id=$id`
TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
// `terra workspace list-users --format=json`
List<UFWorkspaceUser> listWorkspaceUsers = TestCommand.runAndParseCommandExpectSuccess(new TypeReference<>() {
}, "workspace", "list-users");
for (UFWorkspaceUser user : listWorkspaceUsers) {
if (user.email.equalsIgnoreCase(workspaceCreator.email)) {
continue;
}
for (bio.terra.cli.businessobject.WorkspaceUser.Role role : user.roles) {
// `terra workspace remove-user --email=$email --role=$role
TestCommand.runCommandExpectSuccess("workspace", "remove-user", "--email=" + user.email, "--role=" + role);
}
}
super.setupEachTime();
}
use of bio.terra.cli.serialization.userfacing.UFWorkspaceUser in project terra-cli by DataBiosphere.
the class WorkspaceUser method listReflectRemove.
@Test
@DisplayName("list users reflects removing a user")
void listReflectRemove() throws IOException {
// login as the workspace creator and select a test user to share the workspace with
workspaceCreator.login();
TestUser testUser = TestUser.chooseTestUserWhoIsNot(workspaceCreator);
// `terra workspace set --id=$id`
TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
// `terra workspace add-user --email=$email --role=READER --format=json
TestCommand.runCommandExpectSuccess("workspace", "add-user", "--email=" + testUser.email, "--role=READER", "--format=json");
// `terra workspace add-user --email=$email --role=OWNER --format=json
TestCommand.runCommandExpectSuccess("workspace", "add-user", "--email=" + testUser.email, "--role=OWNER", "--format=json");
// `terra workspace remove-user --email=$email --role=READER --format=json
TestCommand.runCommandExpectSuccess("workspace", "remove-user", "--email=" + testUser.email, "--role=READER");
// check that the user is in the list as an OWNER only
expectListedUserWithRoles(testUser.email, OWNER);
// `terra workspace remove-user --email=$email --role=READER`
TestCommand.runCommandExpectSuccess("workspace", "remove-user", "--email=" + testUser.email, "--role=OWNER");
// check that the user is not in the list
Optional<UFWorkspaceUser> workspaceUser = workspaceListUsersWithEmail(testUser.email);
assertTrue(workspaceUser.isEmpty(), "test user is not in users list");
}
use of bio.terra.cli.serialization.userfacing.UFWorkspaceUser in project terra-cli by DataBiosphere.
the class WorkspaceUser method listReflectAdd.
@Test
@DisplayName("list users reflects adding a user")
void listReflectAdd() throws IOException {
// login as the workspace creator and select a test user to share the workspace with
workspaceCreator.login();
TestUser testUser = TestUser.chooseTestUserWhoIsNot(workspaceCreator);
// `terra workspace set --id=$id`
TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
// `terra workspace add-user --email=$email --role=READER --format=json
UFWorkspaceUser addUserReader = TestCommand.runAndParseCommandExpectSuccess(UFWorkspaceUser.class, "workspace", "add-user", "--email=" + testUser.email, "--role=READER");
// check that the user has the READER role
assertTrue(addUserReader.roles.contains(READER), "reader role returned by add-user");
// check that the user is in the list as a reader
expectListedUserWithRoles(testUser.email, READER);
// `terra workspace add-user --email=$email --role=WRITER --format=json
UFWorkspaceUser addUserWriter = TestCommand.runAndParseCommandExpectSuccess(UFWorkspaceUser.class, "workspace", "add-user", "--email=" + testUser.email, "--role=WRITER");
// check that the user has both the READER and WRITER roles
assertTrue(addUserWriter.roles.containsAll(Arrays.asList(READER, WRITER)), "reader and writer roles returned by add-user");
// check that the user is in the list as a reader + writer
expectListedUserWithRoles(testUser.email, READER, WRITER);
}
Aggregations