Class HTTPVaultConnectorBuilder
- java.lang.Object
-
- de.stklcode.jvault.connector.builder.HTTPVaultConnectorBuilder
-
- All Implemented Interfaces:
VaultConnectorBuilder
public final class HTTPVaultConnectorBuilder extends Object implements VaultConnectorBuilder
Vault Connector Builder implementation for HTTP Vault connectors.- Since:
- 0.8.0
- Author:
- Stefan Kalscheuer
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_HOST
static int
DEFAULT_NUMBER_OF_RETRIES
static Integer
DEFAULT_PORT
static String
DEFAULT_PREFIX
static boolean
DEFAULT_TLS
static String
DEFAULT_TLS_VERSION
-
Constructor Summary
Constructors Constructor Description HTTPVaultConnectorBuilder()
Default empty constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HTTPVaultConnector
build()
Build command, produces connector after initialization.HTTPVaultConnector
buildAndAuth()
Build connector and authenticate with token set in factory or from environment.HTTPVaultConnectorBuilder
fromEnv()
Build connector based on the VAULT_ADDR} andVAULT_CACERT
(optional) environment variables.HTTPVaultConnectorBuilder
withHost(String host)
Set hostname (default: 127.0.0.1).HTTPVaultConnectorBuilder
withNumberOfRetries(int numberOfRetries)
Define the number of retries to attempt on 5xx errors.HTTPVaultConnectorBuilder
withoutTLS()
Convenience Method for NOT using TLS.HTTPVaultConnectorBuilder
withPort(Integer port)
Set port (default: 8200).HTTPVaultConnectorBuilder
withPrefix(String prefix)
Set API prefix.HTTPVaultConnectorBuilder
withTimeout(int milliseconds)
Define a custom timeout for the HTTP connection.HTTPVaultConnectorBuilder
withTLS()
Convenience Method for TLS usage (enabled by default).HTTPVaultConnectorBuilder
withTLS(boolean useTLS)
Set TLS usage (default: TRUE).HTTPVaultConnectorBuilder
withTLS(boolean useTLS, String version)
Set TLS usage (default: TRUE).HTTPVaultConnectorBuilder
withTLS(String version)
Convenience Method for TLS usage (enabled by default).HTTPVaultConnectorBuilder
withToken(String token)
Set token for automatic authentication, usingbuildAndAuth()
.HTTPVaultConnectorBuilder
withTrustedCA(Path cert)
Add a trusted CA certificate for HTTPS connections.HTTPVaultConnectorBuilder
withTrustedCA(X509Certificate cert)
Add a trusted CA certificate for HTTPS connections.
-
-
-
Field Detail
-
DEFAULT_HOST
public static final String DEFAULT_HOST
- See Also:
- Constant Field Values
-
DEFAULT_PORT
public static final Integer DEFAULT_PORT
-
DEFAULT_TLS
public static final boolean DEFAULT_TLS
- See Also:
- Constant Field Values
-
DEFAULT_TLS_VERSION
public static final String DEFAULT_TLS_VERSION
- See Also:
- Constant Field Values
-
DEFAULT_PREFIX
public static final String DEFAULT_PREFIX
- See Also:
- Constant Field Values
-
DEFAULT_NUMBER_OF_RETRIES
public static final int DEFAULT_NUMBER_OF_RETRIES
- See Also:
- Constant Field Values
-
-
Method Detail
-
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).- 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, usingbuildAndAuth()
.- Parameters:
token
- Vault token- Returns:
- self
- Since:
- 0.6.0
-
fromEnv
public HTTPVaultConnectorBuilder fromEnv() throws VaultConnectorException
Build connector based on the VAULT_ADDR} andVAULT_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()
Description copied from interface:VaultConnectorBuilder
Build command, produces connector after initialization.- Specified by:
build
in interfaceVaultConnectorBuilder
- Returns:
- Vault Connector instance.
-
buildAndAuth
public HTTPVaultConnector buildAndAuth() throws VaultConnectorException
Description copied from interface:VaultConnectorBuilder
Build connector and authenticate with token set in factory or from environment.- Specified by:
buildAndAuth
in interfaceVaultConnectorBuilder
- Returns:
- Authenticated Vault connector instance.
- Throws:
VaultConnectorException
- if authentication failed
-
-