diff options
author | Jesse Morgan <jesse@jesterpm.net> | 2016-03-19 16:42:31 -0700 |
---|---|---|
committer | Jesse Morgan <jesse@jesterpm.net> | 2016-03-19 16:42:31 -0700 |
commit | cac52cf3a07fb4c032f352ec48b56640b246f04f (patch) | |
tree | 8d389d5c2df73bdbe5abfd3337cc6b24d2bf61b0 /src/com/p4square/grow/config/Config.java | |
parent | 1d6a768d6b6670a523941ad25ab333b1e0bef122 (diff) |
Adding feature to set configs and domain with environment variables.
Diffstat (limited to 'src/com/p4square/grow/config/Config.java')
-rw-r--r-- | src/com/p4square/grow/config/Config.java | 30 |
1 files changed, 26 insertions, 4 deletions
diff --git a/src/com/p4square/grow/config/Config.java b/src/com/p4square/grow/config/Config.java index e89990b..2fc2ea3 100644 --- a/src/com/p4square/grow/config/Config.java +++ b/src/com/p4square/grow/config/Config.java @@ -35,12 +35,27 @@ public class Config { private Properties mProperties; /** - * Construct a new Config object. Domain defaults to prod. + * Construct a new Config object. + * + * Sets the domain to the value of the system property CONFIG_DOMAIN, if present. + * If the system property is not set then the environment variable CONFIG_DOMAIN is checked. + * If neither are set the domain defaults to prod. */ public Config() { - mDomain = "prod"; - mProperties = new Properties(); + // Check the command line for a domain property. + mDomain = System.getProperty("CONFIG_DOMAIN"); + + // If the domain was not set with a property, check for an environment variable. + if (mDomain == null) { + mDomain = System.getenv("CONFIG_DOMAIN"); + } + + // If neither were set, default to prod + if (mDomain == null) { + mDomain = "prod"; + } + mProperties = new Properties(); } /** @@ -62,7 +77,7 @@ public class Config { /** * Load properties from a file. - * Any exceptions are logged and suppressed. + * Any exception are logged and suppressed. */ public void updateConfig(String propertyFilename) { final File propFile = new File(propertyFilename); @@ -114,6 +129,13 @@ public class Config { return result; } + // Environment variables can also override configs + result = System.getenv(key); + if (result != null) { + LOG.debug("Reading System.getenv(" + key + "). Got result = { " + result + " }"); + return result; + } + final String domainKey = mDomain + "." + key; result = mProperties.getProperty(domainKey); if (result != null) { |