Search in sources :

Example 11 with WsmApplication

use of bio.terra.workspace.service.workspace.model.WsmApplication in project terra-workspace-manager by DataBiosphere.

the class ApplicationAbleIamStep method doStep.

@Override
public StepResult doStep(FlightContext context) throws InterruptedException, RetryException {
    FlightMap workingMap = context.getWorkingMap();
    FlightUtils.validateRequiredEntries(workingMap, WsmApplicationKeys.WSM_APPLICATION, WsmApplicationKeys.APPLICATION_ABLE_SAM);
    // if the application was in the correct Sam state in precheck, then we do nothing
    if (workingMap.get(WsmApplicationKeys.APPLICATION_ABLE_SAM, Boolean.class)) {
        return StepResult.getStepResultSuccess();
    }
    WsmApplication application = workingMap.get(WsmApplicationKeys.WSM_APPLICATION, WsmApplication.class);
    if (ableEnum == AbleEnum.ENABLE) {
        samService.grantWorkspaceRole(workspaceId, userRequest, WsmIamRole.APPLICATION, application.getServiceAccount());
    } else {
        samService.removeWorkspaceRole(workspaceId, userRequest, WsmIamRole.APPLICATION, application.getServiceAccount());
    }
    return StepResult.getStepResultSuccess();
}
Also used : WsmApplication(bio.terra.workspace.service.workspace.model.WsmApplication) FlightMap(bio.terra.stairway.FlightMap)

Example 12 with WsmApplication

use of bio.terra.workspace.service.workspace.model.WsmApplication in project terra-workspace-manager by DataBiosphere.

the class ApplicationAbleIamStep method undoStep.

@Override
public StepResult undoStep(FlightContext context) throws InterruptedException {
    FlightMap workingMap = context.getWorkingMap();
    // if the application was not already enabled in Sam when we started, we do not undo it
    if (workingMap.get(WsmApplicationKeys.APPLICATION_ABLE_SAM, Boolean.class)) {
        return StepResult.getStepResultSuccess();
    }
    WsmApplication application = workingMap.get(WsmApplicationKeys.WSM_APPLICATION, WsmApplication.class);
    if (ableEnum == AbleEnum.ENABLE) {
        samService.removeWorkspaceRole(workspaceId, userRequest, WsmIamRole.APPLICATION, application.getServiceAccount());
    } else {
        samService.grantWorkspaceRole(workspaceId, userRequest, WsmIamRole.APPLICATION, application.getServiceAccount());
    }
    return StepResult.getStepResultSuccess();
}
Also used : WsmApplication(bio.terra.workspace.service.workspace.model.WsmApplication) FlightMap(bio.terra.stairway.FlightMap)

Aggregations

WsmApplication (bio.terra.workspace.service.workspace.model.WsmApplication)12 UUID (java.util.UUID)5 Test (org.junit.jupiter.api.Test)4 FlightMap (bio.terra.stairway.FlightMap)3 BaseUnitTest (bio.terra.workspace.common.BaseUnitTest)3 WsmDbApplication (bio.terra.workspace.service.workspace.WsmApplicationService.WsmDbApplication)3 HashMap (java.util.HashMap)3 VisibleForTesting (com.google.common.annotations.VisibleForTesting)2 DirtiesContext (org.springframework.test.annotation.DirtiesContext)2 App (bio.terra.workspace.app.configuration.external.WsmApplicationConfiguration.App)1 BaseTest (bio.terra.workspace.common.BaseTest)1 ApplicationNotFoundException (bio.terra.workspace.db.exception.ApplicationNotFoundException)1 InvalidApplicationStateException (bio.terra.workspace.db.exception.InvalidApplicationStateException)1 InvalidApplicationConfigException (bio.terra.workspace.service.workspace.exceptions.InvalidApplicationConfigException)1 WsmApplicationState (bio.terra.workspace.service.workspace.model.WsmApplicationState)1 WsmWorkspaceApplication (bio.terra.workspace.service.workspace.model.WsmWorkspaceApplication)1 Nullable (javax.annotation.Nullable)1