use of bio.terra.workspace.service.workspace.exceptions.CloudContextRequiredException in project terra-workspace-manager by DataBiosphere.
the class ValidateMRGStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) throws InterruptedException {
AzureCloudContext azureCloudContext = flightContext.getInputParameters().get(JobMapKeys.REQUEST.getKeyName(), AzureCloudContext.class);
try {
ResourceManager resourceManager = crlService.getResourceManager(azureCloudContext, azureConfig);
resourceManager.resourceGroups().getByName(azureCloudContext.getAzureResourceGroupId());
} catch (Exception azureError) {
throw new CloudContextRequiredException("Invalid Azure cloud context", azureError);
}
return StepResult.getStepResultSuccess();
}
use of bio.terra.workspace.service.workspace.exceptions.CloudContextRequiredException in project terra-workspace-manager by DataBiosphere.
the class GcpCloudContextService method getRequiredGcpCloudContext.
/**
* Retrieve the GCP cloud context. If it does not have the policies filled in, retrieve the
* policies from Sam, fill them in, and update the cloud context.
*
* <p>This is used during controlled resource create. Since the caller may not have permission to
* read the workspace policies, we use the WSM SA to query Sam.
*
* @param workspaceId workspace identifier of the cloud context
* @return GCP cloud context with all policies filled in.
*/
public GcpCloudContext getRequiredGcpCloudContext(UUID workspaceId, AuthenticatedUserRequest userRequest) throws InterruptedException {
GcpCloudContext context = getGcpCloudContext(workspaceId).orElseThrow(() -> new CloudContextRequiredException("Operation requires GCP cloud context"));
// store the sync'd workspace policies.
if (context.getSamPolicyOwner().isEmpty()) {
context.setSamPolicyOwner(samService.getWorkspacePolicy(workspaceId, WsmIamRole.OWNER, userRequest));
context.setSamPolicyWriter(samService.getWorkspacePolicy(workspaceId, WsmIamRole.WRITER, userRequest));
context.setSamPolicyReader(samService.getWorkspacePolicy(workspaceId, WsmIamRole.READER, userRequest));
context.setSamPolicyApplication(samService.getWorkspacePolicy(workspaceId, WsmIamRole.APPLICATION, userRequest));
}
workspaceDao.updateCloudContext(workspaceId, CloudPlatform.GCP, context.serialize());
return context;
}
use of bio.terra.workspace.service.workspace.exceptions.CloudContextRequiredException in project terra-workspace-manager by DataBiosphere.
the class WorkspaceApiController method createCloudContext.
@Override
public ResponseEntity<ApiCreateCloudContextResult> createCloudContext(UUID id, @Valid ApiCreateCloudContextRequest body) {
ControllerValidationUtils.validateCloudPlatform(body.getCloudPlatform());
AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
String jobId = body.getJobControl().getId();
String resultPath = getAsyncResultEndpoint(jobId);
if (body.getCloudPlatform() == ApiCloudPlatform.AZURE) {
ApiAzureContext azureContext = Optional.ofNullable(body.getAzureContext()).orElseThrow(() -> new CloudContextRequiredException("AzureContext is required when creating an azure cloud context for a workspace"));
workspaceService.createAzureCloudContext(id, jobId, userRequest, resultPath, AzureCloudContext.fromApi(azureContext));
} else {
workspaceService.createGcpCloudContext(id, jobId, userRequest, resultPath);
}
ApiCreateCloudContextResult response = fetchCreateCloudContextResult(jobId, userRequest);
return new ResponseEntity<>(response, getAsyncResponseCode(response.getJobReport()));
}
Aggregations