From: Dominik Mizyn Date: Tue, 4 Feb 2020 12:10:31 +0000 (+0100) Subject: Allow storing db.user and db.pass in environment variables X-Git-Tag: 2.0.2~4 X-Git-Url: https://gerrit.onap.org/r/gitweb?p=dmaap%2Fdbcapi.git;a=commitdiff_plain;h=0c5fb02166b500ff6751265811030d23acfc5b5e 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 Change-Id: I238447b10869bb953f3cf0bb03d394dff311b0d8 Signed-off-by: Dominik Mizyn --- diff --git a/src/main/java/org/onap/dmaap/dbcapi/database/ConnectionFactory.java b/src/main/java/org/onap/dmaap/dbcapi/database/ConnectionFactory.java index e32b8e0..dc79cfe 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/database/ConnectionFactory.java +++ b/src/main/java/org/onap/dmaap/dbcapi/database/ConnectionFactory.java @@ -58,10 +58,19 @@ public class ConnectionFactory { Properties p = DmaapConfig.getConfig(); host = p.getProperty("DB.host", "dcae-pstg-write-ftl.domain.notset.com"); dbname = p.getProperty("DB.name", "dmaap"); - dbuser = p.getProperty("DB.user", "dmaap_admin"); - dbcr = p.getProperty("DB.cred", "test234-ftl"); + dbuser = getValue(p, "DB.user", "dmaap_admin"); + dbcr = getValue(p, "DB.cred", "test234-ftl"); schema = p.getProperty("DB.schema", "public"); } + + private static String getValue(final Properties props, final String value, final String defaultValue) { + String prop = props.getProperty(value, defaultValue); + if (prop != null && prop.matches("[$][{].*[}]$")) { + return System.getenv(prop.substring(2, prop.length() - 1)); + } + return prop; + } + public static ConnectionFactory getDefaultInstance() { return(instance); }