use of bio.terra.workspace.client.ApiClient in project terra-workspace-manager by DataBiosphere.
the class ControlledApplicationSharedGcsBucketLifecycle method doUserJourney.
@Override
public void doUserJourney(TestUserSpecification unused, WorkspaceApi workspaceApi) throws Exception {
ApiClient ownerApiClient = ClientTestUtils.getClientForTestUser(owner, server);
ApiClient wsmappApiClient = ClientTestUtils.getClientForTestUser(wsmapp, server);
WorkspaceApplicationApi ownerWsmAppApi = new WorkspaceApplicationApi(ownerApiClient);
ControlledGcpResourceApi wsmappResourceApi = new ControlledGcpResourceApi(wsmappApiClient);
// Owner adds a reader and a writer to the workspace
workspaceApi.grantRole(new GrantRoleRequestBody().memberEmail(reader.userEmail), getWorkspaceId(), IamRole.READER);
logger.info("Added {} as a reader to workspace {}", reader.userEmail, getWorkspaceId());
workspaceApi.grantRole(new GrantRoleRequestBody().memberEmail(writer.userEmail), getWorkspaceId(), IamRole.WRITER);
logger.info("Added {} as a writer to workspace {}", writer.userEmail, getWorkspaceId());
// Create the cloud context
String projectId = CloudContextMaker.createGcpCloudContext(getWorkspaceId(), workspaceApi);
assertNotNull(projectId);
logger.info("Created project {}", projectId);
// Create the bucket - should fail because application is not enabled
String bucketResourceName = RandomStringUtils.random(6, true, false);
ApiException createBucketFails = assertThrows(ApiException.class, () -> GcsBucketUtils.makeControlledGcsBucketAppShared(wsmappResourceApi, getWorkspaceId(), bucketResourceName, CloningInstructionsEnum.NOTHING));
// TODO: [PF-1208] this should be FORBIDDEN (403), but we are throwing the wrong thing
assertEquals(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED, createBucketFails.getCode());
logger.info("Failed to create bucket, as expected");
// Enable the application in the workspace
WorkspaceApplicationDescription applicationDescription = ownerWsmAppApi.enableWorkspaceApplication(getWorkspaceId(), TEST_WSM_APP);
assertThat(applicationDescription.getApplicationState(), equalTo(ApplicationState.OPERATING));
logger.info("Enabled application in the workspace");
// Validate that it is enabled
WorkspaceApplicationDescription retrievedDescription = ownerWsmAppApi.getWorkspaceApplication(getWorkspaceId(), TEST_WSM_APP);
assertThat(applicationDescription, equalTo(retrievedDescription));
assertThat(applicationDescription.getWorkspaceApplicationState(), equalTo(WorkspaceApplicationState.ENABLED));
// Create the bucket - should work this time
CreatedControlledGcpGcsBucket createdBucket = GcsBucketUtils.makeControlledGcsBucketAppShared(wsmappResourceApi, getWorkspaceId(), bucketResourceName, CloningInstructionsEnum.NOTHING);
bucketName = createdBucket.getGcpBucket().getAttributes().getBucketName();
assertNotNull(bucketName);
logger.info("Created bucket {}", bucketName);
// Try to disable; should error because you cannot disable an app if it owns resources
// in the workspace.
ApiException disableAppFails = assertThrows(ApiException.class, () -> ownerWsmAppApi.disableWorkspaceApplication(getWorkspaceId(), TEST_WSM_APP));
assertEquals(HttpStatusCodes.STATUS_CODE_BAD_REQUEST, disableAppFails.getCode());
logger.info("Failed to disable app, as expected");
try (GcsBucketAccessTester tester = new GcsBucketAccessTester(wsmapp, bucketName, projectId)) {
tester.checkAccess(wsmapp, ControlledResourceIamRole.EDITOR);
tester.checkAccess(owner, ControlledResourceIamRole.WRITER);
tester.checkAccess(writer, ControlledResourceIamRole.WRITER);
tester.checkAccess(reader, ControlledResourceIamRole.READER);
}
// The reader should be able to enumerate the bucket.
ResourceApi readerResourceApi = ClientTestUtils.getResourceClient(reader, server);
ResourceList bucketList = readerResourceApi.enumerateResources(getWorkspaceId(), 0, 5, ResourceType.GCS_BUCKET, StewardshipType.CONTROLLED);
assertEquals(1, bucketList.getResources().size());
MultiResourcesUtils.assertResourceType(ResourceType.GCS_BUCKET, bucketList);
// Owner cannot delete the bucket through WSM
ControlledGcpResourceApi ownerResourceApi = new ControlledGcpResourceApi(ownerApiClient);
ApiException cannotDelete = assertThrows(ApiException.class, () -> GcsBucketUtils.deleteControlledGcsBucket(createdBucket.getResourceId(), getWorkspaceId(), ownerResourceApi));
// TODO: [PF-1208] this should be FORBIDDEN (403), but we are throwing the wrong thing
assertEquals(HttpStatusCodes.STATUS_CODE_UNAUTHORIZED, cannotDelete.getCode());
logger.info("Owner delete failed as expected");
// Application can delete the bucket through WSM
GcsBucketUtils.deleteControlledGcsBucket(createdBucket.getResourceId(), getWorkspaceId(), wsmappResourceApi);
logger.info("Application delete succeeded");
}
use of bio.terra.workspace.client.ApiClient in project terra-workspace-manager by DataBiosphere.
the class EnumerateResources method doSetup.
@Override
public void doSetup(List<TestUserSpecification> testUsers, WorkspaceApi workspaceApi) throws Exception {
// initialize workspace
super.doSetup(testUsers, workspaceApi);
assertThat("There must be two test users defined for this test.", testUsers != null && testUsers.size() == 2);
TestUserSpecification workspaceOwner = testUsers.get(0);
workspaceReader = testUsers.get(1);
// static assumptions
assertThat(PAGE_SIZE * 2, lessThan(RESOURCE_COUNT));
assertThat(PAGE_SIZE * 3, greaterThan(RESOURCE_COUNT));
ApiClient ownerApiClient = ClientTestUtils.getClientForTestUser(workspaceOwner, server);
ownerControlledGcpResourceApi = new ControlledGcpResourceApi(ownerApiClient);
ownerReferencedGcpResourceApi = new ReferencedGcpResourceApi(ownerApiClient);
ownerResourceApi = new ResourceApi(ownerApiClient);
ApiClient readerApiClient = ClientTestUtils.getClientForTestUser(workspaceReader, server);
readerResourceApi = new ResourceApi(readerApiClient);
// 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());
}
use of bio.terra.workspace.client.ApiClient 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());
}
use of bio.terra.workspace.client.ApiClient in project terra-workspace-manager by DataBiosphere.
the class ControlledApplicationPrivateGcsBucketLifecycle method doUserJourney.
@Override
public void doUserJourney(TestUserSpecification testUser, WorkspaceApi workspaceApi) throws Exception {
ApiClient ownerApiClient = ClientTestUtils.getClientForTestUser(owner, server);
ApiClient wsmappApiClient = ClientTestUtils.getClientForTestUser(wsmapp, server);
WorkspaceApplicationApi ownerWsmAppApi = new WorkspaceApplicationApi(ownerApiClient);
ControlledGcpResourceApi wsmappResourceApi = new ControlledGcpResourceApi(wsmappApiClient);
// Owner adds a reader and a writer to the workspace
workspaceApi.grantRole(new GrantRoleRequestBody().memberEmail(reader.userEmail), getWorkspaceId(), IamRole.READER);
logger.info("Added {} as a reader to workspace {}", reader.userEmail, getWorkspaceId());
workspaceApi.grantRole(new GrantRoleRequestBody().memberEmail(writer.userEmail), getWorkspaceId(), IamRole.WRITER);
logger.info("Added {} as a writer to workspace {}", writer.userEmail, getWorkspaceId());
// Create the cloud context
String projectId = CloudContextMaker.createGcpCloudContext(getWorkspaceId(), workspaceApi);
assertNotNull(projectId);
logger.info("Created project {}", projectId);
// Enable the application in the workspace
WorkspaceApplicationDescription applicationDescription = ownerWsmAppApi.enableWorkspaceApplication(getWorkspaceId(), TEST_WSM_APP);
assertThat(applicationDescription.getApplicationState(), equalTo(ApplicationState.OPERATING));
logger.info("Enabled application {} in the workspace {}", TEST_WSM_APP, getWorkspaceId());
// CASE 1: Create a bucket with no assigned user
testNoAssignedUser(wsmappResourceApi, projectId);
// CASE 2: Create a bucket with workspace writer as READER
testAssignedReader(wsmappResourceApi, projectId);
// CASE 3: Create a bucket with workspace reader as WRITER
testAssignedWriter(wsmappResourceApi, projectId);
// All buckets should be visible to enumeration
ResourceApi ownerResourceApi = ClientTestUtils.getResourceClient(owner, server);
ResourceList bucketList = ownerResourceApi.enumerateResources(getWorkspaceId(), 0, 5, ResourceType.GCS_BUCKET, StewardshipType.CONTROLLED);
assertEquals(3, bucketList.getResources().size());
MultiResourcesUtils.assertResourceType(ResourceType.GCS_BUCKET, bucketList);
}
use of bio.terra.workspace.client.ApiClient in project terra-workspace-manager by DataBiosphere.
the class ServiceStatus method userJourney.
@Override
public void userJourney(TestUserSpecification testUser) throws Exception {
if (delay.getSeconds() > 0)
TimeUnit.SECONDS.sleep(delay.getSeconds());
logger.info("Checking service status endpoint now.");
ApiClient apiClient = ClientTestUtils.getClientWithoutAccessToken(server);
UnauthenticatedApi unauthenticatedApi = new UnauthenticatedApi(apiClient);
unauthenticatedApi.serviceStatus();
int httpCode = unauthenticatedApi.getApiClient().getStatusCode();
logger.info("Service status return code: {}", httpCode);
}
Aggregations