Skip to content

Commit 9e49ae5

Browse files
Juli0qoheger-bosch
authored andcommitted
feat(secrets): Add configurable HTTP timeout for Vault client
Add a `vaultHttpTimeoutSec` config property to set the HTTP timeout for requests to the Vault service, defaulting to 10 seconds. Signed-off-by: Julian Olderdissen <julian.olderdissen@bosch.com>
1 parent d1e50ae commit 9e49ae5

3 files changed

Lines changed: 23 additions & 2 deletions

File tree

secrets/vault/src/main/kotlin/VaultConfiguration.kt

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ package org.eclipse.apoapsis.ortserver.secrets.vault
2121

2222
import com.typesafe.config.Config
2323

24+
import kotlin.time.Duration
25+
import kotlin.time.Duration.Companion.seconds
26+
2427
import org.eclipse.apoapsis.ortserver.config.ConfigManager
2528
import org.eclipse.apoapsis.ortserver.config.Path
2629
import org.eclipse.apoapsis.ortserver.secrets.vault.model.VaultCredentials
30+
import org.eclipse.apoapsis.ortserver.utils.config.getLongOrDefault
2731
import org.eclipse.apoapsis.ortserver.utils.config.getStringOrNull
2832

2933
/**
@@ -54,7 +58,10 @@ data class VaultConfiguration(
5458
* of multiple tenants. In an environment that uses namespaces, it is necessary to pass the target namespace as
5559
* a header when sending requests to the Vault service. If this property is not *null*, such a header is added.
5660
*/
57-
val namespace: String? = null
61+
val namespace: String? = null,
62+
63+
/** The timeout to be applied to all HTTP requests against the Vault service. */
64+
val timeout: Duration = DEFAULT_TIMEOUT
5865
) {
5966
companion object {
6067
/** Name of the configuration property for the URI of the Vault service. */
@@ -75,9 +82,15 @@ data class VaultConfiguration(
7582
/** Name of the configuration property defining the namespace to be passed to the vault service. */
7683
private const val NAMESPACE_PROPERTY = "vaultNamespace"
7784

85+
/** Name of the configuration property defining the timeout for HTTP requests in seconds. */
86+
private const val TIMEOUT_PROPERTY = "vaultHttpTimeoutSec"
87+
7888
/** The default path prefix under which the KV Secrets Engine is available. */
7989
private const val DEFAULT_PREFIX = "secret"
8090

91+
/** The default timeout for HTTP requests to the Vault service. */
92+
val DEFAULT_TIMEOUT = 10.seconds
93+
8194
/** The separator for hierarchical paths. */
8295
private const val PATH_SEPARATOR = "/"
8396

@@ -92,7 +105,8 @@ data class VaultConfiguration(
92105
),
93106
rootPath = getOptionalRootPath(configManager),
94107
prefix = getOptionalPrefix(configManager),
95-
namespace = configManager.getStringOrNull(NAMESPACE_PROPERTY)
108+
namespace = configManager.getStringOrNull(NAMESPACE_PROPERTY),
109+
timeout = configManager.getLongOrDefault(TIMEOUT_PROPERTY, DEFAULT_TIMEOUT.inWholeSeconds).seconds
96110
)
97111

98112
/**

secrets/vault/src/main/kotlin/VaultSecretsProvider.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import io.ktor.client.engine.okhttp.OkHttp
2525
import io.ktor.client.plugins.ClientRequestException
2626
import io.ktor.client.plugins.HttpRequestRetry
2727
import io.ktor.client.plugins.HttpSend
28+
import io.ktor.client.plugins.HttpTimeout
2829
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
2930
import io.ktor.client.plugins.defaultRequest
3031
import io.ktor.client.plugins.expectSuccess
@@ -140,6 +141,11 @@ class VaultSecretsProvider(
140141
)
141142
}
142143

144+
install(HttpTimeout) {
145+
requestTimeoutMillis = config.timeout.inWholeMilliseconds
146+
socketTimeoutMillis = config.timeout.inWholeMilliseconds
147+
}
148+
143149
install(HttpRequestRetry) {
144150
retryOnServerErrors(maxRetries = 3)
145151
exponentialDelay()

secrets/vault/src/main/resources/application.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,5 @@ secretsProvider {
2222
vaultRootPath = ${?VAULT_ROOT_PATH}
2323
vaultPrefix = ${?VAULT_PREFIX}
2424
vaultNamespace = ${?VAULT_NAMESPACE}
25+
vaultHttpTimeoutSec = ${?VAULT_HTTP_TIMEOUT_SEC}
2526
}

0 commit comments

Comments
 (0)