Search in sources :

Example 6 with ReferencedGcpResourceApi

use of bio.terra.workspace.api.ReferencedGcpResourceApi in project terra-workspace-manager by DataBiosphere.

the class ReferencedDataRepoSnapshotLifecycle method doUserJourney.

@Override
protected void doUserJourney(TestUserSpecification testUser, WorkspaceApi workspaceApi) throws Exception {
    ReferencedGcpResourceApi referencedGcpResourceApi = ClientTestUtils.getReferencedGcpResourceClient(testUser, server);
    // Add the "partial access" user as a workspace reader. This does not give them access to any
    // underlying referenced resources.
    workspaceApi.grantRole(new GrantRoleRequestBody().memberEmail(partialAccessUser.userEmail), getWorkspaceId(), IamRole.READER);
    // Create the reference
    DataRepoSnapshotResource snapshotResource = DataRepoUtils.makeDataRepoSnapshotReference(referencedGcpResourceApi, getWorkspaceId(), MultiResourcesUtils.makeName(), snapshotId, tdrInstance);
    snapshotResourceId = snapshotResource.getMetadata().getResourceId();
    // Get the reference
    ResourceApi resourceApi = ClientTestUtils.getResourceClient(testUser, server);
    testGetReference(snapshotResource, referencedGcpResourceApi, resourceApi);
    // Create a second workspace to clone the reference into, owned by the same user
    testCloneReference(snapshotResource, referencedGcpResourceApi, workspaceApi);
    // Validate snapshot access
    testValidateReference(testUser);
    // Update reference
    testUpdateReference(referencedGcpResourceApi);
    // Delete the reference
    referencedGcpResourceApi.deleteDataRepoSnapshotReference(getWorkspaceId(), snapshotResourceId);
    // Enumerating all resources with no filters should be empty
    ResourceList enumerateResult = resourceApi.enumerateResources(getWorkspaceId(), 0, 100, null, null);
    assertTrue(enumerateResult.getResources().isEmpty());
}
Also used : 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) DataRepoSnapshotResource(bio.terra.workspace.model.DataRepoSnapshotResource)

Example 7 with ReferencedGcpResourceApi

use of bio.terra.workspace.api.ReferencedGcpResourceApi in project terra-workspace-manager by DataBiosphere.

the class EnumerateJobs method doSetup.

@Override
public void doSetup(List<TestUserSpecification> testUsers, WorkspaceApi workspaceApi) throws Exception {
    // initialize workspace
    super.doSetup(testUsers, workspaceApi);
    TestUserSpecification workspaceOwner = testUsers.get(0);
    // If we like the alpha1 API for job enumeration, then we can maybe piggyback on
    // the EnumerateResources test instead of creating our own set.
    ApiClient ownerApiClient = ClientTestUtils.getClientForTestUser(workspaceOwner, server);
    ownerControlledGcpResourceApi = new ControlledGcpResourceApi(ownerApiClient);
    ownerReferencedGcpResourceApi = new ReferencedGcpResourceApi(ownerApiClient);
    alpha1Api = new Alpha1Api(ownerApiClient);
    // Create a cloud context for the workspace
    CloudContextMaker.createGcpCloudContext(getWorkspaceId(), workspaceApi);
    // create the resources for the test
    logger.info("Creating {} resources", RESOURCE_COUNT);
    resourceList = MultiResourcesUtils.makeResources(ownerReferencedGcpResourceApi, ownerControlledGcpResourceApi, getWorkspaceId());
    logger.info("Created {} resources", resourceList.size());
    logger.info("Cleaning up {} resources", resourceList.size());
    MultiResourcesUtils.cleanupResources(resourceList, ownerControlledGcpResourceApi, getWorkspaceId());
    logger.info("Cleaned up {} resources", resourceList.size());
}
Also used : ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) Alpha1Api(bio.terra.workspace.api.Alpha1Api) ControlledGcpResourceApi(bio.terra.workspace.api.ControlledGcpResourceApi) TestUserSpecification(bio.terra.testrunner.runner.config.TestUserSpecification) ApiClient(bio.terra.workspace.client.ApiClient)

Example 8 with ReferencedGcpResourceApi

use of bio.terra.workspace.api.ReferencedGcpResourceApi in project terra-workspace-manager by DataBiosphere.

the class DeleteGcpContextWithControlledResource method doUserJourney.

@Override
protected void doUserJourney(TestUserSpecification testUser, WorkspaceApi workspaceApi) throws Exception {
    ControlledGcpResourceApi controlledResourceApi = ClientTestUtils.getControlledGcpResourceClient(testUser, server);
    ReferencedGcpResourceApi referencedResourceApi = ClientTestUtils.getReferencedGcpResourceClient(testUser, server);
    // Create a cloud context
    String projectId = CloudContextMaker.createGcpCloudContext(getWorkspaceId(), workspaceApi);
    logger.info("Created project {}", projectId);
    // Create a controlled BigQuery dataset
    GcpBigQueryDatasetResource controlledDataset = BqDatasetUtils.makeControlledBigQueryDatasetUserShared(controlledResourceApi, getWorkspaceId(), DATASET_RESOURCE_NAME, null, null);
    UUID controlledResourceId = controlledDataset.getMetadata().getResourceId();
    logger.info("Created controlled dataset {}", controlledResourceId);
    // Confirm the dataset was created in WSM
    GcpBigQueryDatasetResource fetchedControlledDataset = controlledResourceApi.getBigQueryDataset(getWorkspaceId(), controlledResourceId);
    assertEquals(controlledDataset, fetchedControlledDataset);
    // Create a reference to the controlled resource we just created
    String referenceName = "my-resource-name-" + UUID.randomUUID().toString();
    GcpBigQueryDatasetResource referencedDataset = BqDatasetUtils.makeBigQueryDatasetReference(controlledDataset.getAttributes(), referencedResourceApi, getWorkspaceId(), referenceName);
    // Confirm the reference was created in WSM
    GcpBigQueryDatasetResource fetchedDatasetReference = referencedResourceApi.getBigQueryDatasetReference(getWorkspaceId(), referencedDataset.getMetadata().getResourceId());
    assertEquals(referencedDataset, fetchedDatasetReference);
    // Delete the context, which should delete the controlled resource but not the reference.
    CloudContextMaker.deleteGcpCloudContext(getWorkspaceId(), workspaceApi);
    // Confirm the controlled resource was deleted.
    var noGcpContextException = assertThrows(ApiException.class, () -> controlledResourceApi.getBigQueryDataset(getWorkspaceId(), controlledResourceId));
    assertEquals(HttpStatus.SC_NOT_FOUND, noGcpContextException.getCode());
    // Confirm the referenced resource was not deleted (even though the underlying cloud resource
    // was).
    GcpBigQueryDatasetResource datasetReferenceAfterDelete = referencedResourceApi.getBigQueryDatasetReference(getWorkspaceId(), referencedDataset.getMetadata().getResourceId());
    assertEquals(referencedDataset, datasetReferenceAfterDelete);
}
Also used : ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) ControlledGcpResourceApi(bio.terra.workspace.api.ControlledGcpResourceApi) UUID(java.util.UUID) GcpBigQueryDatasetResource(bio.terra.workspace.model.GcpBigQueryDatasetResource)

Example 9 with ReferencedGcpResourceApi

use of bio.terra.workspace.api.ReferencedGcpResourceApi in project terra-workspace-manager by DataBiosphere.

the class ReferencedBigQueryResourceLifecycle method testUpdateReferences.

private void testUpdateReferences(GcpBigQueryDatasetResource dataset, GcpBigQueryDataTableResource table, ReferencedGcpResourceApi fullAccessApi) throws Exception {
    ReferencedGcpResourceApi partialAccessApi = ClientTestUtils.getReferencedGcpResourceClient(partialAccessUser, server);
    ResourceApi partialAccessResourceApi = ClientTestUtils.getResourceClient(partialAccessUser, server);
    UUID bqDatasetResourceId = dataset.getMetadata().getResourceId();
    UUID bqTableResourceId = table.getMetadata().getResourceId();
    // Update BQ dataset's name and description
    String newDatasetName = "newDatasetName";
    String newDatasetDescription = "newDescription";
    BqDatasetUtils.updateBigQueryDatasetReference(fullAccessApi, getWorkspaceId(), bqDatasetResourceId, newDatasetName, newDatasetDescription, /*projectId=*/
    null, /*datasetId=*/
    null);
    GcpBigQueryDatasetResource datasetReferenceFirstUpdate = fullAccessApi.getBigQueryDatasetReference(getWorkspaceId(), bqDatasetResourceId);
    assertEquals(newDatasetName, datasetReferenceFirstUpdate.getMetadata().getName());
    assertEquals(newDatasetDescription, datasetReferenceFirstUpdate.getMetadata().getDescription());
    assertEquals(referencedBqTableAttributes.getDatasetId(), datasetReferenceFirstUpdate.getAttributes().getDatasetId());
    assertEquals(referencedBqTableAttributes.getProjectId(), datasetReferenceFirstUpdate.getAttributes().getProjectId());
    // {@code userWithPartialAccess} does not have access to the original dataset.
    assertFalse(partialAccessResourceApi.checkReferenceAccess(getWorkspaceId(), bqDatasetResourceId));
    // Update BQ dataset's referencing target
    // Attempt to update the referencing target but {@code userWithPartialAccess} does not have
    // access to the original dataset.
    assertThrows(ApiException.class, () -> BqDatasetUtils.updateBigQueryDatasetReference(partialAccessApi, getWorkspaceId(), bqDatasetResourceId, /*name=*/
    null, /*description=*/
    null, /*projectId=*/
    null, bqTableFromAlternateDatasetAttributes.getDatasetId()));
    BqDatasetUtils.updateBigQueryDatasetReference(fullAccessApi, getWorkspaceId(), bqDatasetResourceId, /*name=*/
    null, /*description=*/
    null, /*projectId=*/
    null, bqTableFromAlternateDatasetAttributes.getDatasetId());
    GcpBigQueryDatasetResource datasetReferenceSecondUpdate = fullAccessApi.getBigQueryDatasetReference(getWorkspaceId(), bqDatasetResourceId);
    assertEquals(newDatasetName, datasetReferenceSecondUpdate.getMetadata().getName());
    assertEquals(newDatasetDescription, datasetReferenceSecondUpdate.getMetadata().getDescription());
    assertEquals(table.getAttributes().getProjectId(), datasetReferenceSecondUpdate.getAttributes().getProjectId());
    assertEquals(bqTableFromAlternateDatasetAttributes.getDatasetId(), datasetReferenceSecondUpdate.getAttributes().getDatasetId());
    // {@code userWithPartialAccess} have access to dataset 2. Now since the reference is pointing
    // to dataset 2, the user have access to this reference now.
    assertTrue(partialAccessResourceApi.checkReferenceAccess(getWorkspaceId(), bqDatasetResourceId));
    // Update BQ data table's name and description.
    String newDataTableName = "newDataTableName";
    String newDataTableDescription = "a new description to the new data table reference";
    BqDataTableUtils.updateBigQueryDataTableReference(fullAccessApi, getWorkspaceId(), bqTableResourceId, newDataTableName, newDataTableDescription, /*projectId=*/
    null, /*datasetId=*/
    null, /*tableId=*/
    null);
    GcpBigQueryDataTableResource dataTableReferenceFirstUpdate = fullAccessApi.getBigQueryDataTableReference(getWorkspaceId(), bqTableResourceId);
    assertEquals(newDataTableName, dataTableReferenceFirstUpdate.getMetadata().getName());
    assertEquals(newDataTableDescription, dataTableReferenceFirstUpdate.getMetadata().getDescription());
    assertEquals(table.getAttributes().getProjectId(), dataTableReferenceFirstUpdate.getAttributes().getProjectId());
    assertEquals(table.getAttributes().getDatasetId(), dataTableReferenceFirstUpdate.getAttributes().getDatasetId());
    assertEquals(table.getAttributes().getDataTableId(), dataTableReferenceFirstUpdate.getAttributes().getDataTableId());
    // Update bq data table target
    // Attempt to update bq data table reference but {@code userWithPartialAccess} does not have
    // access to the bq table 2.
    assertThrows(ApiException.class, () -> BqDataTableUtils.updateBigQueryDataTableReference(partialAccessApi, getWorkspaceId(), bqTableResourceId, /*name=*/
    null, /*description=*/
    null, /*projectId=*/
    null, bqTableFromAlternateDatasetAttributes.getDatasetId(), bqTableFromAlternateDatasetAttributes.getDataTableId()));
    // Successfully update the referencing target because the {@code userWithFullAccess} has
    // access to the bq table 2.
    BqDataTableUtils.updateBigQueryDataTableReference(fullAccessApi, getWorkspaceId(), bqTableResourceId, /*name=*/
    null, /*description=*/
    null, /*projectId=*/
    null, bqTableFromAlternateDatasetAttributes.getDatasetId(), bqTableFromAlternateDatasetAttributes.getDataTableId());
    GcpBigQueryDataTableResource dataTableReferenceSecondUpdate = fullAccessApi.getBigQueryDataTableReference(getWorkspaceId(), bqTableResourceId);
    assertEquals(newDataTableName, dataTableReferenceSecondUpdate.getMetadata().getName());
    assertEquals(newDataTableDescription, dataTableReferenceSecondUpdate.getMetadata().getDescription());
    assertEquals(table.getAttributes().getProjectId(), dataTableReferenceSecondUpdate.getAttributes().getProjectId());
    assertEquals(bqTableFromAlternateDatasetAttributes.getDatasetId(), dataTableReferenceSecondUpdate.getAttributes().getDatasetId());
    assertEquals(bqTableFromAlternateDatasetAttributes.getDataTableId(), dataTableReferenceSecondUpdate.getAttributes().getDataTableId());
    BqDataTableUtils.updateBigQueryDataTableReference(fullAccessApi, getWorkspaceId(), bqTableResourceId, /*name=*/
    null, /*description=*/
    null, /*projectId=*/
    null, table.getAttributes().getDatasetId(), /*tableId=*/
    null);
    GcpBigQueryDataTableResource dataTableReferenceThirdUpdate = fullAccessApi.getBigQueryDataTableReference(getWorkspaceId(), bqTableResourceId);
    assertEquals(newDataTableName, dataTableReferenceThirdUpdate.getMetadata().getName());
    assertEquals(newDataTableDescription, dataTableReferenceThirdUpdate.getMetadata().getDescription());
    assertEquals(table.getAttributes().getProjectId(), dataTableReferenceThirdUpdate.getAttributes().getProjectId());
    assertEquals(table.getAttributes().getDatasetId(), dataTableReferenceThirdUpdate.getAttributes().getDatasetId());
    assertEquals(bqTableFromAlternateDatasetAttributes.getDataTableId(), dataTableReferenceThirdUpdate.getAttributes().getDataTableId());
    BqDataTableUtils.updateBigQueryDataTableReference(fullAccessApi, getWorkspaceId(), bqTableResourceId, /*name=*/
    null, /*description=*/
    null, /*projectId=*/
    null, /*datasetId=*/
    null, table.getAttributes().getDataTableId());
    GcpBigQueryDataTableResource dataTableReferenceFourthUpdate = fullAccessApi.getBigQueryDataTableReference(getWorkspaceId(), bqTableResourceId);
    assertEquals(newDataTableName, dataTableReferenceFourthUpdate.getMetadata().getName());
    assertEquals(newDataTableDescription, dataTableReferenceFourthUpdate.getMetadata().getDescription());
    assertEquals(table.getAttributes().getProjectId(), dataTableReferenceFourthUpdate.getAttributes().getProjectId());
    assertEquals(table.getAttributes().getDatasetId(), dataTableReferenceFourthUpdate.getAttributes().getDatasetId());
    assertEquals(table.getAttributes().getDataTableId(), dataTableReferenceFourthUpdate.getAttributes().getDataTableId());
}
Also used : ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) ResourceApi(bio.terra.workspace.api.ResourceApi) ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) GcpBigQueryDataTableResource(bio.terra.workspace.model.GcpBigQueryDataTableResource) UUID(java.util.UUID) GcpBigQueryDatasetResource(bio.terra.workspace.model.GcpBigQueryDatasetResource)

Example 10 with ReferencedGcpResourceApi

use of bio.terra.workspace.api.ReferencedGcpResourceApi in project terra-workspace-manager by DataBiosphere.

the class ReferencedBigQueryResourceLifecycle method testGetReferences.

private void testGetReferences(GcpBigQueryDatasetResource referencedDataset, GcpBigQueryDataTableResource referencedDataTable, ReferencedGcpResourceApi referencedGcpResourceApi) throws Exception {
    // Get the references
    GcpBigQueryDatasetResource fetchedDataset = referencedGcpResourceApi.getBigQueryDatasetReference(getWorkspaceId(), bqDatasetResourceId);
    assertEquals(referencedDataset, fetchedDataset);
    GcpBigQueryDataTableResource fetchedDataTable = referencedGcpResourceApi.getBigQueryDataTableReference(getWorkspaceId(), bqDataTableResourceId);
    assertEquals(referencedDataTable, fetchedDataTable);
    // 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(2, referenceList.getResources().size());
    ResourceList datasetList = noAccessApi.enumerateResources(getWorkspaceId(), 0, 5, /*referenceType=*/
    ResourceType.BIG_QUERY_DATASET, StewardshipType.REFERENCED);
    assertEquals(1, datasetList.getResources().size());
    MultiResourcesUtils.assertResourceType(ResourceType.BIG_QUERY_DATASET, datasetList);
    ResourceList tableList = noAccessApi.enumerateResources(getWorkspaceId(), 0, 5, /*referenceType=*/
    ResourceType.BIG_QUERY_DATA_TABLE, StewardshipType.REFERENCED);
    assertEquals(1, tableList.getResources().size());
    MultiResourcesUtils.assertResourceType(ResourceType.BIG_QUERY_DATA_TABLE, tableList);
}
Also used : ReferencedGcpResourceApi(bio.terra.workspace.api.ReferencedGcpResourceApi) ResourceApi(bio.terra.workspace.api.ResourceApi) ResourceList(bio.terra.workspace.model.ResourceList) GcpBigQueryDataTableResource(bio.terra.workspace.model.GcpBigQueryDataTableResource) GcpBigQueryDatasetResource(bio.terra.workspace.model.GcpBigQueryDatasetResource)

Aggregations

ReferencedGcpResourceApi (bio.terra.workspace.api.ReferencedGcpResourceApi)18 ResourceApi (bio.terra.workspace.api.ResourceApi)10 ResourceList (bio.terra.workspace.model.ResourceList)6 ControlledGcpResourceApi (bio.terra.workspace.api.ControlledGcpResourceApi)4 GcpBigQueryDatasetResource (bio.terra.workspace.model.GcpBigQueryDatasetResource)4 GrantRoleRequestBody (bio.terra.workspace.model.GrantRoleRequestBody)4 TestUserSpecification (bio.terra.testrunner.runner.config.TestUserSpecification)3 GcpBigQueryDataTableResource (bio.terra.workspace.model.GcpBigQueryDataTableResource)3 GcpGcsBucketResource (bio.terra.workspace.model.GcpGcsBucketResource)3 GcpGcsObjectResource (bio.terra.workspace.model.GcpGcsObjectResource)3 ApiClient (bio.terra.workspace.client.ApiClient)2 DataRepoSnapshotResource (bio.terra.workspace.model.DataRepoSnapshotResource)2 UUID (java.util.UUID)2 Alpha1Api (bio.terra.workspace.api.Alpha1Api)1 GcpBigQueryDataTableAttributes (bio.terra.workspace.model.GcpBigQueryDataTableAttributes)1 GcpGcsObjectAttributes (bio.terra.workspace.model.GcpGcsObjectAttributes)1 GitRepoResource (bio.terra.workspace.model.GitRepoResource)1 UpdateBigQueryDataTableReferenceRequestBody (bio.terra.workspace.model.UpdateBigQueryDataTableReferenceRequestBody)1 UpdateBigQueryDatasetReferenceRequestBody (bio.terra.workspace.model.UpdateBigQueryDatasetReferenceRequestBody)1 UpdateGcsBucketObjectReferenceRequestBody (bio.terra.workspace.model.UpdateGcsBucketObjectReferenceRequestBody)1