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