Class QMetaDataVariableInterpreter
java.lang.Object
com.kingsrook.qqq.backend.core.instances.QMetaDataVariableInterpreter
To avoid having secrets (passwords, access keys, etc) committed into meta data
files, as well as to just let some meta data not be hard-coded, this class is
used by the Enricher to "promote" values, such as ${env.ACCESS_KEY}
to be read from the environment (or other secret providers (to be implemented)).
Supported syntax / value sources are:
${env.VAR} = system environment variables, e.g., export VAR=val
${prop.VAR} = properties, e.g., -DVAR=val
${literal.VAR} = get back a literal "VAR" (in case VAR matches some of the other supported syntax in here)
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
addValueMap
(String name, Map<String, Serializable> values) boolean
getBooleanFromPropertyOrEnvironment
(String systemPropertyName, String environmentVariableName, boolean defaultIfNotSet) First look for a boolean ("true" or "false") in the specified system property - Next look for a boolean in the specified env var name - Finally return the default.getIntegerFromPropertyOrEnvironment
(String systemPropertyName, String environmentVariableName, Integer defaultIfNotSet) First look for an Integer in the specified system property - Next look for an Integer in the specified env var name - Finally return the default (null allowed as default!)getStringFromPropertyOrEnvironment
(String systemPropertyName, String environmentVariableName, String defaultIfNotSet) First look for a string in the specified system property - Next look for a string in the specified env var name - Finally return the default.Interpret a value string, which may be a variable, into its run-time value - always as a String.interpretForObject
(String value) Interpret a value string, which may be a variable, into its run-time value.interpretForObject
(String value, Serializable defaultIfLooksLikeVariableButNotFound) Interpret a value string, which may be a variable, into its run-time value, getting back the specified default if the string looks like a variable, but can't be found.void
protected void
setEnvironmentOverrides
(Map<String, String> environmentOverrides) Setter for environmentOverrides - protected - meant to be called (at least at this time), only in unit test
-
Constructor Details
-
QMetaDataVariableInterpreter
public QMetaDataVariableInterpreter()
-
-
Method Details
-
interpretObject
- Throws:
QException
-
interpret
-
interpretForObject
Interpret a value string, which may be a variable, into its run-time value. If input is null, output is null. If input looks like ${env.X}, then the return value is the value of the env variable 'X' If input looks like ${prop.X}, then the return value is the value of the system property 'X' If input looks like ${literal.X}, then the return value is the literal 'X' - used if you really want to get back the literal value, ${env.X}, for example. Else the output is the input. -
interpretForObject
public Serializable interpretForObject(String value, Serializable defaultIfLooksLikeVariableButNotFound) Interpret a value string, which may be a variable, into its run-time value, getting back the specified default if the string looks like a variable, but can't be found. Where "looks like" means, for example, started with "${env." and ended with "}", but wasn't set in the environment, or, more interestingly, based on the valueMaps - only if the name to the left of the dot is an actual valueMap name. If input is null, output is null. If input looks like ${env.X}, then the return value is the value of the env variable 'X' If input looks like ${prop.X}, then the return value is the value of the system property 'X' If input looks like ${literal.X}, then the return value is the literal 'X' - used if you really want to get back the literal value, ${env.X}, for example. Else the output is the input. -
setEnvironmentOverrides
-
addValueMap
-
getStringFromPropertyOrEnvironment
-
getBooleanFromPropertyOrEnvironment
-
getIntegerFromPropertyOrEnvironment
public Integer getIntegerFromPropertyOrEnvironment(String systemPropertyName, String environmentVariableName, Integer defaultIfNotSet) First look for an Integer in the specified system property - Next look for an Integer in the specified env var name - Finally return the default (null allowed as default!)
-