From abf190f6c56b3a817909ba1b99e3799c03e9c99e Mon Sep 17 00:00:00 2001 From: Felix Cornelissen Date: Thu, 25 Jul 2024 15:52:23 +0200 Subject: [PATCH 1/2] fix: check for errors on ElasticsearchClient --- src/Kiss.Elastic.Sync/ElasticBulkClient.cs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/Kiss.Elastic.Sync/ElasticBulkClient.cs b/src/Kiss.Elastic.Sync/ElasticBulkClient.cs index 4e0df45..77db634 100644 --- a/src/Kiss.Elastic.Sync/ElasticBulkClient.cs +++ b/src/Kiss.Elastic.Sync/ElasticBulkClient.cs @@ -30,16 +30,14 @@ public ElasticBulkClient(Uri baseUri, string username, string password, int scro { var handler = new HttpClientHandler(); handler.ClientCertificateOptions = ClientCertificateOption.Manual; - handler.ServerCertificateCustomValidationCallback = - (httpRequestMessage, cert, cetChain, policyErrors) => - { - return true; - }; + handler.ServerCertificateCustomValidationCallback = (a, b, c, d) => true; _httpClient = new HttpClient(handler); _httpClient.BaseAddress = baseUri; _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Helpers.EncodeCredential(username, password)); var clientSettings = new ElasticsearchClientSettings(baseUri) - .Authentication(new BasicAuthentication(username, password)); + .Authentication(new BasicAuthentication(username, password)) + .ServerCertificateValidationCallback((a, b, c, d) => true); + _elasticsearchClient = new ElasticsearchClient(clientSettings); _scrollPageSize = scrollPageSize; } @@ -185,6 +183,11 @@ private async Task> GetExistingIds(string indexName, Cancellatio .Scroll(scrollDuration), token); + if (!searchResponse.IsSuccess()) + { + throw new Exception("search failed: " + searchResponse.ToString()); + } + var scrollId = searchResponse.ScrollId; var hits = searchResponse.Hits; @@ -200,7 +203,12 @@ private async Task> GetExistingIds(string indexName, Cancellatio ScrollId = scrollId, Scroll = scrollDuration, }, token); - + + if (!scrollResponse.IsSuccess()) + { + throw new Exception("scroll failed: " + scrollResponse.ToString()); + } + scrollId = scrollResponse.ScrollId; hits = scrollResponse.Hits; } From 883145c16ab6eb8eb39082b2f5ffe283e0cf2611 Mon Sep 17 00:00:00 2001 From: Felix Cornelissen Date: Thu, 25 Jul 2024 16:24:42 +0200 Subject: [PATCH 2/2] chore: comments --- src/Kiss.Elastic.Sync/ElasticBulkClient.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Kiss.Elastic.Sync/ElasticBulkClient.cs b/src/Kiss.Elastic.Sync/ElasticBulkClient.cs index 77db634..af45f24 100644 --- a/src/Kiss.Elastic.Sync/ElasticBulkClient.cs +++ b/src/Kiss.Elastic.Sync/ElasticBulkClient.cs @@ -30,12 +30,14 @@ public ElasticBulkClient(Uri baseUri, string username, string password, int scro { var handler = new HttpClientHandler(); handler.ClientCertificateOptions = ClientCertificateOption.Manual; + // skip checking the certificate because we run Elastic internally, with a local certificate handler.ServerCertificateCustomValidationCallback = (a, b, c, d) => true; _httpClient = new HttpClient(handler); _httpClient.BaseAddress = baseUri; _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", Helpers.EncodeCredential(username, password)); var clientSettings = new ElasticsearchClientSettings(baseUri) .Authentication(new BasicAuthentication(username, password)) + // skip checking the certificate because we run Elastic internally, with a local certificate .ServerCertificateValidationCallback((a, b, c, d) => true); _elasticsearchClient = new ElasticsearchClient(clientSettings);