Search in sources :

Example 1 with AccessScope

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

the class GcsBucketControlled method createWithAllOptionsExceptLifecycle.

@Test
@DisplayName("create a controlled bucket, specifying all options except lifecycle")
void createWithAllOptionsExceptLifecycle() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id`
    TestCommand.runCommandExpectSuccess("workspace", "set", "--id=" + getWorkspaceId());
    // `terra resources create gcs-bucket --name=$name --bucket-name=$bucketName --access=$access
    // --cloning=$cloning --description=$description --location=$location --storage=$storage
    // --format=json`
    String name = "createWithAllOptionsExceptLifecycle";
    String bucketName = UUID.randomUUID().toString();
    AccessScope access = AccessScope.PRIVATE_ACCESS;
    CloningInstructionsEnum cloning = CloningInstructionsEnum.REFERENCE;
    String description = "\"create with all options except lifecycle\"";
    String location = "US";
    GcsStorageClass storage = GcsStorageClass.NEARLINE;
    UFGcsBucket createdBucket = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "create", "gcs-bucket", "--name=" + name, "--bucket-name=" + bucketName, "--access=" + access, "--cloning=" + cloning, "--description=" + description, "--location=" + location, "--storage=" + storage);
    // check that the properties match
    assertEquals(name, createdBucket.name, "create output matches name");
    assertEquals(bucketName, createdBucket.bucketName, "create output matches bucket name");
    assertEquals(access, createdBucket.accessScope, "create output matches access");
    assertEquals(cloning, createdBucket.cloningInstructions, "create output matches cloning");
    assertEquals(description, createdBucket.description, "create output matches description");
    assertEquals(workspaceCreator.email.toLowerCase(), createdBucket.privateUserName.toLowerCase(), "create output matches private user name");
    Bucket createdBucketOnCloud = ExternalGCSBuckets.getStorageClient(workspaceCreator.getCredentialsWithCloudPlatformScope()).get(bucketName);
    assertNotNull(createdBucketOnCloud, "looking up bucket via GCS API succeeded");
    assertEquals(location, createdBucketOnCloud.getLocation(), "bucket location matches create input");
    assertEquals(storage.toString(), createdBucketOnCloud.getStorageClass().toString(), "bucket storage class matches create input");
    // `terra resources describe --name=$name --format=json`
    UFGcsBucket describeResource = TestCommand.runAndParseCommandExpectSuccess(UFGcsBucket.class, "resource", "describe", "--name=" + name);
    // check that the properties match
    assertEquals(name, describeResource.name, "describe resource output matches name");
    assertEquals(bucketName, describeResource.bucketName, "describe resource output matches bucket name");
    assertEquals(access, describeResource.accessScope, "describe output matches access");
    assertEquals(cloning, describeResource.cloningInstructions, "describe output matches cloning");
    assertEquals(description, describeResource.description, "describe output matches description");
    assertEquals(workspaceCreator.email.toLowerCase(), describeResource.privateUserName.toLowerCase(), "describe output matches private user name");
    // `terra resources delete --name=$name`
    TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + name, "--quiet");
}
Also used : CloningInstructionsEnum(bio.terra.workspace.model.CloningInstructionsEnum) GcsStorageClass(bio.terra.cli.serialization.userfacing.input.GcsStorageClass) Bucket(com.google.cloud.storage.Bucket) UFGcsBucket(bio.terra.cli.serialization.userfacing.resource.UFGcsBucket) AccessScope(bio.terra.workspace.model.AccessScope) UFGcsBucket(bio.terra.cli.serialization.userfacing.resource.UFGcsBucket) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Example 2 with AccessScope

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

the class BqDatasetControlled method createWithAllOptions.

@Test
@DisplayName("create a controlled dataset, specifying all options")
void createWithAllOptions() throws IOException {
    workspaceCreator.login();
    // `terra workspace set --id=$id --format=json`
    UFWorkspace workspace = TestCommand.runAndParseCommandExpectSuccess(UFWorkspace.class, "workspace", "set", "--id=" + getWorkspaceId());
    // `terra resources create bq-dataset --name=$name --dataset-id=$datasetId --access=$access
    // --cloning=$cloning --description=$description --location=$location --format=json`
    String name = "createWithAllOptions";
    String datasetId = randomDatasetId();
    AccessScope access = AccessScope.PRIVATE_ACCESS;
    CloningInstructionsEnum cloning = CloningInstructionsEnum.DEFINITION;
    String description = "\"create with all options\"";
    String location = "us-east1";
    UFBqDataset createdDataset = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "create", "bq-dataset", "--name=" + name, "--dataset-id=" + datasetId, "--access=" + access, "--cloning=" + cloning, "--description=" + description, "--location=" + location);
    // check that the properties match
    assertEquals(name, createdDataset.name, "create output matches name");
    assertEquals(workspace.googleProjectId, createdDataset.projectId, "create output matches project id");
    assertEquals(datasetId, createdDataset.datasetId, "create output matches dataset id");
    assertEquals(access, createdDataset.accessScope, "create output matches access");
    assertEquals(cloning, createdDataset.cloningInstructions, "create output matches cloning");
    assertEquals(description, createdDataset.description, "create output matches description");
    assertEquals(workspaceCreator.email.toLowerCase(), createdDataset.privateUserName.toLowerCase(), "create output matches private user name");
    Dataset createdDatasetOnCloud = ExternalBQDatasets.getBQClient(workspaceCreator.getCredentialsWithCloudPlatformScope()).getDataset(DatasetId.of(workspace.googleProjectId, datasetId));
    assertNotNull(createdDatasetOnCloud, "looking up dataset via BQ API succeeded");
    assertEquals(location, createdDatasetOnCloud.getLocation(), "dataset location matches create input");
    // `terra resources describe --name=$name --format=json`
    UFBqDataset describeResource = TestCommand.runAndParseCommandExpectSuccess(UFBqDataset.class, "resource", "describe", "--name=" + name);
    // check that the properties match
    assertEquals(name, describeResource.name, "describe resource output matches name");
    assertEquals(datasetId, describeResource.datasetId, "describe resource output matches dataset id");
    assertEquals(access, describeResource.accessScope, "describe output matches access");
    assertEquals(cloning, describeResource.cloningInstructions, "describe output matches cloning");
    assertEquals(description, describeResource.description, "describe output matches description");
    assertEquals(workspaceCreator.email.toLowerCase(), describeResource.privateUserName.toLowerCase(), "describe output matches private user name");
    // `terra resources delete --name=$name`
    TestCommand.runCommandExpectSuccess("resource", "delete", "--name=" + name, "--quiet");
}
Also used : CloningInstructionsEnum(bio.terra.workspace.model.CloningInstructionsEnum) UFBqDataset(bio.terra.cli.serialization.userfacing.resource.UFBqDataset) UFBqDataset(bio.terra.cli.serialization.userfacing.resource.UFBqDataset) Dataset(com.google.cloud.bigquery.Dataset) UFWorkspace(bio.terra.cli.serialization.userfacing.UFWorkspace) AccessScope(bio.terra.workspace.model.AccessScope) Test(org.junit.jupiter.api.Test) DisplayName(org.junit.jupiter.api.DisplayName)

Aggregations

AccessScope (bio.terra.workspace.model.AccessScope)2 CloningInstructionsEnum (bio.terra.workspace.model.CloningInstructionsEnum)2 DisplayName (org.junit.jupiter.api.DisplayName)2 Test (org.junit.jupiter.api.Test)2 UFWorkspace (bio.terra.cli.serialization.userfacing.UFWorkspace)1 GcsStorageClass (bio.terra.cli.serialization.userfacing.input.GcsStorageClass)1 UFBqDataset (bio.terra.cli.serialization.userfacing.resource.UFBqDataset)1 UFGcsBucket (bio.terra.cli.serialization.userfacing.resource.UFGcsBucket)1 Dataset (com.google.cloud.bigquery.Dataset)1 Bucket (com.google.cloud.storage.Bucket)1