public class EnvironmentVariables extends Object
The
MP config specification describes the environment variables ConfigSource as follows:
Some operating systems allow only alphabetic characters or an underscore, _, in environment variables. Other characters such as ., /, etc may be disallowed. In order to set a value for a config property that has a name containing such disallowed characters from an environment variable, the following rules are used. This ConfigSource searches 3 environment variables for a given property name (e.g. com.ACME.size): 1. Exact match (i.e. com.ACME.size) 2. Replace the character that is neither alphanumeric nor _ with _ (i.e. com_ACME_size) 3. Replace the character that is neither alphanumeric nor _ with _ and convert to upper case (i.e. COM_ACME_SIZE) The first environment variable that is found is returned by this ConfigSource.
The spec assumes the mapping takes place during search, where the desired key is known, but Helidon merges
ConfigSources instead; therefore this implementation produces additional KV pairs with aliases
for any variable that can meaningfully be mapped. See shouldAlias(String) for the mapping criteria.
Since Helidon supports many configuration keys that contain '-' (e.g. "server.executor-service.max-pool-size"),
an additional mapping is required to produce a matching alias. Given that it must map from legal environment variable names
and reduce the chances of inadvertent mappings, a verbose mapping is used: "_dash_" substrings (upper and lower case)
are first replaced by '-'. See expand() for the aliases produced.
| Modifier and Type | Method and Description |
|---|---|
static Map<String,String> |
expand()
Returns the environment variables and their aliases.
|
static Map<String,String> |
expand(Map<String,String> env)
Returns the environment variables and their aliases.
|
static boolean |
shouldAlias(String name)
Tests whether aliases should be created for the given environment variable name.
|
public static boolean shouldAlias(String name)
To provide a meaningful alias, the name must meet all of the following criteria:
'_' character"__"'_' charactersname - The environment variable name.true if aliases should be created.public static Map<String,String> expand()
The following mappings are applied to any environment variable name for which shouldAlias(String) returns
true:
"_dash_" by '-', e.g. "SERVER_EXECUTOR_dash_SERVICE_MAX_dash_POOL_dash_SIZE" becomes
"SERVER_EXECUTOR-SERVICE_MAX-POOL-SIZE".'_' by '.' and add as a alias, e.g. "com_ACME_size" becomes "com.ACME.size"
and "SERVER_EXECUTOR-SERVICE_MAX-POOL-SIZE" becomes "SERVER.EXECUTOR-SERVICE.MAX-POOL-SIZE". This mapping
is added primarily to support mixed case config keys such as "app.someCamelCaseKey"."com.ACME.size" becomes
"com.acme.size" and "SERVER.EXECUTOR-SERVICE.MAX-POOL-SIZE" becomes
"server.executor-service.max-pool-size".
System.getenv() including aliases.public static Map<String,String> expand(Map<String,String> env)
The following mappings are applied to any environment variable name for which shouldAlias(String) returns
true:
"_dash_" by '-', e.g. "SERVER_EXECUTOR_dash_SERVICE_MAX_dash_POOL_dash_SIZE" becomes
"SERVER_EXECUTOR-SERVICE_MAX-POOL-SIZE".'_' by '.' and add as an alias, e.g. "com_ACME_size" becomes "com.ACME.size"
and "SERVER_EXECUTOR-SERVICE_MAX-POOL-SIZE" becomes "SERVER.EXECUTOR-SERVICE.MAX-POOL-SIZE". This mapping
is added primarily to support mixed case config keys such as "app.someCamelCaseKey"."com.ACME.size" becomes
"com.acme.size" and "SERVER.EXECUTOR-SERVICE.MAX-POOL-SIZE" becomes
"server.executor-service.max-pool-size".
env - The environment variables.env with aliases added.Copyright © 2018–2019 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms.