use of bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields in project terra-workspace-manager by DataBiosphere.
the class RemoveUserFromWorkspaceFlightTest method buildPrivateDataset.
private ControlledBigQueryDatasetResource buildPrivateDataset(UUID workspaceId, String datasetName, String projectId) {
ControlledResourceFields commonFields = ControlledResourceFields.builder().workspaceId(workspaceId).resourceId(UUID.randomUUID()).name(datasetName).cloningInstructions(CloningInstructions.COPY_NOTHING).assignedUser(userAccessUtils.getSecondUserEmail()).accessScope(AccessScopeType.ACCESS_SCOPE_PRIVATE).managedBy(ManagedByType.MANAGED_BY_USER).build();
ControlledBigQueryDatasetResource datasetToCreate = ControlledBigQueryDatasetResource.builder().common(commonFields).datasetName(datasetName).projectId(projectId).build();
ApiGcpBigQueryDatasetCreationParameters datasetCreationParameters = new ApiGcpBigQueryDatasetCreationParameters().datasetId(datasetName).location("us-central1");
return controlledResourceService.createControlledResourceSync(datasetToCreate, ControlledResourceIamRole.EDITOR, userAccessUtils.secondUserAuthRequest(), datasetCreationParameters).castByEnum(WsmResourceType.CONTROLLED_GCP_BIG_QUERY_DATASET);
}
use of bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields in project terra-workspace-manager by DataBiosphere.
the class SamServiceTest method workspaceReaderIsNotPrivateResourceReader.
@Test
void workspaceReaderIsNotPrivateResourceReader() throws Exception {
// Default user is workspace owner, secondary user is workspace reader
samService.grantWorkspaceRole(workspaceId, defaultUserRequest(), WsmIamRole.READER, userAccessUtils.getSecondUserEmail());
// Create private resource assigned to the default user.
ControlledResourceFields commonFields = ControlledResourceFixtures.makeDefaultControlledResourceFieldsBuilder().workspaceId(workspaceId).accessScope(AccessScopeType.ACCESS_SCOPE_PRIVATE).assignedUser(userAccessUtils.getDefaultUserEmail()).privateResourceState(PrivateResourceState.ACTIVE).build();
ControlledResource bucketResource = ControlledGcsBucketResource.builder().bucketName(ControlledResourceFixtures.uniqueBucketName()).common(commonFields).build();
samService.createControlledResource(bucketResource, ControlledResourceIamRole.EDITOR, userAccessUtils.getDefaultUserEmail(), defaultUserRequest());
// Workspace reader should not have read access on a private resource.
assertFalse(samService.isAuthorized(secondaryUserRequest(), ControlledResourceCategory.USER_PRIVATE.getSamResourceName(), bucketResource.getResourceId().toString(), SamConstants.SamWorkspaceAction.READ));
// However, the assigned user should have read access.
assertTrue(samService.isAuthorized(defaultUserRequest(), ControlledResourceCategory.USER_PRIVATE.getSamResourceName(), bucketResource.getResourceId().toString(), SamConstants.SamWorkspaceAction.READ));
samService.deleteControlledResource(bucketResource, defaultUserRequest());
}
use of bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields in project terra-workspace-manager by DataBiosphere.
the class ControlledAzureNetworkHandler method makeResourceFromDb.
/**
* {@inheritDoc}
*/
@Override
public WsmResource makeResourceFromDb(DbResource dbResource) {
ControlledAzureNetworkAttributes attributes = DbSerDes.fromJson(dbResource.getAttributes(), ControlledAzureNetworkAttributes.class);
var resource = ControlledAzureNetworkResource.builder().common(new ControlledResourceFields(dbResource)).networkName(attributes.getNetworkName()).subnetName(attributes.getSubnetName()).addressSpaceCidr(attributes.getAddressSpaceCidr()).subnetAddressCidr(attributes.getSubnetAddressCidr()).region(attributes.getRegion()).build();
return resource;
}
use of bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields in project terra-workspace-manager by DataBiosphere.
the class ControlledGcpResourceApiController method createBucket.
@Override
public ResponseEntity<ApiCreatedControlledGcpGcsBucket> createBucket(UUID workspaceId, @Valid ApiCreateControlledGcpGcsBucketRequestBody body) {
final AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
ControlledResourceFields commonFields = toCommonFields(workspaceId, body.getCommon(), userRequest);
ControlledGcsBucketResource resource = ControlledGcsBucketResource.builder().bucketName(body.getGcsBucket().getName()).common(commonFields).build();
final ControlledGcsBucketResource createdBucket = controlledResourceService.createControlledResourceSync(resource, commonFields.getIamRole(), userRequest, body.getGcsBucket()).castByEnum(WsmResourceType.CONTROLLED_GCP_GCS_BUCKET);
var response = new ApiCreatedControlledGcpGcsBucket().resourceId(createdBucket.getResourceId()).gcpBucket(createdBucket.toApiResource());
return new ResponseEntity<>(response, HttpStatus.OK);
}
use of bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields in project terra-workspace-manager by DataBiosphere.
the class ControlledGcpResourceApiController method createBigQueryDataset.
@Override
public ResponseEntity<ApiCreatedControlledGcpBigQueryDataset> createBigQueryDataset(UUID workspaceId, ApiCreateControlledGcpBigQueryDatasetRequestBody body) {
final AuthenticatedUserRequest userRequest = getAuthenticatedInfo();
ControlledResourceFields commonFields = toCommonFields(workspaceId, body.getCommon(), userRequest);
// We need to retrieve the project id so it can be used in the BQ dataset attributes.
String projectId = workspaceService.getAuthorizedRequiredGcpProject(workspaceId, userRequest);
ControlledBigQueryDatasetResource resource = ControlledBigQueryDatasetResource.builder().datasetName(Optional.ofNullable(body.getDataset().getDatasetId()).orElse(body.getCommon().getName())).projectId(projectId).common(commonFields).build();
final ControlledBigQueryDatasetResource createdDataset = controlledResourceService.createControlledResourceSync(resource, commonFields.getIamRole(), userRequest, body.getDataset()).castByEnum(WsmResourceType.CONTROLLED_GCP_BIG_QUERY_DATASET);
var response = new ApiCreatedControlledGcpBigQueryDataset().resourceId(createdDataset.getResourceId()).bigQueryDataset(createdDataset.toApiResource());
return new ResponseEntity<>(response, HttpStatus.OK);
}
Aggregations