Search in sources :

Example 6 with SpendProfileId

use of bio.terra.workspace.service.spendprofile.SpendProfileId in project terra-workspace-manager by DataBiosphere.

the class GcpCloudContextUnitTest method autoUpgradeTest.

@Test
public void autoUpgradeTest() throws Exception {
    // By default, allow all spend link calls as authorized. (All other isAuthorized calls return
    // false by Mockito default.
    Mockito.when(mockSamService.isAuthorized(Mockito.any(), Mockito.any(), Mockito.any(), Mockito.eq(SamSpendProfileAction.LINK))).thenReturn(true);
    // Fake groups
    Mockito.when(mockSamService.getWorkspacePolicy(any(), Mockito.eq(WsmIamRole.READER), any())).thenReturn(POLICY_READER);
    Mockito.when(mockSamService.getWorkspacePolicy(any(), Mockito.eq(WsmIamRole.WRITER), any())).thenReturn(POLICY_WRITER);
    Mockito.when(mockSamService.getWorkspacePolicy(any(), Mockito.eq(WsmIamRole.OWNER), any())).thenReturn(POLICY_OWNER);
    Mockito.when(mockSamService.getWorkspacePolicy(any(), Mockito.eq(WsmIamRole.APPLICATION), any())).thenReturn(POLICY_APPLICATION);
    // Create a workspace record
    UUID workspaceId = UUID.randomUUID();
    var workspace = new Workspace(workspaceId, "gcpCloudContextAutoUpgradeTest", "cloud context description", new SpendProfileId("spend-profile"), Collections.emptyMap(), WorkspaceStage.MC_WORKSPACE);
    workspaceDao.createWorkspace(workspace);
    // Create a cloud context in the database with a V1 format
    final String flightId = UUID.randomUUID().toString();
    workspaceDao.createCloudContextStart(workspaceId, CloudPlatform.GCP, flightId);
    workspaceDao.createCloudContextFinish(workspaceId, CloudPlatform.GCP, V1_JSON, flightId);
    // Run the service call that should do the upgrade
    GcpCloudContext updatedContext = gcpCloudContextService.getRequiredGcpCloudContext(workspaceId, USER_REQUEST);
    assertEquals(updatedContext.getSamPolicyOwner().orElse(null), POLICY_OWNER);
    assertEquals(updatedContext.getSamPolicyWriter().orElse(null), POLICY_WRITER);
    assertEquals(updatedContext.getSamPolicyReader().orElse(null), POLICY_READER);
    assertEquals(updatedContext.getSamPolicyApplication().orElse(null), POLICY_APPLICATION);
}
Also used : UUID(java.util.UUID) SpendProfileId(bio.terra.workspace.service.spendprofile.SpendProfileId) GcpCloudContext(bio.terra.workspace.service.workspace.model.GcpCloudContext) Workspace(bio.terra.workspace.service.workspace.model.Workspace) Test(org.junit.jupiter.api.Test) BaseUnitTest(bio.terra.workspace.common.BaseUnitTest)

Example 7 with SpendProfileId

use of bio.terra.workspace.service.spendprofile.SpendProfileId in project terra-workspace-manager by DataBiosphere.

the class WorkspaceApiController method createWorkspace.

@Override
public ResponseEntity<ApiCreatedWorkspace> createWorkspace(@RequestBody ApiCreateWorkspaceRequestBody body) {
    AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    logger.info("Creating workspace {} for {} subject {}", body.getId(), userRequest.getEmail(), userRequest.getSubjectId());
    // Existing client libraries should not need to know about the stage, as they won't use any of
    // the features it gates. If stage isn't specified in a create request, we default to
    // RAWLS_WORKSPACE.
    ApiWorkspaceStageModel requestStage = body.getStage();
    requestStage = (requestStage == null ? ApiWorkspaceStageModel.RAWLS_WORKSPACE : requestStage);
    WorkspaceStage internalStage = WorkspaceStage.fromApiModel(requestStage);
    Optional<SpendProfileId> spendProfileId = Optional.ofNullable(body.getSpendProfile()).map(SpendProfileId::new);
    Workspace workspace = Workspace.builder().workspaceId(body.getId()).spendProfileId(spendProfileId.orElse(null)).workspaceStage(internalStage).displayName(body.getDisplayName()).description(body.getDescription()).properties(propertyMapFromApi(body.getProperties())).build();
    UUID createdId = workspaceService.createWorkspace(workspace, userRequest);
    ApiCreatedWorkspace responseWorkspace = new ApiCreatedWorkspace().id(createdId);
    logger.info("Created workspace {} for {}", responseWorkspace, userRequest.getEmail());
    return new ResponseEntity<>(responseWorkspace, HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) WorkspaceStage(bio.terra.workspace.service.workspace.model.WorkspaceStage) ApiWorkspaceStageModel(bio.terra.workspace.generated.model.ApiWorkspaceStageModel) ApiCreatedWorkspace(bio.terra.workspace.generated.model.ApiCreatedWorkspace) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) UUID(java.util.UUID) SpendProfileId(bio.terra.workspace.service.spendprofile.SpendProfileId) ApiCreatedWorkspace(bio.terra.workspace.generated.model.ApiCreatedWorkspace) Workspace(bio.terra.workspace.service.workspace.model.Workspace) ApiClonedWorkspace(bio.terra.workspace.generated.model.ApiClonedWorkspace)

Example 8 with SpendProfileId

use of bio.terra.workspace.service.spendprofile.SpendProfileId in project terra-workspace-manager by DataBiosphere.

the class WorkspaceApiController method cloneWorkspace.

/**
 * Clone an entire workspace by creating a new workspace and cloning the workspace's resources
 * into it.
 *
 * @param workspaceId - ID of source workspace
 * @param body - request body
 * @return - result structure for the overall clone operation with details for each resource
 */
@Override
public ResponseEntity<ApiCloneWorkspaceResult> cloneWorkspace(UUID workspaceId, @Valid ApiCloneWorkspaceRequest body) {
    final AuthenticatedUserRequest petRequest = getCloningCredentials(workspaceId);
    Optional<SpendProfileId> spendProfileId = Optional.ofNullable(body.getSpendProfile()).map(SpendProfileId::new);
    // Construct the target workspace object from the inputs
    Workspace destinationWorkspace = Workspace.builder().workspaceId(UUID.randomUUID()).spendProfileId(spendProfileId.orElse(null)).workspaceStage(WorkspaceStage.MC_WORKSPACE).displayName(body.getDisplayName()).description(body.getDescription()).properties(propertyMapFromApi(body.getProperties())).build();
    final String jobId = workspaceService.cloneWorkspace(workspaceId, petRequest, body.getLocation(), destinationWorkspace);
    final ApiCloneWorkspaceResult result = fetchCloneWorkspaceResult(jobId, getAuthenticatedInfo());
    return new ResponseEntity<>(result, getAsyncResponseCode(result.getJobReport()));
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ApiCloneWorkspaceResult(bio.terra.workspace.generated.model.ApiCloneWorkspaceResult) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) SpendProfileId(bio.terra.workspace.service.spendprofile.SpendProfileId) ApiCreatedWorkspace(bio.terra.workspace.generated.model.ApiCreatedWorkspace) Workspace(bio.terra.workspace.service.workspace.model.Workspace) ApiClonedWorkspace(bio.terra.workspace.generated.model.ApiClonedWorkspace)

Aggregations

SpendProfileId (bio.terra.workspace.service.spendprofile.SpendProfileId)8 Workspace (bio.terra.workspace.service.workspace.model.Workspace)5 ApiClonedWorkspace (bio.terra.workspace.generated.model.ApiClonedWorkspace)2 ApiCreatedWorkspace (bio.terra.workspace.generated.model.ApiCreatedWorkspace)2 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)2 UUID (java.util.UUID)2 Test (org.junit.jupiter.api.Test)2 ResponseEntity (org.springframework.http.ResponseEntity)2 WriteTransaction (bio.terra.common.db.WriteTransaction)1 FlightMap (bio.terra.stairway.FlightMap)1 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)1 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)1 ApiAzureContext (bio.terra.workspace.generated.model.ApiAzureContext)1 ApiCloneWorkspaceResult (bio.terra.workspace.generated.model.ApiCloneWorkspaceResult)1 ApiGcpContext (bio.terra.workspace.generated.model.ApiGcpContext)1 ApiProperties (bio.terra.workspace.generated.model.ApiProperties)1 ApiProperty (bio.terra.workspace.generated.model.ApiProperty)1 ApiWorkspaceDescription (bio.terra.workspace.generated.model.ApiWorkspaceDescription)1 ApiWorkspaceStageModel (bio.terra.workspace.generated.model.ApiWorkspaceStageModel)1 SpendProfile (bio.terra.workspace.service.spendprofile.SpendProfile)1