Class VaultConfig

java.lang.Object
codes.grow.packages.vault.VaultConfig

public final class VaultConfig extends Object
Immutable configuration of a VaultClient (SPEC section 2.2).

Build one with builder() or read it from the environment with fromEnv(). Precedence: explicit builder value > SDK variable (EnvReader.DEFAULT_PREFIX + name) > vendor variables > default. toString() never prints credentials.

Environment variables (fromEnv()): GROW_HASHICORP_VAULT_URL / VAULT_ADDR, GROW_HASHICORP_VAULT_TOKEN / VAULT_TOKEN, GROW_HASHICORP_VAULT_NAMESPACE / VAULT_NAMESPACE, GROW_HASHICORP_VAULT_CA_CERT / VAULT_CACERT, GROW_HASHICORP_VAULT_CLIENT_CERT / VAULT_CLIENT_CERT, GROW_HASHICORP_VAULT_CLIENT_KEY / VAULT_CLIENT_KEY, GROW_HASHICORP_VAULT_INSECURE_SKIP_VERIFY / VAULT_SKIP_VERIFY, GROW_HASHICORP_VAULT_KV_MOUNT, GROW_HASHICORP_VAULT_KV_VERSION (1, 2; 0 = auto-detect), GROW_HASHICORP_VAULT_SECRETS_PATH, plus GROW_HASHICORP_VAULT_PROXY, the timeouts and GROW_HASHICORP_VAULT_MAX_RETRIES.

  • Field Details

    • DEFAULT_URL

      public static final String DEFAULT_URL
      Default endpoint.
      See Also:
    • DEFAULT_KV_MOUNT

      public static final String DEFAULT_KV_MOUNT
      Default KV mount used by client.kv() and client.secrets().
      See Also:
    • DEFAULT_VALUE_FIELD

      public static final String DEFAULT_VALUE_FIELD
      Default KV data field that holds a client.secrets() value.
      See Also:
  • Method Details

    • builder

      public static VaultConfig.Builder builder()
      Starts an empty builder (every field at its default).
      Returns:
      a new builder
    • fromEnv

      public static VaultConfig fromEnv()
      Reads the configuration from the process environment.
      Returns:
      the validated configuration
      Throws:
      ConfigException - when a variable holds an invalid value (the message names the variable, never the value)
    • fromEnv

      public static VaultConfig fromEnv(Map<String,String> env)
      Reads the configuration from an explicit variable map (tests).
      Parameters:
      env - variable map
      Returns:
      the validated configuration
    • validate

      public void validate()
      Checks URL scheme, positive timeouts, retry limits and TLS pairs.
      Throws:
      ConfigException - when a rule is violated
    • toTransportConfig

      public TransportConfig toTransportConfig()
      Translates the common fields into transport settings.
      Returns:
      the transport configuration
    • toTransportConfig

      public TransportConfig toTransportConfig(Supplier<Collection<String>> knownSecrets)
      Translates the common fields into transport settings with a custom source of secret values to redact (the client adds tokens obtained by a login).
      Parameters:
      knownSecrets - supplier of credential values removed from error messages
      Returns:
      the transport configuration
    • url

      public String url()
      Returns the endpoint base URL.
      Returns:
      the URL
    • token

      public Optional<Secret> token()
      Returns the API token.
      Returns:
      the token, or empty
    • connectTimeout

      public Duration connectTimeout()
      Returns the connect timeout.
      Returns:
      the timeout
    • requestTimeout

      public Duration requestTimeout()
      Returns the per-attempt timeout.
      Returns:
      the timeout
    • totalTimeout

      public Duration totalTimeout()
      Returns the total timeout per call including retries.
      Returns:
      the timeout
    • retry

      public RetryPolicy retry()
      Returns the retry policy.
      Returns:
      the policy
    • tls

      public TlsOptions tls()
      Returns the TLS options.
      Returns:
      the options
    • proxy

      public Optional<String> proxy()
      Returns the explicit proxy URL.
      Returns:
      the proxy, or empty
    • headers

      public Map<String,String> headers()
      Returns the extra request headers.
      Returns:
      immutable map
    • userAgentSuffix

      public Optional<String> userAgentSuffix()
      Returns the user agent suffix.
      Returns:
      the suffix, or empty
    • hooks

      public Hooks hooks()
      Returns the hooks.
      Returns:
      the hooks
    • logger

      public Logger logger()
      Returns the logger.
      Returns:
      the logger
    • namespace

      public Optional<String> namespace()
      Returns the namespace sent as X-Vault-Namespace.
      Returns:
      the namespace, or empty
    • kvMount

      public String kvMount()
      Returns the default KV mount (default secret).
      Returns:
      the mount
    • kvVersion

      public OptionalInt kvVersion()
      Returns the fixed KV version that skips auto-detection.
      Returns:
      1 or 2, or empty for auto-detection per mount
    • secretsPath

      public String secretsPath()
      Returns the base path of client.secrets() inside the KV mount.
      Returns:
      the path without surrounding slashes ("" = the mount root)
    • valueField

      public String valueField()
      Returns the KV data field that holds a client.secrets() value.
      Returns:
      the field (default value)
    • toString

      public String toString()
      Overrides:
      toString in class Object