Class QMetaDataVariableInterpreter

java.lang.Object
com.kingsrook.qqq.backend.core.instances.QMetaDataVariableInterpreter

public class QMetaDataVariableInterpreter extends Object
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 Details

    • QMetaDataVariableInterpreter

      public QMetaDataVariableInterpreter()
  • Method Details

    • interpretObject

      public void interpretObject(Object o) throws QException
      Throws:
      QException
    • interpret

      public String interpret(String value)
      Interpret a value string, which may be a variable, into its run-time value - always as a String.
    • interpretForObject

      public Serializable interpretForObject(String value)
      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

      protected void setEnvironmentOverrides(Map<String,String> environmentOverrides)
      Setter for environmentOverrides - protected - meant to be called (at least at this time), only in unit test
    • addValueMap

      public void addValueMap(String name, Map<String,Serializable> values)
    • getStringFromPropertyOrEnvironment

      public String 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.
    • getBooleanFromPropertyOrEnvironment

      public 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

      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!)