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();
}
Aggregations