Search in sources :

Example 1 with ControlledResourceFields

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);
}
Also used : ApiGcpBigQueryDatasetCreationParameters(bio.terra.workspace.generated.model.ApiGcpBigQueryDatasetCreationParameters) ControlledResourceFields(bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields) ControlledBigQueryDatasetResource(bio.terra.workspace.service.resource.controlled.cloud.gcp.bqdataset.ControlledBigQueryDatasetResource)

Example 2 with ControlledResourceFields

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());
}
Also used : ControlledResource(bio.terra.workspace.service.resource.controlled.model.ControlledResource) ControlledResourceFields(bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields) BaseConnectedTest(bio.terra.workspace.common.BaseConnectedTest) Test(org.junit.jupiter.api.Test)

Example 3 with ControlledResourceFields

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;
}
Also used : ControlledResourceFields(bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields)

Example 4 with ControlledResourceFields

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);
}
Also used : ResponseEntity(org.springframework.http.ResponseEntity) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ControlledResourceFields(bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields) ControlledGcsBucketResource(bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource) ApiCreatedControlledGcpGcsBucket(bio.terra.workspace.generated.model.ApiCreatedControlledGcpGcsBucket)

Example 5 with ControlledResourceFields

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);
}
Also used : ApiCreatedControlledGcpBigQueryDataset(bio.terra.workspace.generated.model.ApiCreatedControlledGcpBigQueryDataset) ResponseEntity(org.springframework.http.ResponseEntity) AuthenticatedUserRequest(bio.terra.workspace.service.iam.AuthenticatedUserRequest) ControlledResourceFields(bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields) ControlledBigQueryDatasetResource(bio.terra.workspace.service.resource.controlled.cloud.gcp.bqdataset.ControlledBigQueryDatasetResource)

Aggregations

ControlledResourceFields (bio.terra.workspace.service.resource.controlled.model.ControlledResourceFields)21 AuthenticatedUserRequest (bio.terra.workspace.service.iam.AuthenticatedUserRequest)11 ResponseEntity (org.springframework.http.ResponseEntity)9 Test (org.junit.jupiter.api.Test)7 UUID (java.util.UUID)6 BaseConnectedTest (bio.terra.workspace.common.BaseConnectedTest)4 ControlledGcsBucketResource (bio.terra.workspace.service.resource.controlled.cloud.gcp.gcsbucket.ControlledGcsBucketResource)4 ControlledResource (bio.terra.workspace.service.resource.controlled.model.ControlledResource)4 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)3 ApiGcpGcsBucketCreationParameters (bio.terra.workspace.generated.model.ApiGcpGcsBucketCreationParameters)3 ControlledAiNotebookInstanceResource (bio.terra.workspace.service.resource.controlled.cloud.gcp.ainotebook.ControlledAiNotebookInstanceResource)3 ControlledBigQueryDatasetResource (bio.terra.workspace.service.resource.controlled.cloud.gcp.bqdataset.ControlledBigQueryDatasetResource)3 FlightMap (bio.terra.stairway.FlightMap)2 ApiCreatedControlledGcpGcsBucket (bio.terra.workspace.generated.model.ApiCreatedControlledGcpGcsBucket)2 ApiGcpBigQueryDatasetCreationParameters (bio.terra.workspace.generated.model.ApiGcpBigQueryDatasetCreationParameters)2 ControlledResourceIamRole (bio.terra.workspace.service.iam.model.ControlledResourceIamRole)2 ControlledAzureDiskResource (bio.terra.workspace.service.resource.controlled.cloud.azure.disk.ControlledAzureDiskResource)2 ControlledAzureIpResource (bio.terra.workspace.service.resource.controlled.cloud.azure.ip.ControlledAzureIpResource)2 ControlledAzureNetworkResource (bio.terra.workspace.service.resource.controlled.cloud.azure.network.ControlledAzureNetworkResource)2 ControlledAzureVmResource (bio.terra.workspace.service.resource.controlled.cloud.azure.vm.ControlledAzureVmResource)2