Skip to content

Commit b85ff95

Browse files
committed
RestClient is override-able now
1 parent 909812d commit b85ff95

File tree

1 file changed

+14
-6
lines changed
  • lib/stove-testing-e2e-elasticsearch/src/main/kotlin/com/trendyol/stove/testing/e2e/elasticsearch

1 file changed

+14
-6
lines changed

lib/stove-testing-e2e-elasticsearch/src/main/kotlin/com/trendyol/stove/testing/e2e/elasticsearch/ElasticsearchSystem.kt

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
package com.trendyol.stove.testing.e2e.elasticsearch
44

5+
import arrow.core.Option
56
import arrow.core.getOrElse
7+
import arrow.core.none
68
import arrow.core.orElse
79
import arrow.core.toOption
810
import co.elastic.clients.elasticsearch.ElasticsearchClient
@@ -36,7 +38,6 @@ import kotlin.reflect.KClass
3638
import kotlin.time.Duration.Companion.seconds
3739

3840
data class ElasticClientConfigurer(
39-
val restClientBuilder: RestClientBuilder.() -> Unit = {},
4041
val httpClientBuilder: HttpAsyncClientBuilder.() -> Unit = {
4142
setDefaultRequestConfig(
4243
RequestConfig.custom()
@@ -46,6 +47,7 @@ data class ElasticClientConfigurer(
4647
.build()
4748
)
4849
},
50+
val restClientOverrideFn: Option<(cfg: ElasticSearchExposedConfiguration) -> RestClient> = none(),
4951
)
5052

5153
data class ElasticsearchSystemOptions(
@@ -215,7 +217,16 @@ class ElasticsearchSystem internal constructor(
215217
private fun createEsClient(
216218
exposedConfiguration: ElasticSearchExposedConfiguration,
217219
sslContext: SSLContext,
218-
): ElasticsearchClient {
220+
): ElasticsearchClient =
221+
context.options.clientConfigurer.restClientOverrideFn
222+
.getOrElse { { cfg -> secureRestClient(cfg, sslContext) } }
223+
.let { RestClientTransport(it(exposedConfiguration), JacksonJsonpMapper(jacksonObjectMapper())) }
224+
.let { ElasticsearchClient(it) }
225+
226+
private fun secureRestClient(
227+
exposedConfiguration: ElasticSearchExposedConfiguration,
228+
sslContext: SSLContext,
229+
): RestClient {
219230
val credentialsProvider: CredentialsProvider = BasicCredentialsProvider()
220231
credentialsProvider.setCredentials(
221232
AuthScope.ANY,
@@ -229,10 +240,7 @@ class ElasticsearchSystem internal constructor(
229240
clientBuilder.setDefaultCredentialsProvider(credentialsProvider)
230241
context.options.clientConfigurer.httpClientBuilder(clientBuilder)
231242
clientBuilder
232-
}.also(context.options.clientConfigurer.restClientBuilder)
233-
.build()
234-
.let { RestClientTransport(it, JacksonJsonpMapper(jacksonObjectMapper())) }
235-
.let { ElasticsearchClient(it) }
243+
}.build()
236244
}
237245

238246
companion object {

0 commit comments

Comments
 (0)