Search in sources :

Example 1 with ConflictException

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();
}
Also used : Policy(com.google.api.services.iam.v1.model.Policy) ConflictException(bio.terra.common.exception.ConflictException) FlightMap(bio.terra.stairway.FlightMap) StepResult(bio.terra.stairway.StepResult)

Example 2 with ConflictException

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();
}
Also used : ConflictException(bio.terra.common.exception.ConflictException) FlightMap(bio.terra.stairway.FlightMap) StepResult(bio.terra.stairway.StepResult)

Aggregations

ConflictException (bio.terra.common.exception.ConflictException)2 FlightMap (bio.terra.stairway.FlightMap)2 StepResult (bio.terra.stairway.StepResult)2 Policy (com.google.api.services.iam.v1.model.Policy)1