Package com.illumon.util
Class PropertyRetriever
java.lang.Object
com.illumon.util.PropertyRetriever
Class to assist with retrieving properties such as passwords from environment variables, files, and properties.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
getProperty
(com.fishlib.configuration.Configuration configuration, String propertyMeaning, String environmentVariable, String fileProperty, String propertyName, boolean base64Encoded) Return a property value from a set of possible locations, allowing for optional base64 decoding.
-
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 checkpropertyMeaning
- a user-friendly property meaning, included in thrown exceptionsenvironmentVariable
- an optional environment variable to check for the valuefileProperty
- an optional Configuration property that specifies the file that contains the valuepropertyName
- an optional Configuration property that specifies the valuebase64Encoded
- if true, the retrieved value is base64 decoded before being returned to the caller- Returns:
- the found value, base64-decoded if requested
-