Search in sources :

Example 1 with CloudContextRequiredException

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();
}
Also used : CloudContextRequiredException(bio.terra.workspace.service.workspace.exceptions.CloudContextRequiredException) AzureCloudContext(bio.terra.workspace.service.workspace.model.AzureCloudContext) ResourceManager(com.azure.resourcemanager.resources.ResourceManager) CloudContextRequiredException(bio.terra.workspace.service.workspace.exceptions.CloudContextRequiredException)

Example 2 with CloudContextRequiredException

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;
}
Also used : CloudContextRequiredException(bio.terra.workspace.service.workspace.exceptions.CloudContextRequiredException) GcpCloudContext(bio.terra.workspace.service.workspace.model.GcpCloudContext)

Example 3 with CloudContextRequiredException

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()));
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ApiCreateCloudContextResult(bio.terra.workspace.generated.model.ApiCreateCloudContextResult) CloudContextRequiredException(bio.terra.workspace.service.workspace.exceptions.CloudContextRequiredException) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ApiAzureContext(bio.terra.workspace.generated.model.ApiAzureContext)

Aggregations

CloudContextRequiredException (bio.terra.workspace.service.workspace.exceptions.CloudContextRequiredException)3 ApiAzureContext (bio.terra.workspace.generated.model.ApiAzureContext)1 ApiCreateCloudContextResult (bio.terra.workspace.generated.model.ApiCreateCloudContextResult)1 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)1 AzureCloudContext (bio.terra.workspace.service.workspace.model.AzureCloudContext)1 GcpCloudContext (bio.terra.workspace.service.workspace.model.GcpCloudContext)1 ResourceManager (com.azure.resourcemanager.resources.ResourceManager)1 ResponseEntity (org.springframework.http.ResponseEntity)1