Class KeyClientBuilder

java.lang.Object
com.azure.security.keyvault.keys.KeyClientBuilder
All Implemented Interfaces:
ConfigurationTrait<KeyClientBuilder>, HttpTrait<KeyClientBuilder>, TokenCredentialTrait<KeyClientBuilder>

This class provides a fluent builder API to help aid the configuration and instantiation of the 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();
 
See Also:
  • Constructor Details

    • KeyClientBuilder

      public KeyClientBuilder()
      The constructor with defaults.
  • Method Details