public class EnvVarDestinationLoader extends Object implements DestinationLoader
DestinationLoader
implementation reading the destination from an environment variable.
The environment variable is expected to be a JSON array of JSON object containing a field called name
. All
other fields of the JSON object will be converted to String
and put into the created Destination
object.
Valid example:
destinations='[{"name"="destinationName", "url"="www.sap.de"}, {"name"="destinationName2", "url"="www.sap.com"}]'
Constructor and Description |
---|
EnvVarDestinationLoader()
Creates a new instance of
EnvVarDestinationLoader reading the destinations variable from the
system environment variables. |
EnvVarDestinationLoader(Function<String,String> environmentVariableAccessor,
Function<String,DefaultDestination> destinationJsonParser,
String variableName)
Creates a new instance of
EnvVarDestinationLoader reading variable with the provided name from the
provided function. |
EnvVarDestinationLoader(Function<String,String> environmentVariableAccessor,
String variableName)
Creates a new instance of
EnvVarDestinationLoader reading variable with the provided name from the
provided function. |
Modifier and Type | Method and Description |
---|---|
io.vavr.control.Try<DefaultDestination> |
loadTypedDestination(String destinationName,
DestinationOptions options)
This executes the same logic as
DestinationLoader.tryGetDestination(String) but provides the returned Destination
in a more specific type. |
io.vavr.control.Try<Destination> |
tryGetDestination(String destinationName,
DestinationOptions options)
Retrieves a destination for the given name and configuration options.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
tryGetDestination
public EnvVarDestinationLoader()
EnvVarDestinationLoader
reading the destinations
variable from the
system environment variables.public EnvVarDestinationLoader(@Nullable Function<String,String> environmentVariableAccessor, @Nullable Function<String,DefaultDestination> destinationJsonParser, @Nullable String variableName)
EnvVarDestinationLoader
reading variable with the provided name from the
provided function.environmentVariableAccessor
- A function returning the environment variable for a given name parameter. If null
is passed,
this will fall back to System.getenv(String)
.destinationJsonParser
- A function returning the DefaultDestination
after parsing the JSON. If null
is passed,
a default implementation is used.variableName
- The name of the environment variable to read. If null
is passed this will fall back to
destinations
.public EnvVarDestinationLoader(@Nullable Function<String,String> environmentVariableAccessor, @Nullable String variableName)
EnvVarDestinationLoader
reading variable with the provided name from the
provided function.environmentVariableAccessor
- A function returning the environment variable for a given name parameter. If null
is passed
this will fall back to System.getenv(String)
.variableName
- The name of the environment variable to read. If null
is passed this will fall back to
destinations
.@Nonnull public io.vavr.control.Try<Destination> tryGetDestination(@Nonnull String destinationName, @Nonnull DestinationOptions options)
The returned Try
object will contain a
DestinationNotFoundException
in case the
destination could not be found or a
DestinationAccessException
with more details in
case something else went wrong.
If the returned Try
object contains no Exception it will always contain a non-null Destination
value.
tryGetDestination
in interface DestinationLoader
destinationName
- The name of the destination to obtain.options
- Additional settings to modify the behaviour of the destination loader.Try
object containing either the non-null Destination
value or an exception.@Nonnull public io.vavr.control.Try<DefaultDestination> loadTypedDestination(@Nonnull String destinationName, @Nonnull DestinationOptions options)
DestinationLoader.tryGetDestination(String)
but provides the returned Destination
in a more specific type.destinationName
- The name of the destination to obtain.options
- Additional settings to modify the behaviour of the destination loader.Try
object containing either the non-null DefaultDestination
value or an exception.Copyright © 2021 SAP SE. All rights reserved.