Search in sources :

Example 1 with WsmApplicationState

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

the class WsmApplicationService method appFromConfig.

@VisibleForTesting
Optional<WsmApplication> appFromConfig(App config) {
    try {
        if (config.getIdentifier() == null || config.getServiceAccount() == null || config.getState() == null) {
            logError("Invalid application configuration: missing some required fields (identifier, service-account, state)");
            return Optional.empty();
        }
        UUID applicationId = UUID.fromString(config.getIdentifier());
        WsmApplicationState state = WsmApplicationState.fromString(config.getState());
        if (!EmailValidator.getInstance(false, true).isValid(config.getServiceAccount())) {
            logError("Invalid application configuration: service account is not a valid email address");
            return Optional.empty();
        }
        // We keep everything homogeneously lowercase
        String serviceAccount = StringUtils.lowerCase(config.getServiceAccount());
        return Optional.of(new WsmApplication().applicationId(applicationId).displayName(config.getName()).description(config.getDescription()).serviceAccount(serviceAccount).state(state));
    } catch (IllegalArgumentException e) {
        logError("Invalid application configuration: invalid UUID format", e);
    } catch (InvalidApplicationConfigException e) {
        logError("Invalid application configuration: state must be operating, deprecated, or decommissioned", e);
    }
    return Optional.empty();
}
Also used : WsmApplication(bio.terra.workspace.service.workspace.model.WsmApplication) WsmApplicationState(bio.terra.workspace.service.workspace.model.WsmApplicationState) UUID(java.util.UUID) InvalidApplicationConfigException(bio.terra.workspace.service.workspace.exceptions.InvalidApplicationConfigException) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

InvalidApplicationConfigException (bio.terra.workspace.service.workspace.exceptions.InvalidApplicationConfigException)1 WsmApplication (bio.terra.workspace.service.workspace.model.WsmApplication)1 WsmApplicationState (bio.terra.workspace.service.workspace.model.WsmApplicationState)1 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 UUID (java.util.UUID)1