Class SecretClientBuilder

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

This class provides a fluent builder API to help aid the configuration and instantiation of the secret async client and secret client, by calling buildAsyncClient and buildClient respectively. It constructs an instance of the desired client.

The minimal configuration options required by secretClientBuilder to build SecretAsyncClient are vaultUrl and credential.

 SecretAsyncClient secretAsyncClient = new SecretClientBuilder()
     .credential(new DefaultAzureCredentialBuilder().build())
     .vaultUrl("https://myvault.vault.azure.net/")
     .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
     .buildAsyncClient();
 

Samples to construct the sync client

 SecretClient secretClient = new SecretClientBuilder()
     .credential(new DefaultAzureCredentialBuilder().build())
     .vaultUrl("https://myvault.vault.azure.net/")
     .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
     .buildClient();
 

The log detail level, multiple custom policies and custom http client can be optionally configured in the SecretClientBuilder.

 SecretAsyncClient secretAsyncClient = new SecretClientBuilder()
     .httpLogOptions(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))
     .vaultUrl("https://myvault.azure.net/")
     .credential(new DefaultAzureCredentialBuilder().build())
     .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 client

 HttpPipeline pipeline = new HttpPipelineBuilder()
     .policies(new KeyVaultCredentialPolicy(credential), new RetryPolicy())
     .build();
 SecretAsyncClient secretAsyncClient = new SecretClientBuilder()
     .pipeline(pipeline)
     .vaultUrl("https://myvault.azure.net/")
     .buildAsyncClient();
 
See Also: