From c9c08001b1abfd971b49b167f8a8e241e0c02564 Mon Sep 17 00:00:00 2001 From: Julian Goede Date: Sat, 24 Jun 2023 11:03:45 +0200 Subject: [PATCH] added timout param fixed keystore not getting set bug on fuel client --- .../kirc/client/BlockingContainerImageClientFactory.kt | 8 ++++++-- .../kirc/client/ReactiveContainerImageClientFactory.kt | 8 ++++++-- .../kirc/client/SuspendingContainerImageClientFactory.kt | 9 ++++++++- 3 files changed, 20 insertions(+), 5 deletions(-) diff --git a/kirc-blocking/src/main/kotlin/de/cmdjulian/kirc/client/BlockingContainerImageClientFactory.kt b/kirc-blocking/src/main/kotlin/de/cmdjulian/kirc/client/BlockingContainerImageClientFactory.kt index e9f46e9..221d671 100644 --- a/kirc-blocking/src/main/kotlin/de/cmdjulian/kirc/client/BlockingContainerImageClientFactory.kt +++ b/kirc-blocking/src/main/kotlin/de/cmdjulian/kirc/client/BlockingContainerImageClientFactory.kt @@ -5,6 +5,7 @@ import kotlinx.coroutines.runBlocking import java.net.Proxy import java.net.URI import java.security.KeyStore +import java.time.Duration object BlockingContainerImageClientFactory { @@ -23,8 +24,9 @@ object BlockingContainerImageClientFactory { proxy: Proxy? = null, skipTlsVerify: Boolean = false, keystore: KeyStore? = null, + timeout: Duration = Duration.ofSeconds(5), ): BlockingContainerImageRegistryClient = - SuspendingContainerImageClientFactory.create(url, credentials, proxy, skipTlsVerify, keystore) + SuspendingContainerImageClientFactory.create(url, credentials, proxy, skipTlsVerify, keystore, timeout) .toBlockingClient() @JvmStatic @@ -36,8 +38,10 @@ object BlockingContainerImageClientFactory { insecure: Boolean = false, skipTlsVerify: Boolean = false, keystore: KeyStore? = null, + timeout: Duration = Duration.ofSeconds(5), ): BlockingContainerImageClient = runBlocking { - SuspendingContainerImageClientFactory.create(image, credentials, proxy, insecure, skipTlsVerify, keystore) + SuspendingContainerImageClientFactory + .create(image, credentials, proxy, insecure, skipTlsVerify, keystore, timeout) .toBlockingClient() } } diff --git a/kirc-reactive/src/main/kotlin/de/cmdjulian/kirc/client/ReactiveContainerImageClientFactory.kt b/kirc-reactive/src/main/kotlin/de/cmdjulian/kirc/client/ReactiveContainerImageClientFactory.kt index a13540b..e181c2a 100644 --- a/kirc-reactive/src/main/kotlin/de/cmdjulian/kirc/client/ReactiveContainerImageClientFactory.kt +++ b/kirc-reactive/src/main/kotlin/de/cmdjulian/kirc/client/ReactiveContainerImageClientFactory.kt @@ -5,6 +5,7 @@ import kotlinx.coroutines.runBlocking import java.net.Proxy import java.net.URI import java.security.KeyStore +import java.time.Duration object ReactiveContainerImageClientFactory { @@ -23,8 +24,9 @@ object ReactiveContainerImageClientFactory { proxy: Proxy? = null, skipTlsVerify: Boolean = false, keystore: KeyStore? = null, + timeout: Duration = Duration.ofSeconds(5), ): ReactiveContainerImageRegistryClient = - SuspendingContainerImageClientFactory.create(url, credentials, proxy, skipTlsVerify, keystore) + SuspendingContainerImageClientFactory.create(url, credentials, proxy, skipTlsVerify, keystore, timeout) .toReactiveClient() @JvmStatic @@ -36,8 +38,10 @@ object ReactiveContainerImageClientFactory { insecure: Boolean = false, skipTlsVerify: Boolean = false, keystore: KeyStore? = null, + timeout: Duration = Duration.ofSeconds(5), ): ReactiveContainerImageClient = runBlocking { - SuspendingContainerImageClientFactory.create(image, credentials, proxy, insecure, skipTlsVerify, keystore) + SuspendingContainerImageClientFactory + .create(image, credentials, proxy, insecure, skipTlsVerify, keystore, timeout) .toReactiveClient() } } diff --git a/kirc-suspending/src/main/kotlin/de/cmdjulian/kirc/client/SuspendingContainerImageClientFactory.kt b/kirc-suspending/src/main/kotlin/de/cmdjulian/kirc/client/SuspendingContainerImageClientFactory.kt index a07a2d8..73cf2b6 100644 --- a/kirc-suspending/src/main/kotlin/de/cmdjulian/kirc/client/SuspendingContainerImageClientFactory.kt +++ b/kirc-suspending/src/main/kotlin/de/cmdjulian/kirc/client/SuspendingContainerImageClientFactory.kt @@ -10,6 +10,7 @@ import de.cmdjulian.kirc.utils.NoopHostnameVerifier import java.net.Proxy import java.net.URI import java.security.KeyStore +import java.time.Duration object SuspendingContainerImageClientFactory { @@ -26,12 +27,17 @@ object SuspendingContainerImageClientFactory { proxy: Proxy? = null, skipTlsVerify: Boolean = false, keystore: KeyStore? = null, + timeout: Duration = Duration.ofSeconds(5), ): SuspendingContainerImageRegistryClient { require(keystore == null || !skipTlsVerify) { "can not skip tls verify if a keystore is set" } + require(timeout.toMillis() in Int.MIN_VALUE..Int.MAX_VALUE) { "timeout in ms has to be a valid int" } val fuel = FuelManager().apply { this.basePath = url.toString() this.proxy = proxy + this.keystore = keystore + this.timeoutInMillisecond = timeout.toMillis().toInt() + this.timeoutReadInMillisecond = timeout.toMillis().toInt() if (skipTlsVerify) { hostnameVerifier = NoopHostnameVerifier @@ -50,9 +56,10 @@ object SuspendingContainerImageClientFactory { insecure: Boolean = false, skipTlsVerify: Boolean = false, keystore: KeyStore? = null, + timeout: Duration = Duration.ofSeconds(5), ): SuspendingContainerImageClient { val url = "${if (insecure) "http://" else "https://"}${image.registry}" - val client = create(URI(url), credentials, proxy, skipTlsVerify, keystore) + val client = create(URI(url), credentials, proxy, skipTlsVerify, keystore, timeout) return SuspendingContainerImageClientImpl(client, image) }