Class Config
- java.lang.Object
-
- com.amazonaws.secretsmanager.util.Config
-
public final class Config extends Object
A class for accessing configuration information from a properties file or from the System properties. Properties defined in the file will override the properties set in the System properties. The properties file should be located somewhere on the class path for the class loader used to load this class.
The default file that properties will be fetched from is referred to by
Config.CONFIG_FILE_NAME.
-
-
Field Summary
Fields Modifier and Type Field Description static StringCONFIG_FILE_NAMEThe name of the properties file used for configuration; "secretsmanager.properties".
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description StringfullPropertyName(String propertyName)Extends a property name to be the full version written in the configuration file.Class<?>getClassPropertyWithDefault(String propertyName, Class<?> defaultValue)Returns aClassproperty or a default value if the property is not set.intgetIntPropertyWithDefault(String propertyName, int defaultValue)Returns aintproperty or a default value if the property is not set.longgetLongPropertyWithDefault(String propertyName, long defaultValue)Returns alongproperty or a default value if the property is not set.Class<?>getRequiredClassProperty(String propertyName)Returns aClassproperty or throws aNoSuchElementExceptionif the property is not set.intgetRequiredIntProperty(String propertyName)Returns aintproperty or throws aNoSuchElementExceptionif the property is not set.longgetRequiredLongProperty(String propertyName)Returns alongproperty or throws aNoSuchElementExceptionif the property is not set.StringgetRequiredStringProperty(String propertyName)Returns aStringproperty or throws aNoSuchElementExceptionif the property is not set.StringgetStringPropertyWithDefault(String propertyName, String defaultValue)Returns aStringproperty or a default value if the property is not set.ConfiggetSubconfig(String subprefix)Extracts all of the properties for a given subprefix into its ownConfigobject.static ConfigloadConfigFrom(String resourceName)Loads a configuration from a specific configuration file.static ConfigloadMainConfig()Loads a configuration fromCONFIG_FILE_NAME.
-
-
-
Field Detail
-
CONFIG_FILE_NAME
public static final String CONFIG_FILE_NAME
The name of the properties file used for configuration; "secretsmanager.properties".- See Also:
- Constant Field Values
-
-
Method Detail
-
loadConfigFrom
public static Config loadConfigFrom(String resourceName)
Loads a configuration from a specific configuration file. Will use the System properties as defaults.- Parameters:
resourceName- The name of the config file to load from.- Returns:
- Config A new
Configwith the properties from the file and the system properties as defaults.
-
loadMainConfig
public static Config loadMainConfig()
Loads a configuration fromCONFIG_FILE_NAME. Will use the System properties as defaults.- Returns:
- Config A new
Configwith the properties from theCONFIG_FILE_NAMEfile and the system properties as defaults.
-
getSubconfig
public Config getSubconfig(String subprefix)
Extracts all of the properties for a given subprefix into its ownConfigobject. The property names will be changed to no longer have the subprefix.- Parameters:
subprefix- The subprefix to get all of the properties for.- Returns:
- Config Configuration properties for the subprefix
-
fullPropertyName
public String fullPropertyName(String propertyName)
Extends a property name to be the full version written in the configuration file. This full name is not necessarily the name that the property is indexed with in thisConfigobject.- Parameters:
propertyName- The property name to extend.- Returns:
- String The full property name as written in the configuration file.
-
getStringPropertyWithDefault
public String getStringPropertyWithDefault(String propertyName, String defaultValue)
Returns aStringproperty or a default value if the property is not set.- Parameters:
propertyName- The name of the property to retrieve.defaultValue- The default value to use.- Returns:
- String The
Stringproperty or a default value if the property is not set.
-
getIntPropertyWithDefault
public int getIntPropertyWithDefault(String propertyName, int defaultValue)
Returns aintproperty or a default value if the property is not set.- Parameters:
propertyName- The name of the property to retrieve.defaultValue- The default value to use.- Returns:
- int The
intproperty or a default value if the property is not set. - Throws:
PropertyException- If the property value is not a decimalint.
-
getLongPropertyWithDefault
public long getLongPropertyWithDefault(String propertyName, long defaultValue)
Returns alongproperty or a default value if the property is not set.- Parameters:
propertyName- The name of the property to retrieve.defaultValue- The default value to use.- Returns:
- long The
longproperty or a default value if the property is not set. - Throws:
PropertyException- If the property value is not a decimallong.
-
getClassPropertyWithDefault
public Class<?> getClassPropertyWithDefault(String propertyName, Class<?> defaultValue)
Returns aClassproperty or a default value if the property is not set.- Parameters:
propertyName- The name of the property to retrieve.defaultValue- The default value to use.- Returns:
- Class The
Classproperty or a default value if the property is not set. - Throws:
PropertyException- If the class name does not exist in this class loader.
-
getRequiredStringProperty
public String getRequiredStringProperty(String propertyName)
Returns aStringproperty or throws aNoSuchElementExceptionif the property is not set.- Parameters:
propertyName- The name of the property to retrieve.- Returns:
- String The
Stringproperty or a default value if the property is not set. - Throws:
NoSuchElementException- If the property is not set.
-
getRequiredIntProperty
public int getRequiredIntProperty(String propertyName)
Returns aintproperty or throws aNoSuchElementExceptionif the property is not set.- Parameters:
propertyName- The name of the property to retrieve.- Returns:
- int The
intproperty or a default value if the property is not set. - Throws:
PropertyException- If the property value is not a decimalint.NoSuchElementException- If the property is not set.
-
getRequiredLongProperty
public long getRequiredLongProperty(String propertyName)
Returns alongproperty or throws aNoSuchElementExceptionif the property is not set.- Parameters:
propertyName- The name of the property to retrieve.- Returns:
- long The
longproperty or a default value if the property is not set. - Throws:
PropertyException- If the property value is not a decimallong.NoSuchElementException- If the property is not set.
-
getRequiredClassProperty
public Class<?> getRequiredClassProperty(String propertyName)
Returns aClassproperty or throws aNoSuchElementExceptionif the property is not set.- Parameters:
propertyName- The name of the property to retrieve.- Returns:
- Class The
Classproperty or a default value if the property is not set. - Throws:
PropertyException- If the class name does not exist in this class loader.NoSuchElementException- If the property is not set.
-
-