use of bio.terra.buffer.service.resource.FlightMapKeys.GOOGLE_PROJECT_ID in project terra-resource-buffer by DataBiosphere.
the class SetIamPolicyStep method doStep.
@Override
public StepResult doStep(FlightContext flightContext) throws RetryException {
// Skip if IAM binding is not set.
if (gcpProjectConfig.getIamBindings() == null || gcpProjectConfig.getIamBindings().isEmpty()) {
return StepResult.getStepResultSuccess();
}
String projectId = flightContext.getWorkingMap().get(GOOGLE_PROJECT_ID, String.class);
try {
Policy policy = rmCow.projects().getIamPolicy(projectId, new GetIamPolicyRequest()).execute();
gcpProjectConfig.getIamBindings().stream().map(iamBinding -> new Binding().setRole(iamBinding.getRole()).setMembers(iamBinding.getMembers())).forEach(policy.getBindings()::add);
rmCow.projects().setIamPolicy(projectId, new SetIamPolicyRequest().setPolicy(policy)).execute();
} catch (IOException e) {
logger.info("Error when setting IAM policy", e);
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
return StepResult.getStepResultSuccess();
}
Aggregations