Commit 009cfc56 authored by Maria C's avatar Maria C
Browse files

Merge branch 'fix-label-for-secure-variable' into 'rc3.1'

change way for saving variable in secure store

See merge request !7
parents b1c1817c ce31d48e
......@@ -73,6 +73,7 @@ public class DeploymentController {
@ResponseStatus(HttpStatus.CREATED)
public List<String> saveSecureVariables(@RequestBody List<SecureVariable> secureVariablesRequest) {
log.info("POST request for save secure variables");
secureStoreService.validateSecureVariables(secureVariablesRequest);
return secureStoreService.saveSecureVariables(secureVariablesRequest);
}
}
......@@ -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<SecureVariable> 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<String> saveSecureVariables(List<SecureVariable> secureVariablesRequest) {
return secureVariablesRequest
.stream()
......@@ -86,7 +99,9 @@ public class SecureStoreService {
}
public Pair<String, String> 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);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment