[tomcat] 01/02: PropertySource: Add an environment variable based source
This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch 8.5.x in repository https://gitbox.apache.org/repos/asf/tomcat.git commit b58f02a0f88fead8ab5210566a396dae476d9362 Author: Thomas Meyer AuthorDate: Sat Jul 20 22:22:42 2019 +0200 PropertySource: Add an environment variable based source When tomcat runs in an Openshift based container a Secret containing passwords can be map as environment variables (with an additional prefix). An webapp containing an embedded context.xml which defines JDBC datasources and placeholder variables can be used with this new PropertySource to easily inject configuration from a Secret or ConfigMap. --- java/org/apache/tomcat/util/digester/Digester.java | 15 +++ webapps/docs/changelog.xml | 6 ++ webapps/docs/config/systemprops.xml| 9 +++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/java/org/apache/tomcat/util/digester/Digester.java b/java/org/apache/tomcat/util/digester/Digester.java index 59d59f0..f31518c 100644 --- a/java/org/apache/tomcat/util/digester/Digester.java +++ b/java/org/apache/tomcat/util/digester/Digester.java @@ -139,6 +139,21 @@ public class Digester extends DefaultHandler2 { } +public class EnvironmentPropertySource implements IntrospectionUtils.PropertySource { +@Override +public String getProperty(String key) { +ClassLoader cl = getClassLoader(); +if (cl instanceof PermissionCheck) { +Permission p = new RuntimePermission("getenv." + key, null); +if (!((PermissionCheck) cl).check(p)) { +return null; +} +} +return System.getenv(key); +} +} + + protected IntrospectionUtils.PropertySource source[] = new IntrospectionUtils.PropertySource[] { new SystemPropertySource() }; diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 75c640c..2cf2b54 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -57,6 +57,12 @@ Service is embedded directly (i.e. with no Server) in an applciation and JNDI is enabled. Patch provided by S. Ali Tokmen. (markt) + +Add a new PropertySource implementation, +EnvironmentPropertySource, that can be used to do property +replacement in configuration files with environment variables. Pull +request provided by Thomas Meyer. (markt) + diff --git a/webapps/docs/config/systemprops.xml b/webapps/docs/config/systemprops.xml index cb39fb1..5e37c42 100644 --- a/webapps/docs/config/systemprops.xml +++ b/webapps/docs/config/systemprops.xml @@ -43,11 +43,16 @@ Set this to a fully qualified name of a class that implements org.apache.tomcat.util.IntrospectionUtils.PropertySource. Required to have a public constructor with no arguments. - Use this to add a property source, that will be invoked when ${parameter} - denoted parameters are found in the XML files that Tomcat parses. + Use this to add a property source, that will be invoked when + ${parameter} denoted parameters are found in the XML files + that Tomcat parses. Property replacement from the specified property source on the JVM system properties can also be done using the REPLACE_SYSTEM_PROPERTIES system property. + org.apache.tomcat.util.digester.Digester$EnvironmentPropertySource + can be used to replace parameters from the process' environment + variables, e.g. injected ConfigMaps or Secret objects in container + based systems like OpenShift or Kubernetes. Set this boolean system property to true to cause - To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org
[tomcat] 01/02: PropertySource: Add an environment variable based source
This is an automated email from the ASF dual-hosted git repository. markt pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/tomcat.git commit 583a9f40ed033807db11827596e999f007264adb Author: Thomas Meyer AuthorDate: Sat Jul 20 22:22:42 2019 +0200 PropertySource: Add an environment variable based source When tomcat runs in an Openshift based container a Secret containing passwords can be map as environment variables (with an additional prefix). An webapp containing an embedded context.xml which defines JDBC datasources and placeholder variables can be used with this new PropertySource to easily inject configuration from a Secret or ConfigMap. --- java/org/apache/tomcat/util/digester/Digester.java | 15 +++ webapps/docs/changelog.xml | 6 ++ webapps/docs/config/systemprops.xml| 9 +++-- 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/java/org/apache/tomcat/util/digester/Digester.java b/java/org/apache/tomcat/util/digester/Digester.java index e3ed881..810274b 100644 --- a/java/org/apache/tomcat/util/digester/Digester.java +++ b/java/org/apache/tomcat/util/digester/Digester.java @@ -138,6 +138,21 @@ public class Digester extends DefaultHandler2 { } +public class EnvironmentPropertySource implements IntrospectionUtils.PropertySource { +@Override +public String getProperty(String key) { +ClassLoader cl = getClassLoader(); +if (cl instanceof PermissionCheck) { +Permission p = new RuntimePermission("getenv." + key, null); +if (!((PermissionCheck) cl).check(p)) { +return null; +} +} +return System.getenv(key); +} +} + + protected IntrospectionUtils.PropertySource source[] = new IntrospectionUtils.PropertySource[] { new SystemPropertySource() }; diff --git a/webapps/docs/changelog.xml b/webapps/docs/changelog.xml index 7bdf0e7..e89ca90 100644 --- a/webapps/docs/changelog.xml +++ b/webapps/docs/changelog.xml @@ -66,6 +66,12 @@ Service is embedded directly (i.e. with no Server) in an applciation and JNDI is enabled. Patch provided by S. Ali Tokmen. (markt) + +Add a new PropertySource implementation, +EnvironmentPropertySource, that can be used to do property +replacement in configuration files with environment variables. Pull +request provided by Thomas Meyer. (markt) + diff --git a/webapps/docs/config/systemprops.xml b/webapps/docs/config/systemprops.xml index a17687f..d49a67d 100644 --- a/webapps/docs/config/systemprops.xml +++ b/webapps/docs/config/systemprops.xml @@ -43,11 +43,16 @@ Set this to a fully qualified name of a class that implements org.apache.tomcat.util.IntrospectionUtils.PropertySource. Required to have a public constructor with no arguments. - Use this to add a property source, that will be invoked when ${parameter} - denoted parameters are found in the XML files that Tomcat parses. + Use this to add a property source, that will be invoked when + ${parameter} denoted parameters are found in the XML files + that Tomcat parses. Property replacement from the specified property source on the JVM system properties can also be done using the REPLACE_SYSTEM_PROPERTIES system property. + org.apache.tomcat.util.digester.Digester$EnvironmentPropertySource + can be used to replace parameters from the process' environment + variables, e.g. injected ConfigMaps or Secret objects in container + based systems like OpenShift or Kubernetes. Set this boolean system property to true to cause - To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org