Allow storing database password in environment variables 77/101877/3
authorDominik Mizyn <d.mizyn@samsung.com>
Tue, 18 Feb 2020 08:57:40 +0000 (09:57 +0100)
committerDominik Mizyn <d.mizyn@samsung.com>
Tue, 18 Feb 2020 13:48:06 +0000 (14:48 +0100)
This patch allows to store and get database password from
environment variables. This is needed if we want to send those
variables by helm secrets.

Issue-ID: OOM-2287
Change-Id: I041c3e4dd3b9042b2b6c2b34afc22867bab81b22
Signed-off-by: Dominik Mizyn <d.mizyn@samsung.com>
BRMSGateway/src/main/java/org/onap/policy/brms/api/BrmsPush.java
LogParser/src/main/java/org/onap/xacml/parser/ParseLog.java

index 45f6585..8826d56 100644 (file)
@@ -256,8 +256,8 @@ public class BrmsPush {
             repUrlList = new ArrayList<>();
             repUrlList.add(repUrl);
         }
-        repUserName = config.getProperty("repositoryUsername");
-        repPassword = PeCryptoUtils.decrypt(config.getProperty("repositoryPassword"));
+        repUserName = getValue(config.getProperty("repositoryUsername"));
+        repPassword = PeCryptoUtils.decrypt(getValue(config.getProperty("repositoryPassword")));
         if (repUserName == null || repPassword == null) {
             LOGGER.error(XACMLErrorConstants.ERROR_DATA_ISSUE
                     + "repostoryUserName and respositoryPassword properties are required.");
@@ -367,6 +367,13 @@ public class BrmsPush {
 
     }
 
+    private String getValue(final String value) {
+        if (value != null && value.matches("[$][{].*[}]$")) {
+            return System.getenv(value.substring(2, value.length() - 1));
+        }
+        return value;
+    }
+
     private static void setBackupMonitor(final BackUpMonitor instance) {
         bm = instance;
     }
index f12522a..77aafdf 100644 (file)
@@ -884,11 +884,11 @@ public class ParseLog {
             setLogFileProperties(splitString);
 
             jdbcUrl = config.getProperty("JDBC_URL").replace("'", "");
-            jdbcUser = config.getProperty("JDBC_USER");
+            jdbcUser = getValue(config.getProperty("JDBC_USER"));
             jdbcDriver = config.getProperty("JDBC_DRIVER");
 
             PeCryptoUtils.initAesKey(config.getProperty(PROP_AES_KEY));
-            jdbcPassword = PeCryptoUtils.decrypt(config.getProperty("JDBC_PASSWORD"));
+            jdbcPassword = PeCryptoUtils.decrypt(getValue(config.getProperty("JDBC_PASSWORD")));
             config.setProperty("javax.persistence.jdbc.password", jdbcPassword);
             return config;
 
@@ -902,6 +902,13 @@ public class ParseLog {
         return null;
     }
 
+    private static String getValue(final String value) {
+        if (value != null && value.matches("[$][{].*[}]$")) {
+            return System.getenv(value.substring(2, value.length() - 1));
+        }
+        return value;
+    }
+
     public static Connection getDbConnection() {
         return dbConnection(jdbcDriver, jdbcUrl, jdbcUser, jdbcPassword);
     }