Search in sources :

Example 1 with UFWorkspaceUser

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");
}
Also used : UserActionableException(bio.terra.cli.exception.UserActionableException) WorkspaceUser(bio.terra.cli.businessobject.WorkspaceUser) TestCommand(harness.TestCommand) TestUser(harness.TestUser) IOException(java.io.IOException) UUID(java.util.UUID) ArrayList(java.util.ArrayList) List(java.util.List) UFWorkspaceUser(bio.terra.cli.serialization.userfacing.UFWorkspaceUser) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) Optional(java.util.Optional) TestContext(harness.TestContext) TypeReference(com.fasterxml.jackson.core.type.TypeReference) UFWorkspaceUser(bio.terra.cli.serialization.userfacing.UFWorkspaceUser) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) TypeReference(com.fasterxml.jackson.core.type.TypeReference)

Example 2 with UFWorkspaceUser

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");
}
Also used : UFWorkspaceUser(bio.terra.cli.serialization.userfacing.UFWorkspaceUser) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with UFWorkspaceUser

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();
}
Also used : UFWorkspaceUser(bio.terra.cli.serialization.userfacing.UFWorkspaceUser) UFWorkspaceUser(bio.terra.cli.serialization.userfacing.UFWorkspaceUser) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 4 with UFWorkspaceUser

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");
}
Also used : UFWorkspaceUser(bio.terra.cli.serialization.userfacing.UFWorkspaceUser) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with UFWorkspaceUser

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);
}
Also used : UFWorkspaceUser(bio.terra.cli.serialization.userfacing.UFWorkspaceUser) TestUser(harness.TestUser) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

UFWorkspaceUser (bio.terra.cli.serialization.userfacing.UFWorkspaceUser)6 TestUser (harness.TestUser)4 DisplayName (org.junit.jupiter.api.DisplayName)3 Test (org.junit.jupiter.api.Test)3 WorkspaceUser (bio.terra.cli.businessobject.WorkspaceUser)2 WorkspaceOverride (bio.terra.cli.command.shared.options.WorkspaceOverride)1 UserActionableException (bio.terra.cli.exception.UserActionableException)1 UFWorkspace (bio.terra.cli.serialization.userfacing.UFWorkspace)1 TypeReference (com.fasterxml.jackson.core.type.TypeReference)1 TestCommand (harness.TestCommand)1 TestContext (harness.TestContext)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Optional (java.util.Optional)1 UUID (java.util.UUID)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1