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 clientandsecret sync client, by callingbuildAsyncClientandbuildClientrespectively. It constructs an instance of the desired client.The minimal configuration options required by
KeyClientBuilderto buildKeyAsyncClientarevaultUrlandcredential.KeyAsyncClient keyAsyncClient = new KeyClientBuilder() .vaultUrl("https://myvault.azure.net/") .credential(new DefaultAzureCredentialBuilder().build()) .buildAsyncClient();The
log detail level, multiple custompoliciesand customhttp clientcan 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 pipelinewith customHttpPipelinePolicypolicies andvaultUrlcan be specified. It provides finer control over the construction ofKeyAsyncClientandKeyClientHttpPipeline 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
secretClientBuilderto buildKeyClientarevaultUrlandcredential.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 KeyClientBuilderaddPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)Adds a policy to the set of existing policies that are executed afterKeyAsyncClientandKeyClientrequired policies.KeyAsyncClientbuildAsyncClient()Creates aKeyAsyncClientbased on options set in the builder.KeyClientbuildClient()Creates aKeyClientbased on options set in the builder.KeyClientBuilderclientOptions(com.azure.core.util.ClientOptions clientOptions)Sets theClientOptionswhich enables various options to be set on the client.KeyClientBuilderconfiguration(com.azure.core.util.Configuration configuration)Sets the configuration store that is used during construction of the service client.KeyClientBuildercredential(com.azure.core.credential.TokenCredential credential)Sets the credential to use when authenticating HTTP requests.KeyClientBuilderhttpClient(com.azure.core.http.HttpClient client)Sets the HTTP client to use for sending and receiving requests to and from the service.KeyClientBuilderhttpLogOptions(com.azure.core.http.policy.HttpLogOptions logOptions)Sets the logging configuration for HTTP requests and responses.KeyClientBuilderpipeline(com.azure.core.http.HttpPipeline pipeline)Sets the HTTP pipeline to use for the service client.KeyClientBuilderretryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)Sets theRetryPolicythat is used when each request is sent.KeyClientBuilderserviceVersion(KeyServiceVersion version)Sets theKeyServiceVersionthat is used when making API requests.KeyClientBuildervaultUrl(String vaultUrl)Sets the vault endpoint URL to send HTTP requests to.
-
-
-
Method Detail
-
buildClient
public KeyClient buildClient()
Creates aKeyClientbased on options set in the builder. Every timebuildClient()is called, a new instance ofKeyClientis created.If
pipelineis set, then thepipelineandvaultUrlare used to create theclient. All other builder settings are ignored. Ifpipelineis not set, thenkey vault credentialandkey vault urlare required to build theclient.- Returns:
- A
KeyClientwith the options set from the builder. - Throws:
IllegalStateException- Ifcredential(TokenCredential)orvaultUrl(String)have not been set.
-
buildAsyncClient
public KeyAsyncClient buildAsyncClient()
Creates aKeyAsyncClientbased on options set in the builder. Every timebuildAsyncClient()is called, a new instance ofKeyAsyncClientis created.If
pipelineis set, then thepipelineandvaultUrlare used to create theclient. All other builder settings are ignored. Ifpipelineis not set, thenkey vault credentialandvaultUrl(String)key vault url are required to build theclient.- Returns:
- A
KeyAsyncClientwith 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 newKeyVaultKeyIdentifierto parse it and obtain thevaultUrland other information.- Returns:
- The updated
KeyClientBuilderobject. - Throws:
IllegalArgumentException- IfvaultUrlcannot be parsed into a valid URL.NullPointerException- IfvaultUrlisnull.
-
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
KeyClientBuilderobject. - Throws:
NullPointerException- Ifcredentialisnull.
-
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.NONEis set.- Parameters:
logOptions- The logging configuration to use when sending and receiving HTTP requests/responses.- Returns:
- The updated
KeyClientBuilderobject.
-
addPolicy
public KeyClientBuilder addPolicy(com.azure.core.http.policy.HttpPipelinePolicy policy)
Adds a policy to the set of existing policies that are executed afterKeyAsyncClientandKeyClientrequired policies.- Parameters:
policy- Thepolicyto be added.- Returns:
- The updated
KeyClientBuilderobject. - Throws:
NullPointerException- Ifpolicyisnull.
-
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
KeyClientBuilderobject.
-
pipeline
public KeyClientBuilder pipeline(com.azure.core.http.HttpPipeline pipeline)
Sets the HTTP pipeline to use for the service client. Ifpipelineis set, all other settings are ignored, aside fromvaultUrlto buildKeyClientorKeyAsyncClient.- Parameters:
pipeline- The HTTP pipeline to use for sending service requests and receiving responses.- Returns:
- The updated
KeyClientBuilderobject.
-
serviceVersion
public KeyClientBuilder serviceVersion(KeyServiceVersion version)
Sets theKeyServiceVersionthat 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-KeyServiceVersionof the service to be used when making requests.- Returns:
- The updated
KeyClientBuilderobject.
-
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.NONEto bypass using configuration settings during construction.- Parameters:
configuration- The configuration store used to get configuration details.- Returns:
- The updated
KeyClientBuilderobject.
-
retryPolicy
public KeyClientBuilder retryPolicy(com.azure.core.http.policy.RetryPolicy retryPolicy)
Sets theRetryPolicythat 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
KeyClientBuilderobject.
-
clientOptions
public KeyClientBuilder clientOptions(com.azure.core.util.ClientOptions clientOptions)
Sets theClientOptionswhich enables various options to be set on the client. For example setting anapplicationIdusingClientOptions.setApplicationId(String)to configure theUserAgentPolicyfor telemetry/monitoring purposes.More About Azure Core: Telemetry policy
- Parameters:
clientOptions- theClientOptionsto be set on the client.- Returns:
- The updated
KeyClientBuilderobject.
-
-