Class KeyClientBuilder


  • public final class KeyClientBuilder
    extends Object
    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:
    KeyAsyncClient, KeyClient
    • Constructor Detail

      • KeyClientBuilder

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

      • 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 - If credential is null.
      • 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.
      • 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. If pipeline is set, all other settings are ignored, aside from vaultUrl to build KeyClient or KeyAsyncClient.
        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 the 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.

        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 the global configuration store, use Configuration.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 the RetryPolicy 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 the 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

        Parameters:
        clientOptions - the ClientOptions to be set on the client.
        Returns:
        The updated KeyClientBuilder object.