Search in sources :

Example 1 with UFGcsObject

use of bio.terra.cli.serialization.userfacing.resource.UFGcsObject in project terra-cli by DataBiosphere.

the class GcsObject method execute.

/**
 * Update a bucket object in the workspace.
 */
@Override
protected void execute() {
    workspaceOption.overrideIfSpecified();
    // all update parameters are optional, but make sure at least one is specified
    if (!resourceUpdateOptions.isDefined() && newObjectName == null && newBucketName.getNewBucketName() == null) {
        throw new UserActionableException("Specify at least one property to update.");
    }
    // get the resource and make sure it's the right type
    bio.terra.cli.businessobject.resource.GcsObject resource = Context.requireWorkspace().getResource(resourceUpdateOptions.resourceNameOption.name).castToType(Resource.Type.GCS_OBJECT);
    UpdateResourceParams updateResourceParams = resourceUpdateOptions.populateMetadataFields().build();
    UpdateReferencedGcsObjectParams gcsObjectParams = new UpdateReferencedGcsObjectParams.Builder().resourceFields(updateResourceParams).bucketName(newBucketName.getNewBucketName()).objectName(newObjectName).build();
    resource.updateReferenced(gcsObjectParams);
    formatOption.printReturnValue(new UFGcsObject(resource), GcsObject::printText);
}
Also used : UFGcsObject(bio.terra.cli.serialization.userfacing.resource.UFGcsObject) UFGcsObject(bio.terra.cli.serialization.userfacing.resource.UFGcsObject) UserActionableException(bio.terra.cli.exception.UserActionableException) UpdateReferencedGcsObjectParams(bio.terra.cli.serialization.userfacing.input.UpdateReferencedGcsObjectParams) UpdateResourceParams(bio.terra.cli.serialization.userfacing.input.UpdateResourceParams) WorkspaceOverride(bio.terra.cli.command.shared.options.WorkspaceOverride)

Example 2 with UFGcsObject

use of bio.terra.cli.serialization.userfacing.resource.UFGcsObject in project terra-cli by DataBiosphere.

the class FineGrainedAccessGcsObjectReference method addRefWithPartialAccess.

@Test
@DisplayName("user with partial access attempt to add reference to bucket objects")
void addRefWithPartialAccess() throws IOException {
    workspaceCreator.login();
    UFWorkspace createWorkspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "create");
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + createWorkspace.id);
    // shareeUser needs WRITER level access to add reference resources.
    // `terra workspace add-user --email=$email --role=WRITER`
    TestCommand.runCommandExpectSuccess("workspace", "add-user", "--email=" + shareeUser.email, "--role=WRITER");
    shareeUser.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + createWorkspace.id);
    // `terra resource add-ref gcs-object --name=$name --bucket-name=$bucketName
    // --object-name=$objectName`
    String noAccessBlobName = "addRefToBucketBlobNoAccess";
    TestCommand.runCommandExpectExitCode(2, "resource", "add-ref", "gcs-object", "--name=" + noAccessBlobName, "--bucket-name=" + externalBucket.getName(), "--object-name=" + privateExternalBlobName);
    String withAccessBlobName = "addRefToBucketBlobWithAccess";
    TestCommand.runCommandExpectSuccess("resource", "add-ref", "gcs-object", "--name=" + withAccessBlobName, "--bucket-name=" + externalBucket.getName(), "--object-name=" + sharedExternalBlobName);
    String bucketRefName = "addRefToBucketWithoutAccess";
    TestCommand.runCommandExpectExitCode(2, "resource", "add-ref", "gcs-bucket", "--name=" + bucketRefName, "--bucket-name=" + externalBucket.getName());
    // check that the object is in the list
    List<UFGcsObject> matchedResourceList = listObjectResourceWithName(withAccessBlobName);
    assertEquals(1, matchedResourceList.size());
    // `terra resource delete --name=$name`
    TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + withAccessBlobName, "--quiet");
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + createWorkspace.id);
    // `terra workspace delete`
    TestCommand.runCommandExpectSuccess("workspace", "delete", "--quiet");
}
Also used : UFGcsObject(bio.terra.cli.serialization.userfacing.resource.UFGcsObject) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 3 with UFGcsObject

use of bio.terra.cli.serialization.userfacing.resource.UFGcsObject in project terra-cli by DataBiosphere.

the class FineGrainedAccessGcsObjectReference method addObjectReferenceWithBucketLevelAccess.

@Test
@DisplayName("add reference to a bucket object that the user has bucket-level access to")
void addObjectReferenceWithBucketLevelAccess() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
    // `terra resource add-ref gcs-object --name=$name --bucket-name=$bucketName
    // --object-name=$objectName`
    String name = "addObjectReferenceWithAccess";
    UFGcsObject addedBucketObjectReference = TestCommand.runAndParseCommandExpectSuccess(UFGcsObject.class, "resource", "add-ref", "gcs-object", "--name=" + name, "--bucket-name=" + externalBucket.getName(), "--object-name=" + privateExternalBlobName);
    // check that the name and bucket name match
    assertEquals(name, addedBucketObjectReference.name, "add ref output matches name");
    assertEquals(externalBucket.getName(), addedBucketObjectReference.bucketName, "add ref output matches bucket name");
    assertEquals(privateExternalBlobName, addedBucketObjectReference.objectName, "add ref output matches bucket object name");
    // `terra resource describe --name=$name --format=json`
    UFGcsObject describeResource = TestCommand.runAndParseCommandExpectSuccess(UFGcsObject.class, "resource", "describe", "--name=" + name);
    // check that the name and bucket name match
    assertEquals(name, describeResource.name, "describe resource output matches name");
    assertEquals(externalBucket.getName(), describeResource.bucketName, "describe resource output matches bucket name");
    assertEquals(privateExternalBlobName, describeResource.objectName, "describe resource output matches object name");
    // `terra resource delete --name=$name`
    TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + name, "--quiet");
}
Also used : UFGcsObject(bio.terra.cli.serialization.userfacing.resource.UFGcsObject) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 4 with UFGcsObject

use of bio.terra.cli.serialization.userfacing.resource.UFGcsObject in project terra-cli by DataBiosphere.

the class FineGrainedAccessGcsObjectReference method updateObjectReferenceWithBucketLevelAccess.

@Test
@DisplayName("user with bucket level access updates object reference")
void updateObjectReferenceWithBucketLevelAccess() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
    // `terra resource add-ref gcs-object --name=$name --bucket-name=$bucketName
    // --object-name=$objectName`
    String name = "updateObjectReferenceWithBucketLevelAccess";
    TestCommand.runCommandExpectSuccess("resource", "add-ref", "gcs-object", "--name=" + name, "--bucket-name=" + externalBucket.getName(), "--object-name=" + privateExternalBlobName);
    String newName = RandomStringUtils.random(6, /*letters=*/
    true, /*numbers=*/
    true);
    String newDescription = "yetAnotherDescription";
    TestCommand.runCommandExpectSuccess("resource", "update", "gcs-object", "--name=" + name, "--new-name=" + newName, "--description=" + newDescription, "--new-bucket-name=" + externalBucket.getName(), "--new-object-name=" + sharedExternalBlobName);
    // `terra resource describe --name=$name --format=json`
    UFGcsObject describeResource = TestCommand.runAndParseCommandExpectSuccess(UFGcsObject.class, "resource", "describe", "--name=" + newName);
    assertEquals(newName, describeResource.name);
    assertEquals(newDescription, describeResource.description);
    assertEquals(externalBucket.getName(), describeResource.bucketName);
    assertEquals(sharedExternalBlobName, describeResource.objectName);
    // `terra resource delete --name=$name`
    TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + newName, "--quiet");
}
Also used : UFGcsObject(bio.terra.cli.serialization.userfacing.resource.UFGcsObject) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 5 with UFGcsObject

use of bio.terra.cli.serialization.userfacing.resource.UFGcsObject in project terra-cli by DataBiosphere.

the class FineGrainedAccessGcsObjectReference method describeObjectReferenceWhenUserHasBucketLevelAccess.

@Test
@DisplayName("describe the reference to a bucket object that the user has bucket level access to")
void describeObjectReferenceWhenUserHasBucketLevelAccess() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
    // `terra resource add-ref gcs-object --name=$name --bucket-name=$bucketName
    // --object-name=$objectName`
    String name = "describeObjectReferenceWithAccess";
    TestCommand.runAndParseCommandExpectSuccess(UFGcsObject.class, "resource", "add-ref", "gcs-object", "--name=" + name, "--bucket-name=" + externalBucket.getName(), "--object-name=" + sharedExternalBlobName);
    // `terra resource describe --name=$name --format=json`
    UFGcsObject describeResource = TestCommand.runAndParseCommandExpectSuccess(UFGcsObject.class, "resource", "describe", "--name=" + name);
    // check that the name and bucket name match
    assertEquals(name, describeResource.name, "describe resource output matches name");
    assertEquals(externalBucket.getName(), describeResource.bucketName, "describe resource output matches bucket name");
    assertEquals(sharedExternalBlobName, describeResource.objectName, "describe resource output matches object name");
    assertEquals(sharedBlob.getSize(), describeResource.size, "describe resource output matches object size");
    assertEquals(sharedBlob.isDirectory(), describeResource.isDirectory, "describe resource output matches object boolean isDirectory");
    assertEquals(sharedBlob.getUpdateTime(), describeResource.timeStorageClassUpdated, "describe resource output matches object last storage update time");
    assertEquals(sharedBlob.getContentType(), describeResource.contentType, "describe resource output matches object content type");
    // `terra resource delete --name=$name`
    TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + name, "--quiet");
}
Also used : UFGcsObject(bio.terra.cli.serialization.userfacing.resource.UFGcsObject) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

UFGcsObject (bio.terra.cli.serialization.userfacing.resource.UFGcsObject)13 DisplayName (org.junit.jupiter.api.DisplayName)11 Test (org.junit.jupiter.api.Test)11 UFWorkspace (bio.terra.cli.serialization.userfacing.UFWorkspace)3 WorkspaceOverride (bio.terra.cli.command.shared.options.WorkspaceOverride)2 UserActionableException (bio.terra.cli.exception.UserActionableException)1 AddGcsObjectParams (bio.terra.cli.serialization.userfacing.input.AddGcsObjectParams)1 CreateResourceParams (bio.terra.cli.serialization.userfacing.input.CreateResourceParams)1 UpdateReferencedGcsObjectParams (bio.terra.cli.serialization.userfacing.input.UpdateReferencedGcsObjectParams)1 UpdateResourceParams (bio.terra.cli.serialization.userfacing.input.UpdateResourceParams)1 CloningInstructionsEnum (bio.terra.workspace.model.CloningInstructionsEnum)1