Search in sources :

Example 1 with ReferencedResource

use of bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource in project terra-workspace-manager by DataBiosphere.

the class SamServiceTest method addedWriterCanWrite.

@Test
void addedWriterCanWrite() throws Exception {
    ReferencedDataRepoSnapshotResource referenceResource = ReferenceResourceFixtures.makeDataRepoSnapshotResource(workspaceId);
    // Before being granted permission, secondary user should be rejected.
    assertThrows(ForbiddenException.class, () -> referenceResourceService.createReferenceResource(referenceResource, secondaryUserRequest()));
    // After being granted permission, secondary user can modify the workspace.
    samService.grantWorkspaceRole(workspaceId, defaultUserRequest(), WsmIamRole.WRITER, userAccessUtils.getSecondUserEmail());
    ReferencedResource ref = referenceResourceService.createReferenceResource(referenceResource, secondaryUserRequest());
    ReferencedDataRepoSnapshotResource resultResource = ref.castByEnum(WsmResourceType.REFERENCED_ANY_DATA_REPO_SNAPSHOT);
    assertEquals(referenceResource, resultResource);
}
Also used : ReferencedResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource) ReferencedDataRepoSnapshotResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.datareposnapshot.ReferencedDataRepoSnapshotResource) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest) Test(org.junit.jupiter.api.Test)

Example 2 with ReferencedResource

use of bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource in project terra-workspace-manager by DataBiosphere.

the class ReferencedGcpResourceController method cloneGcpGcsObjectReference.

@Override
public ResponseEntity<ApiCloneReferencedGcpGcsObjectResourceResult> cloneGcpGcsObjectReference(UUID workspaceId, UUID resourceId, @Valid ApiCloneReferencedResourceRequestBody body) {
    AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    final ReferencedResource sourceReferencedResource = referenceResourceService.getReferenceResource(workspaceId, resourceId, userRequest);
    final CloningInstructions effectiveCloningInstructions = Optional.ofNullable(body.getCloningInstructions()).map(CloningInstructions::fromApiModel).orElse(sourceReferencedResource.getCloningInstructions());
    if (CloningInstructions.COPY_REFERENCE != effectiveCloningInstructions) {
        // Nothing to clone here
        final var emptyResult = new ApiCloneReferencedGcpGcsObjectResourceResult().effectiveCloningInstructions(effectiveCloningInstructions.toApiModel()).sourceResourceId(sourceReferencedResource.getResourceId()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).resource(null);
        return new ResponseEntity<>(emptyResult, HttpStatus.OK);
    }
    // Clone the reference
    final ReferencedGcsObjectResource clonedReferencedResource = referenceResourceService.cloneReferencedResource(sourceReferencedResource, body.getDestinationWorkspaceId(), body.getName(), body.getDescription(), userRequest).castByEnum(WsmResourceType.REFERENCED_GCP_GCS_OBJECT);
    // Build the correct response type
    final var result = new ApiCloneReferencedGcpGcsObjectResourceResult().resource(clonedReferencedResource.toApiResource()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).sourceResourceId(sourceReferencedResource.getResourceId()).effectiveCloningInstructions(effectiveCloningInstructions.toApiModel());
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ReferencedResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource) ResponseEntity(org.springframework.http.ResponseEntity) CloningInstructions(bio.terra.workspace.service.resource.model.CloningInstructions) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ApiCloneReferencedGcpGcsObjectResourceResult(bio.terra.workspace.generated.model.ApiCloneReferencedGcpGcsObjectResourceResult) ReferencedGcsObjectResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsobject.ReferencedGcsObjectResource)

Example 3 with ReferencedResource

use of bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource in project terra-workspace-manager by DataBiosphere.

the class ReferencedGcpResourceController method cloneGcpGcsBucketReference.

@Override
public ResponseEntity<ApiCloneReferencedGcpGcsBucketResourceResult> cloneGcpGcsBucketReference(UUID workspaceId, UUID resourceId, @Valid ApiCloneReferencedResourceRequestBody body) {
    final AuthenticatedUserRequest petRequest = getCloningCredentials(workspaceId);
    final ReferencedResource sourceReferencedResource = referenceResourceService.getReferenceResource(workspaceId, resourceId, petRequest);
    final CloningInstructions effectiveCloningInstructions = Optional.ofNullable(body.getCloningInstructions()).map(CloningInstructions::fromApiModel).orElse(sourceReferencedResource.getCloningInstructions());
    if (CloningInstructions.COPY_REFERENCE != effectiveCloningInstructions) {
        // Nothing to clone here
        final var emptyResult = new ApiCloneReferencedGcpGcsBucketResourceResult().effectiveCloningInstructions(effectiveCloningInstructions.toApiModel()).sourceResourceId(sourceReferencedResource.getResourceId()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).resource(null);
        return new ResponseEntity<>(emptyResult, HttpStatus.OK);
    }
    // Clone the reference
    final ReferencedGcsBucketResource clonedReferencedResource = referenceResourceService.cloneReferencedResource(sourceReferencedResource, body.getDestinationWorkspaceId(), body.getName(), body.getDescription(), petRequest).castByEnum(WsmResourceType.REFERENCED_GCP_GCS_BUCKET);
    // Build the correct response type
    final var result = new ApiCloneReferencedGcpGcsBucketResourceResult().resource(clonedReferencedResource.toApiResource()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).sourceResourceId(sourceReferencedResource.getResourceId()).effectiveCloningInstructions(effectiveCloningInstructions.toApiModel());
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ReferencedResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource) ResponseEntity(org.springframework.http.ResponseEntity) CloningInstructions(bio.terra.workspace.service.resource.model.CloningInstructions) ReferencedGcsBucketResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.gcsbucket.ReferencedGcsBucketResource) ApiCloneReferencedGcpGcsBucketResourceResult(bio.terra.workspace.generated.model.ApiCloneReferencedGcpGcsBucketResourceResult) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest)

Example 4 with ReferencedResource

use of bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource in project terra-workspace-manager by DataBiosphere.

the class ReferencedGcpResourceController method cloneGcpDataRepoSnapshotReference.

@Override
public ResponseEntity<ApiCloneReferencedGcpDataRepoSnapshotResourceResult> cloneGcpDataRepoSnapshotReference(UUID workspaceId, UUID resourceId, @Valid ApiCloneReferencedResourceRequestBody body) {
    final AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    final ReferencedResource sourceReferencedResource = referenceResourceService.getReferenceResource(workspaceId, resourceId, userRequest);
    final CloningInstructions effectiveCloningInstructions = Optional.ofNullable(body.getCloningInstructions()).map(CloningInstructions::fromApiModel).orElse(sourceReferencedResource.getCloningInstructions());
    if (CloningInstructions.COPY_REFERENCE != effectiveCloningInstructions) {
        // Nothing to clone here
        final var emptyResult = new ApiCloneReferencedGcpDataRepoSnapshotResourceResult().effectiveCloningInstructions(effectiveCloningInstructions.toApiModel()).sourceResourceId(sourceReferencedResource.getResourceId()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).resource(null);
        return new ResponseEntity<>(emptyResult, HttpStatus.OK);
    }
    // Clone the reference
    final ReferencedDataRepoSnapshotResource clonedReferencedResource = referenceResourceService.cloneReferencedResource(sourceReferencedResource, body.getDestinationWorkspaceId(), body.getName(), body.getDescription(), userRequest).castByEnum(WsmResourceType.REFERENCED_ANY_DATA_REPO_SNAPSHOT);
    // Build the correct response type
    final var result = new ApiCloneReferencedGcpDataRepoSnapshotResourceResult().resource(clonedReferencedResource.toApiResource()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).sourceResourceId(sourceReferencedResource.getResourceId()).effectiveCloningInstructions(effectiveCloningInstructions.toApiModel());
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ReferencedResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource) ResponseEntity(org.springframework.http.ResponseEntity) CloningInstructions(bio.terra.workspace.service.resource.model.CloningInstructions) ApiCloneReferencedGcpDataRepoSnapshotResourceResult(bio.terra.workspace.generated.model.ApiCloneReferencedGcpDataRepoSnapshotResourceResult) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ReferencedDataRepoSnapshotResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.datareposnapshot.ReferencedDataRepoSnapshotResource)

Example 5 with ReferencedResource

use of bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource in project terra-workspace-manager by DataBiosphere.

the class ReferencedGcpResourceController method cloneGcpBigQueryDatasetReference.

@Override
public ResponseEntity<ApiCloneReferencedGcpBigQueryDatasetResourceResult> cloneGcpBigQueryDatasetReference(UUID workspaceId, UUID resourceId, @Valid ApiCloneReferencedResourceRequestBody body) {
    final AuthenticatedUserRequest petRequest = getCloningCredentials(workspaceId);
    final ReferencedResource sourceReferencedResource = referenceResourceService.getReferenceResource(workspaceId, resourceId, petRequest);
    final CloningInstructions effectiveCloningInstructions = Optional.ofNullable(body.getCloningInstructions()).map(CloningInstructions::fromApiModel).orElse(sourceReferencedResource.getCloningInstructions());
    if (CloningInstructions.COPY_REFERENCE != effectiveCloningInstructions) {
        // Nothing to clone here
        final var emptyResult = new ApiCloneReferencedGcpBigQueryDatasetResourceResult().effectiveCloningInstructions(effectiveCloningInstructions.toApiModel()).sourceResourceId(sourceReferencedResource.getResourceId()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).resource(null);
        return new ResponseEntity<>(emptyResult, HttpStatus.OK);
    }
    // Clone the reference
    final ReferencedBigQueryDatasetResource clonedReferencedResource = referenceResourceService.cloneReferencedResource(sourceReferencedResource, body.getDestinationWorkspaceId(), body.getName(), body.getDescription(), petRequest).castByEnum(WsmResourceType.REFERENCED_GCP_BIG_QUERY_DATASET);
    // Build the correct response type
    final var result = new ApiCloneReferencedGcpBigQueryDatasetResourceResult().resource(clonedReferencedResource.toApiResource()).sourceWorkspaceId(sourceReferencedResource.getWorkspaceId()).sourceResourceId(sourceReferencedResource.getResourceId()).effectiveCloningInstructions(effectiveCloningInstructions.toApiModel());
    return new ResponseEntity<>(result, HttpStatus.OK);
}
Also used : ReferencedResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource) ResponseEntity(org.springframework.http.ResponseEntity) CloningInstructions(bio.terra.workspace.service.resource.model.CloningInstructions) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ReferencedBigQueryDatasetResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.bqdataset.ReferencedBigQueryDatasetResource) ApiCloneReferencedGcpBigQueryDatasetResourceResult(bio.terra.workspace.generated.model.ApiCloneReferencedGcpBigQueryDatasetResourceResult)

Aggregations

ReferencedResource (bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource)11 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)7 CloningInstructions (bio.terra.workspace.service.resource.model.CloningInstructions)6 ResponseEntity (org.springframework.http.ResponseEntity)6 ReferencedDataRepoSnapshotResource (bio.terra.workspace.service.resource.referenced.cloud.gcp.datareposnapshot.ReferencedDataRepoSnapshotResource)4 Test (org.junit.jupiter.api.Test)3 FlightMap (bio.terra.stairway.FlightMap)2 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)2 UUID (java.util.UUID)2 StepResult (bio.terra.stairway.StepResult)1 DatabaseOperationException (bio.terra.stairway.exception.DatabaseOperationException)1 DuplicateFlightIdException (bio.terra.stairway.exception.DuplicateFlightIdException)1 StairwayExecutionException (bio.terra.stairway.exception.StairwayExecutionException)1 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)1 ApiCloneReferencedGcpBigQueryDataTableResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpBigQueryDataTableResourceResult)1 ApiCloneReferencedGcpBigQueryDatasetResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpBigQueryDatasetResourceResult)1 ApiCloneReferencedGcpDataRepoSnapshotResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpDataRepoSnapshotResourceResult)1 ApiCloneReferencedGcpGcsBucketResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpGcsBucketResourceResult)1 ApiCloneReferencedGcpGcsObjectResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpGcsObjectResourceResult)1 ApiCloneReferencedGitRepoResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGitRepoResourceResult)1