java.lang.Object
io.aiven.commons.system.EnvCheck
Checks URLs against the URLs allowed as per the
org.apache.kafka.sasl.oauthbearer.allowed.urls environment variable.
If the variable is not set all URLs are allowed.-
Nested Class Summary
Nested Classes -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanallowed(EnvCheck.Type type, String value) Checks if the URL is allowed as per theorg.apache.kafka.sasl.oauthbearer.allowed.urlsenvironment variable.static StringformatError(EnvCheck.Type type, String value) Format the error message for the specified URL.Return an updatable version of the environment variables.static voidthrowIfNotAllowed(EnvCheck.Type type, String value) Thorw an exception if the specified URL is not listed in theorg.apache.kafka.sasl.oauthbearer.allowed.urlsenvironment variable.
-
Method Details
-
formatError
Format the error message for the specified URL.- Parameters:
type- the type check that failedvalue- the value to create an error message for.- Returns:
- the error message.
-
allowed
Checks if the URL is allowed as per theorg.apache.kafka.sasl.oauthbearer.allowed.urlsenvironment variable.- Parameters:
type- the type to check.value- the value to check.- Returns:
trueif the value is listed in the environment variable for the type,falseif the environment variable is not set or the value is not listed.
-
throwIfNotAllowed
public static void throwIfNotAllowed(EnvCheck.Type type, String value) throws IllegalArgumentException Thorw an exception if the specified URL is not listed in theorg.apache.kafka.sasl.oauthbearer.allowed.urlsenvironment variable.- Parameters:
type- the type to check.value- the value to check- Throws:
IllegalArgumentException- if theallowed(Type, String)returns false.
-
getEnvVars
Return an updatable version of the environment variables. Changes to the map will be reflected in the system environment variables.This method will only work if the command line options
--add-opens java.base/java.util=io.aiven.commons.systemand--add-opens java.base/java.lang=io.aiven.commons.systemare used.Changes made to the returned map change the environment variables. This is handy for testing but should be done in a
try-catch-finallyblock with the values being reset in the finally block.To remove an environment variable use the
Map.remove(Object)method. Setting the map value tonullwill throw an exception.- Returns:
- a modifiable map backed by the system environment variables.
- Throws:
NoSuchFieldException- Should not be thrown. Indicates a change to theCollections.UnmodifiableMapimplementation.IllegalAccessException- if the command line options were not specified when the JVM was loaded.
-