Class ExternalConfigProvider

  • All Implemented Interfaces:
    ConfigProvider

    public class ExternalConfigProvider
    extends Object
    implements ConfigProvider
    Config provider that looks up configuration values from a known properties file. This provider loads the properties so that other providers can access the values.

    The provider will look for the external config file in the following order:

    1. System property with the given system property key
    2. System property with the default system property key (kiwi.external.config.path)
    3. Environment variable with the given variable name
    4. Environment variable with the default variable name (KIWI_EXTERNAL_CONFIG_PATH)
    5. The given properties path
    6. The default properties path (~/.kiwi.external.config.properties)
    • Method Detail

      • canProvide

        public boolean canProvide()
        This provider can provide if the properties have been loaded from the given file
        Specified by:
        canProvide in interface ConfigProvider
        Returns:
        true if properties are loaded, false otherwise.
      • getProperty

        public Optional<String> getProperty​(String propertyKey)
        Returns a property for a given key if it exists otherwise an Optional.empty().
        Parameters:
        propertyKey - the key of the property to look up
        Returns:
        An Optional with the requested property or empty if not found
      • usePropertyIfPresent

        public void usePropertyIfPresent​(String propertyKey,
                                         Consumer<String> propertyValueConsumer,
                                         Runnable orElse)
        Executes given consumer if the requested property is found, otherwise runs the orElse function.
        Parameters:
        propertyKey - the key of the property to look up
        propertyValueConsumer - a consumer to process the value of the property if found
        orElse - a runnable to execute if the property is not found
      • resolveExternalProperty

        public <T> ResolverResult<T> resolveExternalProperty​(String propertyKey,
                                                             Function<String,​ResolverResult<T>> propertyValueFunction,
                                                             Supplier<ResolverResult<T>> orElseSupplier)
        Executes a given function if the requested property is found, otherwise runs the orElseSupplier supplier.
        Type Parameters:
        T - The class type of the value inside the ResolverResult
        Parameters:
        propertyKey - the key of the property to look up
        propertyValueFunction - a function to process the value of the property if found and return a ResolverResult
        orElseSupplier - a supplier to execute if the property is not found and return a ResolverResult
        Returns:
        a ResolverResult containing the resolved value and the resolution method