Search in sources :

Example 16 with Workspace

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

the class WorkspaceService method deleteGcpCloudContext.

/**
 * Delete the GCP cloud context for the workspace. Verifies workspace existence and write
 * permission before deleting the cloud context.
 */
@Traced
public void deleteGcpCloudContext(UUID workspaceUuid, AuthenticatedUserRequest userRequest) {
    Workspace workspace = validateWorkspaceAndAction(userRequest, workspaceUuid, SamConstants.SamWorkspaceAction.WRITE);
    stageService.assertMcWorkspace(workspace, "deleteGcpCloudContext");
    String workspaceName = workspace.getDisplayName().orElse("");
    String jobDescription = String.format("Delete GCP cloud context for workspace: name: '%s' id: '%s'  ", workspaceName, workspaceUuid);
    jobService.newJob().description(jobDescription).flightClass(DeleteGcpContextFlight.class).userRequest(userRequest).operationType(OperationType.DELETE).workspaceId(workspaceUuid.toString()).submitAndWait(null);
}
Also used : Workspace(bio.terra.workspace.service.workspace.model.Workspace) Traced(io.opencensus.contrib.spring.aop.Traced)

Example 17 with Workspace

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

the class WorkspaceService method deleteAzureCloudContext.

public void deleteAzureCloudContext(UUID workspaceUuid, AuthenticatedUserRequest userRequest) {
    Workspace workspace = validateWorkspaceAndAction(userRequest, workspaceUuid, SamWorkspaceAction.WRITE);
    stageService.assertMcWorkspace(workspace, "deleteAzureCloudContext");
    String workspaceName = workspace.getDisplayName().orElse("");
    String jobDescription = String.format("Delete Azure cloud context for workspace: name: '%s' id: '%s'  ", workspaceName, workspaceUuid);
    jobService.newJob().description(jobDescription).flightClass(DeleteAzureContextFlight.class).userRequest(userRequest).operationType(OperationType.DELETE).workspaceId(workspaceUuid.toString()).submitAndWait(null);
}
Also used : Workspace(bio.terra.workspace.service.workspace.model.Workspace)

Example 18 with Workspace

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

the class WorkspaceService method removeWorkspaceRoleFromUser.

/**
 * Remove a workspace role from a user. This will also remove a user from their private resources
 * if they are no longer a member of the workspace (i.e. have no other roles) after role removal.
 *
 * @param workspaceUuid ID of the workspace user to remove user's role in
 * @param role Role to remove
 * @param rawUserEmail Email identifier of user whose role is being removed
 * @param executingUserRequest User credentials to authenticate this removal. Must belong to a
 *     workspace owner, and likely do not belong to {@code userEmail}.
 */
public void removeWorkspaceRoleFromUser(UUID workspaceUuid, WsmIamRole role, String rawUserEmail, AuthenticatedUserRequest executingUserRequest) {
    Workspace workspace = validateWorkspaceAndAction(executingUserRequest, workspaceUuid, SamConstants.SamWorkspaceAction.OWN);
    stageService.assertMcWorkspace(workspace, "removeWorkspaceRoleFromUser");
    // GCP always uses lowercase email identifiers, so we do the same here.
    String targetUserEmail = rawUserEmail.toLowerCase();
    // Before launching the flight, validate that the user being removed is a direct member of the
    // specified role. Users may also be added to a workspace via managed groups, but WSM does not
    // control membership of those groups, and so cannot remove them here.
    List<String> roleMembers = samService.listUsersWithWorkspaceRole(workspaceUuid, role, executingUserRequest).stream().map(String::toLowerCase).collect(Collectors.toList());
    if (!roleMembers.contains(targetUserEmail)) {
        return;
    }
    jobService.newJob().description(String.format("Remove role %s from user %s in workspace %s", role.name(), targetUserEmail, workspaceUuid)).flightClass(RemoveUserFromWorkspaceFlight.class).userRequest(executingUserRequest).operationType(OperationType.DELETE).workspaceId(workspaceUuid.toString()).addParameter(WorkspaceFlightMapKeys.USER_TO_REMOVE, targetUserEmail).addParameter(WorkspaceFlightMapKeys.ROLE_TO_REMOVE, role).submitAndWait(null);
}
Also used : Workspace(bio.terra.workspace.service.workspace.model.Workspace)

Example 19 with Workspace

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

the class WorkspaceService method getWorkspaceByUserFacingId.

/**
 * Retrieves an existing workspace by userFacingId
 */
@Traced
public Workspace getWorkspaceByUserFacingId(String userFacingId, AuthenticatedUserRequest userRequest) {
    logger.info("getWorkspaceByUserFacingId - userRequest: {}\nuserFacingId: {}", userRequest, userFacingId);
    Workspace workspace = workspaceDao.getWorkspaceByUserFacingId(userFacingId);
    SamRethrow.onInterrupted(() -> samService.checkAuthz(userRequest, SamConstants.SamResource.WORKSPACE, workspace.getWorkspaceId().toString(), SamWorkspaceAction.READ), "checkAuthz");
    return workspace;
}
Also used : Workspace(bio.terra.workspace.service.workspace.model.Workspace) Traced(io.opencensus.contrib.spring.aop.Traced)

Example 20 with Workspace

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

the class WorkspaceService method deleteWorkspace.

/**
 * Delete an existing workspace by ID.
 */
@Traced
public void deleteWorkspace(UUID uuid, AuthenticatedUserRequest userRequest) {
    Workspace workspace = validateWorkspaceAndAction(userRequest, uuid, SamWorkspaceAction.DELETE);
    String description = "Delete workspace " + uuid;
    JobBuilder deleteJob = jobService.newJob().description(description).flightClass(WorkspaceDeleteFlight.class).operationType(OperationType.DELETE).workspaceId(uuid.toString()).userRequest(userRequest).addParameter(WorkspaceFlightMapKeys.WORKSPACE_STAGE, workspace.getWorkspaceStage().name());
    // Skip access check, which can't succeed after the workspace is deleted
    deleteJob.submitAndWait(null, false);
}
Also used : JobBuilder(bio.terra.workspace.service.job.JobBuilder) Workspace(bio.terra.workspace.service.workspace.model.Workspace) Traced(io.opencensus.contrib.spring.aop.Traced)

Aggregations

Workspace (bio.terra.workspace.service.workspace.model.Workspace)74 Test (org.junit.jupiter.api.Test)40 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)30 ApiClonedWorkspace (bio.terra.workspace.generated.model.ApiClonedWorkspace)27 UUID (java.util.UUID)27 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)11 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)8 HashMap (java.util.HashMap)7 FlightDebugInfo (bio.terra.stairway.FlightDebugInfo)6 ApiCreatedWorkspace (bio.terra.workspace.generated.model.ApiCreatedWorkspace)6 SpendProfileId (bio.terra.workspace.service.spendprofile.SpendProfileId)6 ResponseEntity (org.springframework.http.ResponseEntity)6 FlightMap (bio.terra.stairway.FlightMap)5 StepStatus (bio.terra.stairway.StepStatus)5 Traced (io.opencensus.contrib.spring.aop.Traced)5 DisabledIfEnvironmentVariable (org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable)5 ForbiddenException (bio.terra.common.exception.ForbiddenException)4 FlightState (bio.terra.stairway.FlightState)3 ApiWorkspaceDescription (bio.terra.workspace.generated.model.ApiWorkspaceDescription)3 JobBuilder (bio.terra.workspace.service.job.JobBuilder)3