Search in sources :

Example 1 with ReferencedDataRepoSnapshotResource

use of bio.terra.workspace.service.resource.referenced.cloud.gcp.datareposnapshot.ReferencedDataRepoSnapshotResource 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 ReferencedDataRepoSnapshotResource

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

the class ReferenceResourceFixtures method makeDataRepoSnapshotResource.

public static ReferencedDataRepoSnapshotResource makeDataRepoSnapshotResource(UUID workspaceId) {
    UUID resourceId = UUID.randomUUID();
    String resourceName = "testdatarepo-" + resourceId.toString();
    return new ReferencedDataRepoSnapshotResource(workspaceId, resourceId, resourceName, "description of " + resourceName, CloningInstructions.COPY_NOTHING, "terra", "polaroid");
}
Also used : UUID(java.util.UUID) ReferencedDataRepoSnapshotResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.datareposnapshot.ReferencedDataRepoSnapshotResource)

Example 3 with ReferencedDataRepoSnapshotResource

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

the class ReferencedGcpResourceController method getDataRepoSnapshotReference.

@Override
public ResponseEntity<ApiDataRepoSnapshotResource> getDataRepoSnapshotReference(UUID id, UUID referenceId) {
    AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
    ReferencedDataRepoSnapshotResource referenceResource = referenceResourceService.getReferenceResource(id, referenceId, userRequest).castByEnum(WsmResourceType.REFERENCED_ANY_DATA_REPO_SNAPSHOT);
    return new ResponseEntity<>(referenceResource.toApiResource(), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ReferencedDataRepoSnapshotResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.datareposnapshot.ReferencedDataRepoSnapshotResource)

Example 4 with ReferencedDataRepoSnapshotResource

use of bio.terra.workspace.service.resource.referenced.cloud.gcp.datareposnapshot.ReferencedDataRepoSnapshotResource 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 ReferencedDataRepoSnapshotResource

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

the class ReferencedGcpResourceController method createDataRepoSnapshotReference.

// -- Data Repo Snapshot -- //
@Override
public ResponseEntity<ApiDataRepoSnapshotResource> createDataRepoSnapshotReference(UUID id, @Valid ApiCreateDataRepoSnapshotReferenceRequestBody body) {
    var resource = ReferencedDataRepoSnapshotResource.builder().workspaceId(id).name(body.getMetadata().getName()).description(body.getMetadata().getDescription()).cloningInstructions(CloningInstructions.fromApiModel(body.getMetadata().getCloningInstructions())).instanceName(body.getSnapshot().getInstanceName()).snapshotId(body.getSnapshot().getSnapshot()).build();
    ReferencedDataRepoSnapshotResource referenceResource = referenceResourceService.createReferenceResource(resource, getAuthenticatedInfo()).castByEnum(WsmResourceType.REFERENCED_ANY_DATA_REPO_SNAPSHOT);
    return new ResponseEntity<>(referenceResource.toApiResource(), HttpStatus.OK);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) ReferencedDataRepoSnapshotResource(bio.terra.workspace.service.resource.referenced.cloud.gcp.datareposnapshot.ReferencedDataRepoSnapshotResource)

Aggregations

ReferencedDataRepoSnapshotResource (bio.terra.workspace.service.resource.referenced.cloud.gcp.datareposnapshot.ReferencedDataRepoSnapshotResource)11 Test (org.junit.jupiter.api.Test)5 ResponseEntity (org.springframework.http.ResponseEntity)5 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)4 ReferencedResource (bio.terra.workspace.service.resource.referenced.cloud.gcp.ReferencedResource)4 UUID (java.util.UUID)4 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)3 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)2 ApiCloneReferencedGcpDataRepoSnapshotResourceResult (bio.terra.workspace.generated.model.ApiCloneReferencedGcpDataRepoSnapshotResourceResult)1 ApiDataRepoSnapshotAttributes (bio.terra.workspace.generated.model.ApiDataRepoSnapshotAttributes)1 ApiResourceAttributesUnion (bio.terra.workspace.generated.model.ApiResourceAttributesUnion)1 ApiResourceDescription (bio.terra.workspace.generated.model.ApiResourceDescription)1 CloningInstructions (bio.terra.workspace.service.resource.model.CloningInstructions)1 Workspace (bio.terra.workspace.service.workspace.model.Workspace)1