public final class KeyClientBuilder extends Object
secret async client
and secret sync client
, by calling
buildAsyncClient
and buildClient
respectively. It constructs an instance of the desired client.
The minimal configuration options required by KeyClientBuilder
to build KeyAsyncClient
are
vaultUrl
and credential
.
KeyAsyncClient keyAsyncClient = new KeyClientBuilder() .vaultUrl("https://myvault.azure.net/") .credential(new DefaultAzureCredentialBuilder().build()) .buildAsyncClient();
The log detail level
, multiple custom policies
and custom
http client
can be optionally configured in the KeyClientBuilder
.
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 custom HttpPipelinePolicy
policies and
vaultUrl
can be specified. It provides finer control over the construction of KeyAsyncClient
and KeyClient
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 build KeyClient
are vaultUrl
and credential
.
KeyClient keyClient = new KeyClientBuilder() .vaultUrl("https://myvault.azure.net/") .credential(new DefaultAzureCredentialBuilder().build()) .buildClient();
KeyAsyncClient
,
KeyClient
Constructor and Description |
---|
KeyClientBuilder()
The constructor with defaults.
|
Modifier and Type | Method and Description |
---|---|
KeyClientBuilder |
addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)
Adds a policy to the set of existing policies that are executed after
KeyAsyncClient and KeyClient required policies. |
KeyAsyncClient |
buildAsyncClient()
Creates a
KeyAsyncClient based on options set in the builder. |
KeyClient |
buildClient()
Creates a
KeyClient based on options set in the builder. |
KeyClientBuilder |
clientOptions(com.azure.core.util.ClientOptions clientOptions)
Sets the
ClientOptions 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 the
RetryPolicy that is used when each request is sent. |
KeyClientBuilder |
serviceVersion(KeyServiceVersion version)
Sets the
KeyServiceVersion that is used when making API requests. |
KeyClientBuilder |
vaultUrl(String vaultUrl)
Sets the vault endpoint URL to send HTTP requests to.
|
public KeyClient buildClient()
KeyClient
based on options set in the builder.
Every time buildClient()
is called, a new instance of KeyClient
is created.
If pipeline
is set, then the pipeline
and
vaultUrl
are used to create the client
.
All other builder settings are ignored. If pipeline
is not set, then key vault credential
and key vault url
are required to build the client
.
KeyClient
with the options set from the builder.IllegalStateException
- If KeyClientBuilder.credential(TokenCredential)
or
KeyClientBuilder.vaultUrl(String)
have not been set.public KeyAsyncClient buildAsyncClient()
KeyAsyncClient
based on options set in the builder.
Every time buildAsyncClient()
is called, a new instance of KeyAsyncClient
is created.
If pipeline
is set, then the pipeline
and
vaultUrl
are used to create the client
.
All other builder settings are ignored. If pipeline
is not set, then key vault credential and {@link KeyClientBuilder#vaultUrl(String)}
key vault url are required to build the {@link KeyAsyncClient client}.
KeyAsyncClient
with the options set from the builder.IllegalStateException
- If KeyClientBuilder.credential(TokenCredential)
or
KeyClientBuilder.vaultUrl(String)
have not been set.public KeyClientBuilder vaultUrl(String vaultUrl)
vaultUrl
- The vault url is used as destination on Azure to send requests to. If you have a key identifier,
create a new KeyVaultKeyIdentifier
to parse it and obtain the vaultUrl
and other
information.KeyClientBuilder
object.IllegalArgumentException
- If vaultUrl
cannot be parsed into a valid URL.NullPointerException
- If vaultUrl
is null
.public KeyClientBuilder credential(com.azure.core.credential.TokenCredential credential)
credential
- The credential to use for authenticating HTTP requests.KeyClientBuilder
object.NullPointerException
- If credential
is null
.public KeyClientBuilder httpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)
If logLevel is not provided, default value of HttpLogDetailLevel.NONE
is set.
logOptions
- The logging configuration to use when sending and receiving HTTP requests/responses.KeyClientBuilder
object.public KeyClientBuilder addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)
KeyAsyncClient
and KeyClient
required policies.policy
- The policy
to be added.KeyClientBuilder
object.NullPointerException
- If policy
is null
.public KeyClientBuilder httpClient(com.azure.core.http.HttpClient client)
client
- The HTTP client to use for requests.KeyClientBuilder
object.public KeyClientBuilder pipeline(com.azure.core.http.HttpPipeline pipeline)
pipeline
is set, all other settings are ignored, aside from
vaultUrl
to build KeyClient
or KeyAsyncClient
.pipeline
- The HTTP pipeline to use for sending service requests and receiving responses.KeyClientBuilder
object.public KeyClientBuilder serviceVersion(KeyServiceVersion version)
KeyServiceVersion
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.
version
- KeyServiceVersion
of the service to be used when making requests.KeyClientBuilder
object.public KeyClientBuilder configuration(com.azure.core.util.Configuration configuration)
global
configuration store
, use Configuration.NONE
to bypass using configuration settings during construction.configuration
- The configuration store used to get configuration details.KeyClientBuilder
object.public KeyClientBuilder retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
RetryPolicy
that is used when each request is sent.
The default retry policy will be used in the pipeline, if not provided.retryPolicy
- user's retry policy applied to each request.KeyClientBuilder
object.public KeyClientBuilder clientOptions(com.azure.core.util.ClientOptions clientOptions)
ClientOptions
which enables various options to be set on the client. For example setting an
applicationId
using ClientOptions.setApplicationId(String)
to configure
the UserAgentPolicy
for telemetry/monitoring purposes.
More About Azure Core: Telemetry policy
clientOptions
- the ClientOptions
to be set on the client.KeyClientBuilder
object.Visit the Azure for Java Developers site for more Java documentation, including quick starts, tutorials, and code samples.