Class PropertyRetriever

java.lang.Object
com.illumon.util.PropertyRetriever

public class PropertyRetriever extends Object
Class to assist with retrieving properties such as passwords from environment variables, files, and properties.
  • Constructor Details

    • PropertyRetriever

      public PropertyRetriever()
  • Method Details

    • getProperty

      public static String getProperty(@NotNull com.fishlib.configuration.Configuration configuration, @NotNull String propertyMeaning, @Nullable String environmentVariable, @Nullable String fileProperty, @Nullable String propertyName, boolean base64Encoded)
      Return a property value from a set of possible locations, allowing for optional base64 decoding. The following order is used.
      • First, if an environment variable is provided, it is checked. if it exists, then it is returned, base64-decoded if requested.
      • Next, the property file is checked if the property is provided (the configuration is checked for the provided property, and the resulting property value defines the filename). If it exists, the contents are read, base64-decoded if requested, then returned.
      • Finally, the property is checked. If it exists it is base64-decoded if requested and returned.
      • At least one of environmentVariable, fileProperty, or propertyName must be specified and exist.
      • If both a property file and property name are provided and exist in the Configuration instance, an exception will be thrown.
      Parameters:
      configuration - the Configuration instance to check
      propertyMeaning - a user-friendly property meaning, included in thrown exceptions
      environmentVariable - an optional environment variable to check for the value
      fileProperty - an optional Configuration property that specifies the file that contains the value
      propertyName - an optional Configuration property that specifies the value
      base64Encoded - if true, the retrieved value is base64 decoded before being returned to the caller
      Returns:
      the found value, base64-decoded if requested