diff options
author | Dominik Mizyn <d.mizyn@samsung.com> | 2020-02-04 11:24:32 +0100 |
---|---|---|
committer | Patrick Brady <patrick.brady@att.com> | 2020-02-28 18:41:41 +0000 |
commit | ad5fadb29be48230145d2d155daf4dc72a5ce450 (patch) | |
tree | 20a9dc328e034e9d3310bd195fe178d458561c09 /appc-dispatcher/appc-dispatcher-common | |
parent | 90732f0d7d131cb3a9640cde51b9afdc502a7c4d (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.
Change-Id: I166dbee857c95256fa5253379205c81414771c53
Issue-ID: OOM-2275
Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
Diffstat (limited to 'appc-dispatcher/appc-dispatcher-common')
-rw-r--r-- | appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/DBUtils.java | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/DBUtils.java b/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/DBUtils.java index c29ce0287..98fc915eb 100644 --- a/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/DBUtils.java +++ b/appc-dispatcher/appc-dispatcher-common/appc-data-access-lib/src/main/java/org/onap/appc/dao/util/DBUtils.java @@ -25,6 +25,7 @@ package org.onap.appc.dao.util; import com.att.eelf.configuration.EELFLogger; import com.att.eelf.configuration.EELFManager; +import java.util.Properties; import org.onap.appc.configuration.Configuration; import org.onap.appc.configuration.ConfigurationFactory; import java.sql.*; @@ -60,11 +61,20 @@ public class DBUtils { public static Connection getConnection(String schema) throws SQLException { DriverManager.registerDriver(new org.mariadb.jdbc.Driver()); String dbURL = configuration.getProperty(String.format("org.onap.appc.db.url.%s", schema), ""); - String userName = configuration.getProperty(String.format("org.onap.appc.db.user.%s", schema), ""); - String password = configuration.getProperty(String.format("org.onap.appc.db.pass.%s", schema), ""); + String userName = getValue(configuration.getProperty(String.format("org.onap.appc.db.user.%s", schema), "")); + String password = getValue(configuration.getProperty(String.format("org.onap.appc.db.pass.%s", schema), "")); return DriverManager.getConnection(dbURL, userName, password); } + private static String getValue(final String value) { + if (value != null && value.matches("[$][{].*[}]$")) { + String envVariable = System.getenv(value.substring(2, value.length() - 1)); + return envVariable == null ? "" : envVariable; + } else { + return value; + } + } + public static boolean clearResources(ResultSet resultSet, PreparedStatement ptmt, Connection connection) { boolean clearFlag = false; try { |