aboutsummaryrefslogtreecommitdiffstats
path: root/datarouter-prov/src/main/java/org
diff options
context:
space:
mode:
authorDominik Mizyn <d.mizyn@samsung.com>2020-01-31 15:45:21 +0100
committerDominik Mizyn <d.mizyn@samsung.com>2020-02-04 14:25:02 +0100
commita884c481af24e2405f9389b01842c4671a03a75e (patch)
tree61796295328ae9b9c6eb37fcc7db89c96c07082c /datarouter-prov/src/main/java/org
parent6ac1c84f0aeec17dba6c55c7097a264b1a7b6ba2 (diff)
Allow storing db.user and db.pass in environment variables
This patch allows to store and get db.user and db.pass from environment variables. This is needed if we want to send those variables by helm secrets. Issue-ID: OOM-2287 Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com> Change-Id: Ie1736dd4bd89710b441f5cc96dd116bd433ad1b6
Diffstat (limited to 'datarouter-prov/src/main/java/org')
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ProvDbUtils.java16
1 files changed, 12 insertions, 4 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ProvDbUtils.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ProvDbUtils.java
index 34f05f46..b654bf3c 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ProvDbUtils.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/ProvDbUtils.java
@@ -66,14 +66,22 @@ public class ProvDbUtils {
Class.forName((String) props.get("org.onap.dmaap.datarouter.db.driver"));
BasicDataSource dataSource = new BasicDataSource();
dataSource.setUrl((String) props.get("org.onap.dmaap.datarouter.db.url"));
- dataSource.setUsername((String) props.get("org.onap.dmaap.datarouter.db.login"));
- dataSource.setPassword((String) props.get("org.onap.dmaap.datarouter.db.password"));
+ dataSource.setUsername(getValue(props, "org.onap.dmaap.datarouter.db.login"));
+ dataSource.setPassword(getValue(props, "org.onap.dmaap.datarouter.db.password"));
dataSource.setMinIdle(5);
dataSource.setMaxIdle(15);
dataSource.setMaxOpenPreparedStatements(100);
return dataSource;
}
+ private static String getValue(final Properties props, final String value) {
+ String prop = (String) props.get(value);
+ if (prop != null && prop.matches("[$][{].*[}]$")) {
+ return System.getenv(prop.substring(2, prop.length() - 1));
+ }
+ return prop;
+ }
+
public Connection getConnection() throws SQLException {
return dataSource.getConnection();
}
@@ -130,7 +138,7 @@ public class ProvDbUtils {
* sql_init_NN.sql
*
* @param connection a DB connection
- * @param scriptId the number of the sql_init_NN.sql script to run
+ * @param scriptId the number of the sql_init_NN.sql script to run
*/
private void runInitScript(Connection connection, int scriptId) {
String scriptDir = ProvRunner.getProvProperties().getProperty("org.onap.dmaap.datarouter.provserver.dbscripts");
@@ -165,4 +173,4 @@ public class ProvDbUtils {
statement.execute(sql);
}
}
-} \ No newline at end of file
+}