Class HTTPVaultConnectorBuilder

java.lang.Object
de.stklcode.jvault.connector.HTTPVaultConnectorBuilder

public final class HTTPVaultConnectorBuilder extends Object
Vault Connector Builder implementation for HTTP Vault connectors.
Since:
0.8.0, 0.9.5 Package de.stklcode.jvault.connector
Author:
Stefan Kalscheuer
  • Field Details

  • Method Details

    • withBaseURL

      public HTTPVaultConnectorBuilder withBaseURL(String baseURL) throws URISyntaxException
      Set base URL, e.g. "protocol://host:port/prefix".
      Parameters:
      baseURL - Base URL
      Returns:
      self
      Throws:
      URISyntaxException - Invalid URI syntax.
      Since:
      1.0
    • withBaseURL

      public HTTPVaultConnectorBuilder withBaseURL(URI baseURL)
      Set base URL, e.g. "protocol://host:port/prefix".
      Parameters:
      baseURL - Base URL
      Returns:
      self
      Since:
      1.0
    • withHost

      public HTTPVaultConnectorBuilder withHost(String host)
      Set hostname (default: 127.0.0.1).
      Parameters:
      host - Hostname or IP address
      Returns:
      self
    • withPort

      public HTTPVaultConnectorBuilder withPort(Integer port)
      Set port (default: 8200). A value of null or -1 indicates that no port is specified, i.e. the protocol default is used. Otherwise, a valid port number between 1 and 65535 is expected.
      Parameters:
      port - Vault TCP port
      Returns:
      self
    • withTLS

      public HTTPVaultConnectorBuilder withTLS(boolean useTLS)
      Set TLS usage (default: TRUE).
      Parameters:
      useTLS - use TLS or not
      Returns:
      self
    • withTLS

      public HTTPVaultConnectorBuilder withTLS(boolean useTLS, String version)
      Set TLS usage (default: TRUE).
      Parameters:
      useTLS - Use TLS or not.
      version - Supported TLS version (TLSv1.2, TLSv1.1, TLSv1.0, TLS).
      Returns:
      self
      Since:
      0.8 Added version parameter (#22).
    • withTLS

      public HTTPVaultConnectorBuilder withTLS(String version)
      Convenience Method for TLS usage (enabled by default).
      Parameters:
      version - Supported TLS version (TLSv1.2, TLSv1.1, TLSv1.0, TLS).
      Returns:
      self
      Since:
      0.8 Added version parameter (#22).
    • withTLS

      public HTTPVaultConnectorBuilder withTLS()
      Convenience Method for TLS usage (enabled by default).
      Returns:
      self
    • withoutTLS

      public HTTPVaultConnectorBuilder withoutTLS()
      Convenience Method for NOT using TLS.
      Returns:
      self
    • withPrefix

      public HTTPVaultConnectorBuilder withPrefix(String prefix)
      Set API prefix. Default is "/v1/" and changes should not be necessary for current state of development.
      Parameters:
      prefix - Vault API prefix (default: "/v1/")
      Returns:
      self
    • withTrustedCA

      public HTTPVaultConnectorBuilder withTrustedCA(Path cert) throws VaultConnectorException
      Add a trusted CA certificate for HTTPS connections.
      Parameters:
      cert - path to certificate file
      Returns:
      self
      Throws:
      VaultConnectorException - on error
      Since:
      0.4.0
    • withTrustedCA

      public HTTPVaultConnectorBuilder withTrustedCA(X509Certificate cert)
      Add a trusted CA certificate for HTTPS connections.
      Parameters:
      cert - path to certificate file
      Returns:
      self
      Since:
      0.8.0
    • withToken

      public HTTPVaultConnectorBuilder withToken(String token)
      Set token for automatic authentication, using buildAndAuth().
      Parameters:
      token - Vault token
      Returns:
      self
      Since:
      0.6.0
    • fromEnv

      Build connector based on the VAULT_ADDR and VAULT_CACERT (optional) environment variables.
      Returns:
      self
      Throws:
      VaultConnectorException - if Vault address from environment variables is malformed
      Since:
      0.6.0
    • withNumberOfRetries

      public HTTPVaultConnectorBuilder withNumberOfRetries(int numberOfRetries)
      Define the number of retries to attempt on 5xx errors.
      Parameters:
      numberOfRetries - The number of retries to attempt on 5xx errors (default: 0)
      Returns:
      self
      Since:
      0.6.0
    • withTimeout

      public HTTPVaultConnectorBuilder withTimeout(int milliseconds)
      Define a custom timeout for the HTTP connection.
      Parameters:
      milliseconds - Timeout value in milliseconds.
      Returns:
      self
      Since:
      0.6.0
    • build

      public HTTPVaultConnector build()
      Build command, produces connector after initialization.
      Returns:
      Vault Connector instance.
    • buildAndAuth

      public HTTPVaultConnector buildAndAuth() throws VaultConnectorException
      Build connector and authenticate with token set in factory or from environment.
      Returns:
      Authenticated Vault connector instance.
      Throws:
      VaultConnectorException - if authentication failed
      Since:
      0.6.0