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 Details

    • CONFIG_FILE_NAME

      public static final String CONFIG_FILE_NAME
      The name of the properties file used for configuration; "secretsmanager.properties".
      See Also:
  • Method Details

    • 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 Config with the properties from the file and the system properties as defaults.
    • loadMainConfig

      public static Config loadMainConfig()
      Loads a configuration from CONFIG_FILE_NAME. Will use the System properties as defaults.
      Returns:
      Config A new Config with the properties from the CONFIG_FILE_NAME file and the system properties as defaults.
    • getSubconfig

      public Config getSubconfig(String subprefix)
      Extracts all of the properties for a given subprefix into its own Config object. 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 this Config object.
      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 a String property 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 String property or a default value if the property is not set.
    • getIntPropertyWithDefault

      public int getIntPropertyWithDefault(String propertyName, int defaultValue)
      Returns a int property 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 int property or a default value if the property is not set.
      Throws:
      PropertyException - If the property value is not a decimal int.
    • getLongPropertyWithDefault

      public long getLongPropertyWithDefault(String propertyName, long defaultValue)
      Returns a long property 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 long property or a default value if the property is not set.
      Throws:
      PropertyException - If the property value is not a decimal long.
    • getClassPropertyWithDefault

      public Class<?> getClassPropertyWithDefault(String propertyName, Class<?> defaultValue)
      Returns a Class property 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 Class property 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 a String property or throws a NoSuchElementException if the property is not set.
      Parameters:
      propertyName - The name of the property to retrieve.
      Returns:
      String The String property 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 a int property or throws a NoSuchElementException if the property is not set.
      Parameters:
      propertyName - The name of the property to retrieve.
      Returns:
      int The int property or a default value if the property is not set.
      Throws:
      PropertyException - If the property value is not a decimal int.
      NoSuchElementException - If the property is not set.
    • getRequiredLongProperty

      public long getRequiredLongProperty(String propertyName)
      Returns a long property or throws a NoSuchElementException if the property is not set.
      Parameters:
      propertyName - The name of the property to retrieve.
      Returns:
      long The long property or a default value if the property is not set.
      Throws:
      PropertyException - If the property value is not a decimal long.
      NoSuchElementException - If the property is not set.
    • getRequiredClassProperty

      public Class<?> getRequiredClassProperty(String propertyName)
      Returns a Class property or throws a NoSuchElementException if the property is not set.
      Parameters:
      propertyName - The name of the property to retrieve.
      Returns:
      Class The Class property 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.