Package com.azure.core.util
Class ConfigurationPropertyBuilder<T>
java.lang.Object
com.azure.core.util.ConfigurationPropertyBuilder<T>
- Type Parameters:
T
- The property value type.
Builds configuration property.
-
Constructor Summary
ConstructorDescriptionConfigurationPropertyBuilder
(String name, Function<String, T> converter) ConstructsConfigurationPropertyBuilder
instance. -
Method Summary
Modifier and TypeMethodDescriptionSets one or more alias for property.build()
Builds configuration property instance.defaultValue
(T defaultValue) Sets default property value.environmentVariableName
(String environmentVariableName) Sets environment variable name that can represent this property if explicit configuration is not set.logValue
(boolean logValue) Sets flag indicating if property value can be logged.static ConfigurationPropertyBuilder<Boolean>
CreatesConfigurationPropertyBuilder
configured to log property value and parse value usingBoolean.parseBoolean(String)
.static ConfigurationPropertyBuilder<Duration>
ofDuration
(String name) CreatesConfigurationPropertyBuilder
configured to log property value and parses value as long number of milliseconds, proxyingNumberFormatException
exception.static ConfigurationPropertyBuilder<Integer>
CreatesConfigurationPropertyBuilder
configured to log property value and parse value usingInteger.valueOf(String)
, proxyingNumberFormatException
exception.static ConfigurationPropertyBuilder<String>
Creates defaultConfigurationPropertyBuilder
.required
(boolean required) Sets flag indicating if property is required.shared
(boolean shared) Sets flag indicating that property can be provided in the shared configuration section in addition to client-specific configuration section.systemPropertyName
(String systemPropertyName) Sets system property name that can represent this property if explicit configuration is not set.
-
Constructor Details
-
ConfigurationPropertyBuilder
ConstructsConfigurationPropertyBuilder
instance.ConfigurationProperty<SampleEnumProperty> modeProperty = new ConfigurationPropertyBuilder<>("mode", SampleEnumProperty::fromString) .logValue(true) .defaultValue(SampleEnumProperty.MODE_1) .build(); System.out.println(configuration.get(modeProperty));
- Parameters:
name
- name of the property.converter
- Converter used to map the configuration toT
.
-
-
Method Details
-
ofString
Creates defaultConfigurationPropertyBuilder
. String property values are redacted in logs by default. If property value does not contain sensitive information, uselogValue(boolean)
to enable logging.ConfigurationProperty<String> property = ConfigurationPropertyBuilder.ofString("http.proxy.hostname") .shared(true) .logValue(true) .systemPropertyName("http.proxyHost") .build(); // attempts to get local `azure.sdk.<client-name>.http.proxy.host` property and falls back to // shared azure.sdk.http.proxy.port System.out.println(configuration.get(property));
- Parameters:
name
- property name.- Returns:
- instance of
ConfigurationPropertyBuilder
.
-
ofInteger
CreatesConfigurationPropertyBuilder
configured to log property value and parse value usingInteger.valueOf(String)
, proxyingNumberFormatException
exception.ConfigurationProperty<Integer> integerProperty = ConfigurationPropertyBuilder.ofInteger("retry-count") .build(); System.out.println(configuration.get(integerProperty));
- Parameters:
name
- property name.- Returns:
- instance of
ConfigurationPropertyBuilder
.
-
ofDuration
CreatesConfigurationPropertyBuilder
configured to log property value and parses value as long number of milliseconds, proxyingNumberFormatException
exception.ConfigurationProperty<Duration> timeoutProperty = ConfigurationPropertyBuilder.ofDuration("timeout") .build(); System.out.println(configuration.get(timeoutProperty));
- Parameters:
name
- property name.- Returns:
- instance of
ConfigurationPropertyBuilder
.
-
ofBoolean
CreatesConfigurationPropertyBuilder
configured to log property value and parse value usingBoolean.parseBoolean(String)
.ConfigurationProperty<Boolean> booleanProperty = ConfigurationPropertyBuilder.ofBoolean("is-enabled") .build(); System.out.println(configuration.get(booleanProperty));
- Parameters:
name
- property name.- Returns:
- instance of
ConfigurationPropertyBuilder
.
-
defaultValue
Sets default property value.null
by default.- Parameters:
defaultValue
- value to be returned byConfiguration.get(ConfigurationProperty)
if the property isn't found.- Returns:
- the updated ConfigurationPropertyBuilder object.
-
logValue
Sets flag indicating if property value can be logged. Default isfalse
, indicating that property value should not be logged. When and if retrieving of corresponding configuration property is logged,Configuration
will use "redacted" string instead of property value. If flag is set totrue
, value is populated on the logs as is.- Parameters:
logValue
- If set totrue
,Configuration.get(ConfigurationProperty)
will log property value, Otherwise, value is redacted.- Returns:
- the updated ConfigurationPropertyBuilder object.
-
required
Sets flag indicating if property is required. Default isfalse
, indicating that property is optional.- Parameters:
required
- If set totrue
,Configuration.get(ConfigurationProperty)
will throw when property is not found.- Returns:
- the updated ConfigurationPropertyBuilder object.
-
aliases
Sets one or more alias for property.Configuration.get(ConfigurationProperty)
attempts to retrieve property by name first and only then tries to retrieve properties by alias in the order aliases are provided.- Parameters:
aliases
- one or more alias for the property name.- Returns:
- the updated ConfigurationPropertyBuilder object.
-
environmentVariableName
Sets environment variable name that can represent this property if explicit configuration is not set.When property value is not found by
name
oralias
,Configuration.get(ConfigurationProperty)
falls back to system properties and environment variables. When environment variable (or system property) is not set,Configuration.get(ConfigurationProperty)
does not attempt to read environment configuration.- Parameters:
environmentVariableName
- environment variable name.- Returns:
- the updated ConfigurationPropertyBuilder object.
-
systemPropertyName
Sets system property name that can represent this property if explicit configuration is not set.When property value is not found by
name
oralias
,Configuration.get(ConfigurationProperty)
falls back to system properties and environment variables. When environment variable (or system property) is not set,Configuration.get(ConfigurationProperty)
does not attempt to read environment configuration.- Parameters:
systemPropertyName
- one or more environment variable (or system property).- Returns:
- the updated ConfigurationPropertyBuilder object.
-
build
Builds configuration property instance.- Returns:
ConfigurationProperty
instance.
-