Class KeyClientBuilder
- java.lang.Object
-
- com.azure.security.keyvault.keys.KeyClientBuilder
-
public final class KeyClientBuilder extends Object
This class provides a fluent builder API to help aid the configuration and instantiation of thesecret async client
andsecret sync client
, by callingbuildAsyncClient
andbuildClient
respectively. It constructs an instance of the desired client.The minimal configuration options required by
KeyClientBuilder
to buildKeyAsyncClient
arevaultUrl
andcredential
.KeyAsyncClient keyAsyncClient = new KeyClientBuilder() .vaultUrl("https://myvault.azure.net/") .credential(new DefaultAzureCredentialBuilder().build()) .buildAsyncClient();
The
log detail level
, multiple custompolicies
and customhttp client
can be optionally configured in theKeyClientBuilder
.KeyAsyncClient keyAsyncClient = new KeyClientBuilder() .vaultUrl("https://myvault.azure.net/") .credential(new DefaultAzureCredentialBuilder().build()) .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS)) .httpClient(HttpClient.createDefault()) .buildAsyncClient();
Alternatively, custom
http pipeline
with customHttpPipelinePolicy
policies andvaultUrl
can be specified. It provides finer control over the construction ofKeyAsyncClient
andKeyClient
HttpPipeline pipeline = new HttpPipelineBuilder() .policies(new KeyVaultCredentialPolicy(new DefaultAzureCredentialBuilder().build()), new RetryPolicy()) .build(); KeyAsyncClient keyAsyncClient = new KeyClientBuilder() .pipeline(pipeline) .vaultUrl("https://myvault.azure.net/") .buildAsyncClient();
The minimal configuration options required by
secretClientBuilder
to buildKeyClient
arevaultUrl
andcredential
.KeyClient keyClient = new KeyClientBuilder() .vaultUrl("https://myvault.azure.net/") .credential(new DefaultAzureCredentialBuilder().build()) .buildClient();
- See Also:
KeyAsyncClient
,KeyClient
-
-
Constructor Summary
Constructors Constructor Description KeyClientBuilder()
The constructor with defaults.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description KeyClientBuilder
addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)
Adds a policy to the set of existing policies that are executed afterKeyAsyncClient
andKeyClient
required policies.KeyAsyncClient
buildAsyncClient()
Creates aKeyAsyncClient
based on options set in the builder.KeyClient
buildClient()
Creates aKeyClient
based on options set in the builder.KeyClientBuilder
clientOptions(com.azure.core.util.ClientOptions clientOptions)
Sets theClientOptions
which enables various options to be set on the client.KeyClientBuilder
configuration(com.azure.core.util.Configuration configuration)
Sets the configuration store that is used during construction of the service client.KeyClientBuilder
credential(com.azure.core.credential.TokenCredential credential)
Sets the credential to use when authenticating HTTP requests.KeyClientBuilder
httpClient(com.azure.core.http.HttpClient client)
Sets the HTTP client to use for sending and receiving requests to and from the service.KeyClientBuilder
httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
Sets the logging configuration for HTTP requests and responses.KeyClientBuilder
pipeline(com.azure.core.http.HttpPipeline pipeline)
Sets the HTTP pipeline to use for the service client.KeyClientBuilder
retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
Sets theRetryPolicy
that is used when each request is sent.KeyClientBuilder
serviceVersion(KeyServiceVersion version)
Sets theKeyServiceVersion
that is used when making API requests.KeyClientBuilder
vaultUrl(String vaultUrl)
Sets the vault endpoint URL to send HTTP requests to.
-
-
-
Method Detail
-
buildClient
public KeyClient buildClient()
Creates aKeyClient
based on options set in the builder. Every timebuildClient()
is called, a new instance ofKeyClient
is created.If
pipeline
is set, then thepipeline
andvaultUrl
are used to create theclient
. All other builder settings are ignored. Ifpipeline
is not set, thenkey vault credential
andkey vault url
are required to build theclient
.- Returns:
- A
KeyClient
with the options set from the builder. - Throws:
IllegalStateException
- Ifcredential(TokenCredential)
orvaultUrl(String)
have not been set.
-
buildAsyncClient
public KeyAsyncClient buildAsyncClient()
Creates aKeyAsyncClient
based on options set in the builder. Every timebuildAsyncClient()
is called, a new instance ofKeyAsyncClient
is created.If
pipeline
is set, then thepipeline
andvaultUrl
are used to create theclient
. All other builder settings are ignored. Ifpipeline
is not set, thenkey vault credential
andvaultUrl(String)
key vault url are required to build theclient
.- Returns:
- A
KeyAsyncClient
with the options set from the builder. - Throws:
IllegalStateException
- Ifcredential(TokenCredential)
orvaultUrl(String)
have not been set.
-
vaultUrl
public KeyClientBuilder vaultUrl(String vaultUrl)
Sets the vault endpoint URL to send HTTP requests to.- Parameters:
vaultUrl
- The vault url is used as destination on Azure to send requests to. If you have a key identifier, create a newKeyVaultKeyIdentifier
to parse it and obtain thevaultUrl
and other information.- Returns:
- The updated
KeyClientBuilder
object. - Throws:
IllegalArgumentException
- IfvaultUrl
cannot be parsed into a valid URL.NullPointerException
- IfvaultUrl
isnull
.
-
credential
public KeyClientBuilder credential(com.azure.core.credential.TokenCredential credential)
Sets the credential to use when authenticating HTTP requests.- Parameters:
credential
- The credential to use for authenticating HTTP requests.- Returns:
- The updated
KeyClientBuilder
object. - Throws:
NullPointerException
- Ifcredential
isnull
.
-
httpLogOptions
public KeyClientBuilder httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
Sets the logging configuration for HTTP requests and responses.If logLevel is not provided, default value of
HttpLogDetailLevel.NONE
is set.- Parameters:
logOptions
- The logging configuration to use when sending and receiving HTTP requests/responses.- Returns:
- The updated
KeyClientBuilder
object.
-
addPolicy
public KeyClientBuilder addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)
Adds a policy to the set of existing policies that are executed afterKeyAsyncClient
andKeyClient
required policies.- Parameters:
policy
- Thepolicy
to be added.- Returns:
- The updated
KeyClientBuilder
object. - Throws:
NullPointerException
- Ifpolicy
isnull
.
-
httpClient
public KeyClientBuilder httpClient(com.azure.core.http.HttpClient client)
Sets the HTTP client to use for sending and receiving requests to and from the service.- Parameters:
client
- The HTTP client to use for requests.- Returns:
- The updated
KeyClientBuilder
object.
-
pipeline
public KeyClientBuilder pipeline(com.azure.core.http.HttpPipeline pipeline)
Sets the HTTP pipeline to use for the service client. Ifpipeline
is set, all other settings are ignored, aside fromvaultUrl
to buildKeyClient
orKeyAsyncClient
.- Parameters:
pipeline
- The HTTP pipeline to use for sending service requests and receiving responses.- Returns:
- The updated
KeyClientBuilder
object.
-
serviceVersion
public KeyClientBuilder serviceVersion(KeyServiceVersion version)
Sets theKeyServiceVersion
that is used when making API requests.If a service version is not provided, the service version that will be used will be the latest known service version based on the version of the client library being used. If no service version is specified, updating to a newer version the client library will have the result of potentially moving to a newer service version.
- Parameters:
version
-KeyServiceVersion
of the service to be used when making requests.- Returns:
- The updated
KeyClientBuilder
object.
-
configuration
public KeyClientBuilder configuration(com.azure.core.util.Configuration configuration)
Sets the configuration store that is used during construction of the service client. The default configuration store is a clone of theglobal configuration store
, useConfiguration.NONE
to bypass using configuration settings during construction.- Parameters:
configuration
- The configuration store used to get configuration details.- Returns:
- The updated
KeyClientBuilder
object.
-
retryPolicy
public KeyClientBuilder retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
Sets theRetryPolicy
that is used when each request is sent. The default retry policy will be used in the pipeline, if not provided.- Parameters:
retryPolicy
- user's retry policy applied to each request.- Returns:
- The updated
KeyClientBuilder
object.
-
clientOptions
public KeyClientBuilder clientOptions(com.azure.core.util.ClientOptions clientOptions)
Sets theClientOptions
which enables various options to be set on the client. For example setting anapplicationId
usingClientOptions.setApplicationId(String)
to configure theUserAgentPolicy
for telemetry/monitoring purposes.More About Azure Core: Telemetry policy
- Parameters:
clientOptions
- theClientOptions
to be set on the client.- Returns:
- The updated
KeyClientBuilder
object.
-
-