Class EnvUtils

java.lang.Object
fr.codinbox.connector.commons.utils.EnvUtils

public final class EnvUtils extends Object
Utility class for reading connector configuration from environment variables.

Each connector type uses a specific prefix for its environment variables:

Environment variables follow the pattern <PREFIX><CONNECTION_ID>_<PROPERTY>, for example CONNECTOR_REDIS_MAIN_CONFIG=/path/to/config.yml.

See Also:
  • Field Details

  • Constructor Details

    • EnvUtils

      public EnvUtils()
  • Method Details

    • getPrefix

      @NotNull public static @NotNull String getPrefix(@NotNull @NotNull ConnectionType connectionType)
      Returns the environment variable prefix for the given connection type.
      Parameters:
      connectionType - the connection type
      Returns:
      the prefix string used in environment variable names
    • checkBool

      public static boolean checkBool(@Nullable @Nullable String value)
      Checks whether the given string represents a boolean true value.

      Recognized true values are "true" and "1" (case-insensitive). All other values, including null, return false.

      Parameters:
      value - the string to check, may be null
      Returns:
      true if the value represents a boolean true
    • isExitOnFailure

      @CheckReturnValue public static boolean isExitOnFailure(@NotNull @NotNull ConnectionType connectionType, @NotNull @NotNull String id)
      Determines whether the given connection should cause the server to exit on initialization failure.

      Reads the environment variable <PREFIX><ID>_EXIT_ON_FAILURE.

      Parameters:
      connectionType - the connection type
      id - the connection identifier
      Returns:
      true if the connection is configured to exit on failure
    • getConfigFilepath

      @CheckReturnValue public static String getConfigFilepath(@NotNull @NotNull ConnectionType connectionType, @NotNull @NotNull String id)
      Retrieves the configuration file path for the given connection from environment variables.

      Reads the environment variable <PREFIX><ID>_CONFIG.

      Parameters:
      connectionType - the connection type
      id - the connection identifier
      Returns:
      the configuration file path, or null if not set
    • getEnvironmentIds

      @CheckReturnValue public static List<String> getEnvironmentIds(@NotNull @NotNull ConnectionType connectionType)
      Discovers all configured connection identifiers for the given connection type by scanning environment variable names.

      For example, if the environment contains CONNECTOR_REDIS_MAIN_CONFIG and CONNECTOR_REDIS_MAIN_EXIT_ON_FAILURE, this method returns ["MAIN"].

      Parameters:
      connectionType - the connection type to scan for
      Returns:
      a list of distinct connection identifiers
      Throws:
      IllegalArgumentException - if an environment variable has an invalid format