use of bio.terra.workspace.service.workspace.exceptions.InvalidApplicationConfigException 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();
}
Aggregations