Search in sources :

Example 1 with GcpGcsObjectResource

use of bio.terra.workspace.model.GcpGcsObjectResource in project terra-workspace-manager by DataBiosphere.

the class ReferencedGcsResourceLifecycle method testUpdateReferences.

private void testUpdateReferences(GcpGcsBucketResource fineGrainedBucket, ReferencedGcpResourceApi fullAccessApi) throws Exception {
    ReferencedGcpResourceApi partialAccessApi = ClientTestUtils.getReferencedGcpResourceClient(partialAccessUser, server);
    ResourceApi partialAccessResourceApi = ClientTestUtils.getResourceClient(partialAccessUser, server);
    // Update GCS bucket's name and description
    String newBucketName = "newGcsBucket";
    String newBucketDescription = "a new description to the new bucket reference";
    GcsBucketUtils.updateGcsBucketReference(fullAccessApi, getWorkspaceId(), bucketResourceId, newBucketName, newBucketDescription, null);
    GcpGcsBucketResource bucketReferenceFirstUpdate = fullAccessApi.getBucketReference(getWorkspaceId(), bucketResourceId);
    assertEquals(newBucketName, bucketReferenceFirstUpdate.getMetadata().getName());
    assertEquals(newBucketDescription, bucketReferenceFirstUpdate.getMetadata().getDescription());
    assertEquals(gcsUniformAccessBucketAttributes.getBucketName(), bucketReferenceFirstUpdate.getAttributes().getBucketName());
    assertTrue(partialAccessResourceApi.checkReferenceAccess(getWorkspaceId(), bucketResourceId));
    // Attempt to update bucket reference but {@code userWithPartialAccess} does not have
    // access to the bucket with fine-grained access
    assertThrows(ApiException.class, () -> GcsBucketUtils.updateGcsBucketReference(partialAccessApi, getWorkspaceId(), bucketResourceId, /*name=*/
    null, /*description=*/
    null, fineGrainedBucket.getAttributes().getBucketName()));
    // Successfully update the referencing target because the {@code userWithFullAccess} has
    // access to the bucket with fine-grained access.
    GcsBucketUtils.updateGcsBucketReference(fullAccessApi, getWorkspaceId(), bucketResourceId, /*name=*/
    null, /*description=*/
    null, fineGrainedBucket.getAttributes().getBucketName());
    GcpGcsBucketResource bucketReferenceSecondUpdate = fullAccessApi.getBucketReference(getWorkspaceId(), bucketResourceId);
    assertEquals(newBucketName, bucketReferenceSecondUpdate.getMetadata().getName());
    assertEquals(newBucketDescription, bucketReferenceSecondUpdate.getMetadata().getDescription());
    assertEquals(fineGrainedBucket.getAttributes().getBucketName(), bucketReferenceSecondUpdate.getAttributes().getBucketName());
    // Update GCS bucket object's name and description
    String newBlobName = "newBlobName";
    String newBlobDescription = "a new description to the new bucket blob reference";
    GcsBucketUtils.updateGcsBucketObjectReference(fullAccessApi, getWorkspaceId(), fileResourceId, newBlobName, newBlobDescription, /*bucketName=*/
    null, /*objectName=*/
    null);
    GcpGcsObjectResource blobResource = fullAccessApi.getGcsObjectReference(getWorkspaceId(), fileResourceId);
    assertEquals(newBlobName, blobResource.getMetadata().getName());
    assertEquals(newBlobDescription, blobResource.getMetadata().getDescription());
    assertEquals(gcsFileAttributes.getBucketName(), blobResource.getAttributes().getBucketName());
    assertEquals(gcsFileAttributes.getFileName(), blobResource.getAttributes().getFileName());
    // Update GCS bucket object's referencing target from foo/monkey_sees_monkey_dos.txt to foo/.
    assertTrue(partialAccessResourceApi.checkReferenceAccess(getWorkspaceId(), fileResourceId));
    // Update object path only.
    // Attempt to update to foo but {@code userWithPartialAccess} does not have access to foo/
    assertThrows(ApiException.class, () -> GcsBucketUtils.updateGcsBucketObjectReference(partialAccessApi, getWorkspaceId(), fileResourceId, /*name=*/
    null, /*description=*/
    null, gcsFileAttributes.getBucketName(), gcsFolderAttributes.getFileName()));
    // User with access to foo/ can successfully update the referencing target to foo/.
    GcsBucketUtils.updateGcsBucketObjectReference(fullAccessApi, getWorkspaceId(), fileResourceId, /*name=*/
    null, /*description=*/
    null, /*bucketName=*/
    null, gcsFolderAttributes.getFileName());
    GcpGcsObjectResource blobReferenceSecondUpdate = fullAccessApi.getGcsObjectReference(getWorkspaceId(), fileResourceId);
    assertEquals(gcsFileAttributes.getBucketName(), blobReferenceSecondUpdate.getAttributes().getBucketName());
    assertEquals(gcsFolderAttributes.getFileName(), blobReferenceSecondUpdate.getAttributes().getFileName());
    assertEquals(newBlobName, blobReferenceSecondUpdate.getMetadata().getName());
    assertEquals(newBlobDescription, blobReferenceSecondUpdate.getMetadata().getDescription());
    // update bucket only.
    GcsBucketUtils.updateGcsBucketObjectReference(fullAccessApi, getWorkspaceId(), fileResourceId, /*name=*/
    null, /*description=*/
    null, /*bucketName=*/
    gcsUniformAccessBucketAttributes.getBucketName(), null);
    GcpGcsObjectResource blobReferenceThirdUpdate = fullAccessApi.getGcsObjectReference(getWorkspaceId(), fileResourceId);
    assertEquals(gcsUniformAccessBucketAttributes.getBucketName(), blobReferenceThirdUpdate.getAttributes().getBucketName());
    assertEquals(gcsFolderAttributes.getFileName(), blobReferenceThirdUpdate.getAttributes().getFileName());
    assertEquals(newBlobName, blobReferenceThirdUpdate.getMetadata().getName());
    assertEquals(newBlobDescription, blobReferenceThirdUpdate.getMetadata().getDescription());
    // Update both bucket and object path.
    GcsBucketUtils.updateGcsBucketObjectReference(fullAccessApi, getWorkspaceId(), fileResourceId, /*name=*/
    null, /*description=*/
    null, /*bucketName=*/
    gcsFileAttributes.getBucketName(), gcsFileAttributes.getFileName());
    GcpGcsObjectResource blobReferenceFourthUpdate = fullAccessApi.getGcsObjectReference(getWorkspaceId(), fileResourceId);
    assertEquals(gcsFileAttributes.getBucketName(), blobReferenceFourthUpdate.getAttributes().getBucketName());
    assertEquals(gcsFileAttributes.getFileName(), blobReferenceFourthUpdate.getAttributes().getFileName());
    assertEquals(newBlobName, blobReferenceFourthUpdate.getMetadata().getName());
    assertEquals(newBlobDescription, blobReferenceFourthUpdate.getMetadata().getDescription());
}
Also used : GcpGcsBucketResource(bio.terra.workspace.model.GcpGcsBucketResource) GcpGcsObjectResource(bio.terra.workspace.model.GcpGcsObjectResource) ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) ResourceApi(bio.terra.workspace.api.ResourceApi) ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi)

Example 2 with GcpGcsObjectResource

use of bio.terra.workspace.model.GcpGcsObjectResource in project terra-cli by DataBiosphere.

the class GcsObject method addReferenced.

/**
 * Add a GCS bucket object as a referenced resource in the workspace.
 *
 * @return the resource that was added
 */
public static GcsObject addReferenced(AddGcsObjectParams createParams) {
    validateEnvironmentVariableName(createParams.resourceFields.name);
    GcpGcsObjectResource addedResource = WorkspaceManagerService.fromContext().createReferencedGcsObject(Context.requireWorkspace().getId(), createParams);
    logger.info("Created GCS bucket object: {}", addedResource);
    // convert the WSM object to a CLI object
    Context.requireWorkspace().listResourcesAndSync();
    return new GcsObject(addedResource);
}
Also used : GcpGcsObjectResource(bio.terra.workspace.model.GcpGcsObjectResource) UFGcsObject(bio.terra.cli.serialization.userfacing.resource.UFGcsObject) PDGcsObject(bio.terra.cli.serialization.persisted.resource.PDGcsObject)

Example 3 with GcpGcsObjectResource

use of bio.terra.workspace.model.GcpGcsObjectResource in project terra-workspace-manager by DataBiosphere.

the class ReferencedGcsResourceLifecycle method doUserJourney.

@Override
protected void doUserJourney(TestUserSpecification testUser, WorkspaceApi workspaceApi) throws Exception {
    ReferencedGcpResourceApi referencedGcpResourceApi = ClientTestUtils.getReferencedGcpResourceClient(testUser, server);
    // Grant secondary users READER permission in the workspace.
    workspaceApi.grantRole(new GrantRoleRequestBody().memberEmail(partialAccessUser.userEmail), getWorkspaceId(), IamRole.READER);
    workspaceApi.grantRole(new GrantRoleRequestBody().memberEmail(noAccessUser.userEmail), getWorkspaceId(), IamRole.READER);
    // Create the references
    GcpGcsBucketResource referencedBucket = GcsBucketUtils.makeGcsBucketReference(gcsUniformAccessBucketAttributes, referencedGcpResourceApi, getWorkspaceId(), MultiResourcesUtils.makeName(), CloningInstructionsEnum.REFERENCE);
    bucketResourceId = referencedBucket.getMetadata().getResourceId();
    GcpGcsBucketResource fineGrainedBucket = GcsBucketUtils.makeGcsBucketReference(gcsFineGrainedAccessBucketAttributes, referencedGcpResourceApi, getWorkspaceId(), MultiResourcesUtils.makeName(), CloningInstructionsEnum.REFERENCE);
    fineGrainedBucketResourceId = fineGrainedBucket.getMetadata().getResourceId();
    GcpGcsObjectResource referencedGcsFile = GcsBucketObjectUtils.makeGcsObjectReference(gcsFileAttributes, referencedGcpResourceApi, getWorkspaceId(), MultiResourcesUtils.makeName(), CloningInstructionsEnum.REFERENCE);
    fileResourceId = referencedGcsFile.getMetadata().getResourceId();
    GcpGcsObjectResource referencedGcsFolder = GcsBucketObjectUtils.makeGcsObjectReference(gcsFolderAttributes, referencedGcpResourceApi, getWorkspaceId(), MultiResourcesUtils.makeName(), CloningInstructionsEnum.REFERENCE);
    folderResourceId = referencedGcsFolder.getMetadata().getResourceId();
    // Get the references
    testGetReferences(referencedBucket, fineGrainedBucket, referencedGcsFile, referencedGcsFolder, referencedGcpResourceApi);
    // Create a second workspace to clone references into, owned by the same user
    testCloneReference(referencedBucket, fineGrainedBucket, referencedGcsFile, referencedGcsFolder, referencedGcpResourceApi, workspaceApi);
    // Validate reference access
    testValidateReference(testUser);
    // Update the references
    testUpdateReferences(fineGrainedBucket, referencedGcpResourceApi);
    // Delete the references
    referencedGcpResourceApi.deleteBucketReference(getWorkspaceId(), bucketResourceId);
    referencedGcpResourceApi.deleteBucketReference(getWorkspaceId(), fineGrainedBucketResourceId);
    referencedGcpResourceApi.deleteGcsObjectReference(getWorkspaceId(), fileResourceId);
    referencedGcpResourceApi.deleteGcsObjectReference(getWorkspaceId(), folderResourceId);
    // Enumerating all resources with no filters should be empty
    ResourceApi resourceApi = ClientTestUtils.getResourceClient(testUser, server);
    ResourceList enumerateResult = resourceApi.enumerateResources(getWorkspaceId(), 0, 100, null, null);
    assertTrue(enumerateResult.getResources().isEmpty());
}
Also used : GcpGcsBucketResource(bio.terra.workspace.model.GcpGcsBucketResource) GcpGcsObjectResource(bio.terra.workspace.model.GcpGcsObjectResource) ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) ResourceApi(bio.terra.workspace.api.ResourceApi) ResourceList(bio.terra.workspace.model.ResourceList) GrantRoleRequestBody(bio.terra.workspace.model.GrantRoleRequestBody) ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi)

Example 4 with GcpGcsObjectResource

use of bio.terra.workspace.model.GcpGcsObjectResource in project terra-workspace-manager by DataBiosphere.

the class ReferencedGcsResourceLifecycle method testGetReferences.

private void testGetReferences(GcpGcsBucketResource uniformBucketReference, GcpGcsBucketResource fineGrainedBucketReference, GcpGcsObjectResource fileReference, GcpGcsObjectResource folderReference, ReferencedGcpResourceApi referencedGcpResourceApi) throws Exception {
    GcpGcsBucketResource fetchedBucket = referencedGcpResourceApi.getBucketReference(getWorkspaceId(), bucketResourceId);
    assertEquals(uniformBucketReference, fetchedBucket);
    GcpGcsBucketResource fetchedFineGrainedBucket = referencedGcpResourceApi.getBucketReference(getWorkspaceId(), fineGrainedBucketResourceId);
    assertEquals(fineGrainedBucketReference, fetchedFineGrainedBucket);
    GcpGcsObjectResource fetchedGcsFile = referencedGcpResourceApi.getGcsObjectReference(getWorkspaceId(), fileResourceId);
    assertEquals(fileReference, fetchedGcsFile);
    GcpGcsObjectResource fetchedGcsFolder = referencedGcpResourceApi.getGcsObjectReference(getWorkspaceId(), folderResourceId);
    assertEquals(folderReference, fetchedGcsFolder);
    // Enumerate the references
    // Any workspace member can view references in WSM, even if they can't view the underlying cloud
    // resource or contents.
    ResourceApi noAccessApi = ClientTestUtils.getResourceClient(noAccessUser, server);
    ResourceList referenceList = noAccessApi.enumerateResources(getWorkspaceId(), 0, 5, /*referenceType=*/
    null, StewardshipType.REFERENCED);
    assertEquals(4, referenceList.getResources().size());
    ResourceList bucketList = noAccessApi.enumerateResources(getWorkspaceId(), 0, 5, /*referenceType=*/
    ResourceType.GCS_BUCKET, StewardshipType.REFERENCED);
    assertEquals(2, bucketList.getResources().size());
    MultiResourcesUtils.assertResourceType(ResourceType.GCS_BUCKET, bucketList);
    ResourceList fileList = noAccessApi.enumerateResources(getWorkspaceId(), 0, 5, /*referenceType=*/
    ResourceType.GCS_OBJECT, StewardshipType.REFERENCED);
    assertEquals(2, fileList.getResources().size());
    MultiResourcesUtils.assertResourceType(ResourceType.GCS_OBJECT, fileList);
}
Also used : GcpGcsBucketResource(bio.terra.workspace.model.GcpGcsBucketResource) GcpGcsObjectResource(bio.terra.workspace.model.GcpGcsObjectResource) ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) ResourceApi(bio.terra.workspace.api.ResourceApi) ResourceList(bio.terra.workspace.model.ResourceList)

Aggregations

GcpGcsObjectResource (bio.terra.workspace.model.GcpGcsObjectResource)4 ReferencedGcpResourceApi (bio.terra.workspace.api.ReferencedGcpResourceApi)3 ResourceApi (bio.terra.workspace.api.ResourceApi)3 GcpGcsBucketResource (bio.terra.workspace.model.GcpGcsBucketResource)3 ResourceList (bio.terra.workspace.model.ResourceList)2 PDGcsObject (bio.terra.cli.serialization.persisted.resource.PDGcsObject)1 UFGcsObject (bio.terra.cli.serialization.userfacing.resource.UFGcsObject)1 GrantRoleRequestBody (bio.terra.workspace.model.GrantRoleRequestBody)1