Class EnvUtils
java.lang.Object
fr.codinbox.connector.commons.utils.EnvUtils
Utility class for reading connector configuration from environment variables.
Each connector type uses a specific prefix for its environment variables:
- Redis: "CONNECTOR_REDIS_"
- Database: "CONNECTOR_DB_"
- RabbitMQ: "CONNECTOR_RABBITMQ_"
- Kafka: "CONNECTOR_KAFKA_"
Environment variables follow the pattern
<PREFIX><CONNECTION_ID>_<PROPERTY>, for example
CONNECTOR_REDIS_MAIN_CONFIG=/path/to/config.yml.
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionEnvironment variable prefix for Kafka connections.Environment variable prefix for database connections.Environment variable prefix for RabbitMQ connections.Environment variable prefix for Redis connections. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanChecks whether the given string represents a booleantruevalue.static StringgetConfigFilepath(@NotNull ConnectionType connectionType, @NotNull String id) Retrieves the configuration file path for the given connection from environment variables.getEnvironmentIds(@NotNull ConnectionType connectionType) Discovers all configured connection identifiers for the given connection type by scanning environment variable names.getPrefix(@NotNull ConnectionType connectionType) Returns the environment variable prefix for the given connection type.static booleanisExitOnFailure(@NotNull ConnectionType connectionType, @NotNull String id) Determines whether the given connection should cause the server to exit on initialization failure.
-
Field Details
-
REDIS_PREFIX
Environment variable prefix for Redis connections.- See Also:
-
MYSQL_PREFIX
Environment variable prefix for database connections.- See Also:
-
RABBITMQ_PREFIX
Environment variable prefix for RabbitMQ connections.- See Also:
-
KAFKA_PREFIX
Environment variable prefix for Kafka connections.- See Also:
-
-
Constructor Details
-
EnvUtils
public EnvUtils()
-
-
Method Details
-
getPrefix
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
Checks whether the given string represents a booleantruevalue.Recognized true values are
"true"and"1"(case-insensitive). All other values, includingnull, returnfalse.- Parameters:
value- the string to check, may benull- Returns:
trueif 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 typeid- the connection identifier- Returns:
trueif 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 typeid- the connection identifier- Returns:
- the configuration file path, or
nullif 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_CONFIGandCONNECTOR_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
-