use of bio.terra.common.exception.ConflictException in project terra-workspace-manager by DataBiosphere.
the class GrantPetUsagePermissionStep method doStep.
@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
String userEmail = SamRethrow.onInterrupted(() -> samService.getUserEmailFromSam(userRequest), "enablePet");
Policy modifiedPolicy;
try {
modifiedPolicy = petSaService.enablePetServiceAccountImpersonation(workspaceUuid, userEmail, userRequest);
} catch (ConflictException e) {
// There was a conflict enabling the service account. Request retry.
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
// Store the eTag value of the modified policy in case this step needs to be undone.
FlightMap workingMap = context.getWorkingMap();
workingMap.put(PetSaKeys.MODIFIED_PET_SA_POLICY_ETAG, modifiedPolicy.getEtag());
return StepResult.getStepResultSuccess();
}
use of bio.terra.common.exception.ConflictException in project terra-workspace-manager by DataBiosphere.
the class GrantPetUsagePermissionStep method undoStep.
@Override
public StepResult undoStep(FlightContext context) throws InterruptedException {
FlightMap workingMap = context.getWorkingMap();
String expectedEtag = workingMap.get(PetSaKeys.MODIFIED_PET_SA_POLICY_ETAG, String.class);
if (expectedEtag == null) {
// If the do step did not finish, we cannot guarantee we aren't undoing something we didn't do
logger.warn("Unable to undo GrantUsagePermissionStep for user {} in workspace {} as do step may not have completed.", userRequest.getEmail(), workspaceUuid);
return StepResult.getStepResultSuccess();
}
try {
petSaService.disablePetServiceAccountImpersonationWithEtag(workspaceUuid, userRequest.getEmail(), userRequest, expectedEtag);
} catch (ConflictException e) {
// one succeeds and one fails, the failed one will disable the impersonation on undo.
return new StepResult(StepStatus.STEP_RESULT_FAILURE_RETRY, e);
}
return StepResult.getStepResultSuccess();
}
Aggregations