Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Melodic
melodic-upperware
Commits
ce31d48e
Commit
ce31d48e
authored
May 14, 2020
by
Alicja Reniewicz
Browse files
change way for saving variable in secure store
parent
b1c1817c
Changes
2
Hide whitespace changes
Inline
Side-by-side
gui-backend/src/main/java/eu/melodic/upperware/guibackend/controller/deployment/DeploymentController.java
View file @
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
);
}
}
gui-backend/src/main/java/eu/melodic/upperware/guibackend/service/secure/store/SecureStoreService.java
View file @
ce31d48e
...
...
@@ -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
);
}
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment