From ce31d48e8936c12a477bb09cf184b051b9bc78d2 Mon Sep 17 00:00:00 2001 From: areniewicz Date: Thu, 14 May 2020 18:05:11 +0200 Subject: [PATCH] change way for saving variable in secure store --- .../deployment/DeploymentController.java | 1 + .../secure/store/SecureStoreService.java | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/gui-backend/src/main/java/eu/melodic/upperware/guibackend/controller/deployment/DeploymentController.java b/gui-backend/src/main/java/eu/melodic/upperware/guibackend/controller/deployment/DeploymentController.java index 7887e9b23..9a6a97cc2 100644 --- a/gui-backend/src/main/java/eu/melodic/upperware/guibackend/controller/deployment/DeploymentController.java +++ b/gui-backend/src/main/java/eu/melodic/upperware/guibackend/controller/deployment/DeploymentController.java @@ -73,6 +73,7 @@ public class DeploymentController { @ResponseStatus(HttpStatus.CREATED) public List saveSecureVariables(@RequestBody List secureVariablesRequest) { log.info("POST request for save secure variables"); + secureStoreService.validateSecureVariables(secureVariablesRequest); return secureStoreService.saveSecureVariables(secureVariablesRequest); } } diff --git a/gui-backend/src/main/java/eu/melodic/upperware/guibackend/service/secure/store/SecureStoreService.java b/gui-backend/src/main/java/eu/melodic/upperware/guibackend/service/secure/store/SecureStoreService.java index 292b63de7..f37c34f6b 100644 --- a/gui-backend/src/main/java/eu/melodic/upperware/guibackend/service/secure/store/SecureStoreService.java +++ b/gui-backend/src/main/java/eu/melodic/upperware/guibackend/service/secure/store/SecureStoreService.java @@ -3,6 +3,7 @@ package eu.melodic.upperware.guibackend.service.secure.store; import eu.melodic.upperware.guibackend.communication.cloudiator.CloudiatorApi; import eu.melodic.upperware.guibackend.controller.deployment.common.SecureVariable; import eu.melodic.upperware.guibackend.exception.SecureVariableNotFoundException; +import eu.melodic.upperware.guibackend.exception.ValidationException; import eu.melodic.upperware.guibackend.model.byon.LoginCredential; import eu.melodic.upperware.guibackend.model.provider.CloudDefinition; import lombok.AllArgsConstructor; @@ -44,6 +45,18 @@ public class SecureStoreService { return secureVariablesKeys; } + // This method checks correctness of secure variable names, + // chars: '/' and '\' are not allowed as key of variable for Cloudiator secure store. + public void validateSecureVariables(List secureVariablesRequest) { + String invalidVariables = secureVariablesRequest.stream() + .filter(secureVariable -> secureVariable.getName().contains("/") || secureVariable.getName().contains("\\")) + .map(SecureVariable::getName) + .collect(Collectors.joining(", ")); + if (!invalidVariables.isEmpty()) { + throw new ValidationException(String.format("Variables: [ %s ] contain not allowed chars: '\\' or '/'", invalidVariables)); + } + } + public List saveSecureVariables(List secureVariablesRequest) { return secureVariablesRequest .stream() @@ -86,7 +99,9 @@ public class SecureStoreService { } public Pair createKeyLabelForSecret(CloudDefinition cloudDefinition) { - String keyForSecret = cloudDefinition.getApi().getProviderName() + "-" + cloudDefinition.getCredential().getUser() + SECURE_VARIABLE_SECURE_SUFIX; + String keyForSecret = cloudDefinition.getApi().getProviderName() + "-" + + cloudDefinition.getId() + + SECURE_VARIABLE_SECURE_SUFIX; return Pair.of(keyForSecret, SECURE_VARIABLE_PREFIX + keyForSecret + SECURE_VARIABLE_SUFFIX); } -- GitLab