Class VaultConfig.Builder

java.lang.Object
codes.grow.packages.vault.VaultConfig.Builder
Enclosing class:
VaultConfig

public static final class VaultConfig.Builder extends Object
Builder of the configuration.

Unset fields take the environment (when fromEnv(EnvReader) is called) or the default.

  • Method Details

    • fromEnv

      public VaultConfig.Builder fromEnv(EnvReader env)
      Fills every field that was not set explicitly from the environment.
      Parameters:
      env - environment reader
      Returns:
      this builder
      Throws:
      ConfigException - when a variable holds an invalid value
    • secretsPath

      public VaultConfig.Builder secretsPath(String secretsPath)
      Sets the base path inside the KV mount under which client.secrets() stores secrets (env GROW_HASHICORP_VAULT_SECRETS_PATH, default "" = the mount root).
      Parameters:
      secretsPath - base path
      Returns:
      this builder
    • valueField

      public VaultConfig.Builder valueField(String valueField)
      Sets the KV data field that holds a client.secrets() value (default value).
      Parameters:
      valueField - field name
      Returns:
      this builder
    • namespace

      public VaultConfig.Builder namespace(String namespace)
      Sets the namespace sent as X-Vault-Namespace (env GROW_HASHICORP_VAULT_NAMESPACE, VAULT_NAMESPACE).
      Parameters:
      namespace - namespace path, e.g. team-a
      Returns:
      this builder
    • kvMount

      public VaultConfig.Builder kvMount(String kvMount)
      Sets the default KV mount (default secret).
      Parameters:
      kvMount - mount path
      Returns:
      this builder
    • kvVersion

      public VaultConfig.Builder kvVersion(int kvVersion)
      Fixes the KV version of every mount and skips auto-detection ( sys/internal/ui/mounts); set it for tokens that cannot read the preflight endpoint.
      Parameters:
      kvVersion - 1 or 2
      Returns:
      this builder
    • url

      public VaultConfig.Builder url(String url)
      Sets the endpoint base URL.
      Parameters:
      url - http or https URL
      Returns:
      this builder
    • token

      public VaultConfig.Builder token(Secret token)
      Sets the API token.
      Parameters:
      token - token
      Returns:
      this builder
    • token

      public VaultConfig.Builder token(String token)
      Sets the API token.
      Parameters:
      token - token
      Returns:
      this builder
    • connectTimeout

      public VaultConfig.Builder connectTimeout(Duration d)
      Sets the connect timeout (default 10 s).
      Parameters:
      d - positive duration
      Returns:
      this builder
    • requestTimeout

      public VaultConfig.Builder requestTimeout(Duration d)
      Sets the per-attempt timeout (default 30 s).
      Parameters:
      d - positive duration
      Returns:
      this builder
    • totalTimeout

      public VaultConfig.Builder totalTimeout(Duration d)
      Sets the total timeout per call including retries (default 120 s).
      Parameters:
      d - positive duration
      Returns:
      this builder
    • retry

      public VaultConfig.Builder retry(RetryPolicy retry)
      Sets the retry policy (default RetryPolicy.defaults()).
      Parameters:
      retry - policy
      Returns:
      this builder
    • tls

      public VaultConfig.Builder tls(TlsOptions tls)
      Sets the TLS options; environment TLS variables are then ignored.
      Parameters:
      tls - options
      Returns:
      this builder
    • proxy

      public VaultConfig.Builder proxy(String proxy)
      Sets an explicit proxy URL; environment proxies (HTTPS_PROXY) are never used.
      Parameters:
      proxy - proxy URL
      Returns:
      this builder
    • header

      public VaultConfig.Builder header(String name, String value)
      Adds a header sent with every request.
      Parameters:
      name - header name
      value - header value
      Returns:
      this builder
    • userAgentSuffix

      public VaultConfig.Builder userAgentSuffix(String suffix)
      Sets the text appended to the User-Agent.
      Parameters:
      suffix - suffix
      Returns:
      this builder
    • hooks

      public VaultConfig.Builder hooks(Hooks hooks)
      Sets request hooks.
      Parameters:
      hooks - hooks
      Returns:
      this builder
    • logger

      public VaultConfig.Builder logger(Logger logger)
      Sets the logger (default silent).
      Parameters:
      logger - logger
      Returns:
      this builder
    • build

      public VaultConfig build()
      Builds and validates the configuration.
      Returns:
      the configuration
      Throws:
      ConfigException - when a rule is violated