Search in sources :

Example 1 with SyncMapping

use of bio.terra.workspace.service.resource.controlled.ControlledResourceSyncMapping.SyncMapping in project terra-workspace-manager by DataBiosphere.

the class ControlledResourceService method configureGcpPolicyForResource.

public Policy configureGcpPolicyForResource(ControlledResource resource, GcpCloudContext cloudContext, Policy currentPolicy, AuthenticatedUserRequest userRequest) throws InterruptedException {
    GcpPolicyBuilder gcpPolicyBuilder = new GcpPolicyBuilder(resource, cloudContext.getGcpProjectId(), currentPolicy);
    List<SyncMapping> syncMappings = resource.getCategory().getSyncMappings();
    for (SyncMapping syncMapping : syncMappings) {
        String policyGroup = null;
        switch(syncMapping.getRoleSource()) {
            case RESOURCE:
                policyGroup = samService.syncResourcePolicy(resource, syncMapping.getResourceRole().orElseThrow(badState), userRequest);
                break;
            case WORKSPACE:
                switch(syncMapping.getWorkspaceRole().orElseThrow(badState)) {
                    case OWNER:
                        policyGroup = cloudContext.getSamPolicyOwner().orElseThrow(badState);
                        break;
                    case WRITER:
                        policyGroup = cloudContext.getSamPolicyWriter().orElseThrow(badState);
                        break;
                    case READER:
                        policyGroup = cloudContext.getSamPolicyReader().orElseThrow(badState);
                        break;
                    case APPLICATION:
                        policyGroup = cloudContext.getSamPolicyApplication().orElseThrow(badState);
                        break;
                    default:
                        break;
                }
                break;
        }
        if (policyGroup == null) {
            throw new InternalLogicException("Policy group not set");
        }
        gcpPolicyBuilder.addResourceBinding(syncMapping.getTargetRole(), policyGroup);
    }
    return gcpPolicyBuilder.build();
}
Also used : InternalLogicException(bio.terra.workspace.common.exception.InternalLogicException) GcpPolicyBuilder(bio.terra.workspace.service.resource.controlled.cloud.gcp.GcpPolicyBuilder) SyncMapping(bio.terra.workspace.service.resource.controlled.ControlledResourceSyncMapping.SyncMapping)

Aggregations

InternalLogicException (bio.terra.workspace.common.exception.InternalLogicException)1 SyncMapping (bio.terra.workspace.service.resource.controlled.ControlledResourceSyncMapping.SyncMapping)1 GcpPolicyBuilder (bio.terra.workspace.service.resource.controlled.cloud.gcp.GcpPolicyBuilder)1