From f364a4d6dcf77c3143c4cf289a5fb0e900582ce4 Mon Sep 17 00:00:00 2001 From: Steve Hu Date: Wed, 4 Sep 2024 20:51:46 -0400 Subject: [PATCH] fixes #2334 make convertEnvVars configurable to work with lower case envs --- .../src/main/java/com/networknt/config/ConfigInjection.java | 5 +++++ config/src/main/resources/config/config.yml | 6 ++++++ 2 files changed, 11 insertions(+) diff --git a/config/src/main/java/com/networknt/config/ConfigInjection.java b/config/src/main/java/com/networknt/config/ConfigInjection.java index 3d8a691377..a2138883fa 100644 --- a/config/src/main/java/com/networknt/config/ConfigInjection.java +++ b/config/src/main/java/com/networknt/config/ConfigInjection.java @@ -52,6 +52,7 @@ public class ConfigInjection { private static final String SCALABLE_CONFIG = "config"; private static final String EXCLUSION_CONFIG_FILE_LIST = "exclusionConfigFileList"; private static final String ALLOW_DEFAULT_EMPTY = "allowDefaultValueEmpty"; + private static final String CONVERT_ENV_VARS = "convertEnvVars"; private static final Map exclusionMap = Config.getInstance().getJsonMapConfig(SCALABLE_CONFIG); @@ -107,6 +108,10 @@ static String convertEnvVars(String input){ if (input == null) { return null; } + if (exclusionMap.get(CONVERT_ENV_VARS) != null && !(Boolean)exclusionMap.get(CONVERT_ENV_VARS)) { + // only if the flag is set to false, then don't convert. + return input; + } return input.replaceAll("[^A-Za-z0-9]", "_").toUpperCase(); } diff --git a/config/src/main/resources/config/config.yml b/config/src/main/resources/config/config.yml index 60f210df98..fa0671cac2 100644 --- a/config/src/main/resources/config/config.yml +++ b/config/src/main/resources/config/config.yml @@ -29,3 +29,9 @@ decryptorClass: com.networknt.decrypt.AutoAESSaltDecryptor # would be negative impact on the application security. The following config will ensure that # null will be used when the default value is empty without stopping the server during the start. allowDefaultValueEmpty: true + +# For some operating systems, environment variable can be only upper case, to make sure they can +# match the key defined in each config files, we can convert the env vars to upper case to match. +# The default value is true, and it will cover most operating systems (Linux and Windows). Change +# this value to false if you have lower or mix case environment variable names. +convertEnvVars: true