summaryrefslogtreecommitdiffstats
path: root/models-provider/src/main/java
diff options
context:
space:
mode:
authorDominik Mizyn <d.mizyn@samsung.com>2020-02-13 15:04:53 +0100
committerDominik Mizyn <d.mizyn@samsung.com>2020-02-13 15:07:29 +0100
commit6c494d06a7a0c0492f4c7bc42cebd42222fa44f1 (patch)
tree64ea8093b6c6d526a227f6f66c2632bfdcf7928e /models-provider/src/main/java
parentfd79f7920d454c35d6a8c02d430d9beba434dcc2 (diff)
Allow storing database password in environment variables
This patch allows to store and get database passwor from environment variables. This is needed if we want to send those variables by helm secrets. Issue-ID: OOM-2287 Change-Id: Id9ea8f43dd07c2b0cdeaa6d14a8033336d26923f Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
Diffstat (limited to 'models-provider/src/main/java')
-rw-r--r--models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java9
1 files changed, 8 insertions, 1 deletions
diff --git a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
index 08c01b68f..50c739059 100644
--- a/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
+++ b/models-provider/src/main/java/org/onap/policy/models/provider/impl/DatabasePolicyModelsProviderImpl.java
@@ -101,7 +101,7 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
daoParameters.setPersistenceUnit(parameters.getPersistenceUnit());
// Decode the password using Base64
- String decodedPassword = new String(Base64.getDecoder().decode(parameters.getDatabasePassword()));
+ String decodedPassword = new String(Base64.getDecoder().decode(getValue(parameters.getDatabasePassword())));
// @formatter:off
Properties jdbcProperties = new Properties();
@@ -125,6 +125,13 @@ public class DatabasePolicyModelsProviderImpl implements PolicyModelsProvider {
}
}
+ private String getValue(final String value) {
+ if (value != null && value.matches("[$][{].*[}]$")) {
+ return System.getenv(value.substring(2, value.length() - 1));
+ }
+ return value;
+ }
+
@Override
public void close() throws PfModelException {
LOGGER.debug("closing the database connection to {} using persistence unit {}", parameters.getDatabaseUrl(),