From ebaaddd140643eec96dc912e8a368f4fc401a396 Mon Sep 17 00:00:00 2001 From: Russ Cam Date: Wed, 4 Mar 2020 10:34:09 +1000 Subject: [PATCH] Deserialize string bool and int repository setting values (#4468) This commit updates the repository settings to deserialize nullable bool and int values from strings. Fixes #4467 --- .../Repositories/AzureRepository.cs | 2 + .../Repositories/HdfsRepository.cs | 4 ++ .../Repositories/ReadOnlyUrlRepository.cs | 2 + .../Repositories/S3Repository.cs | 5 ++ tests/Tests.Reproduce/GithubIssue4467.cs | 52 +++++++++++++++++++ 5 files changed, 65 insertions(+) create mode 100644 tests/Tests.Reproduce/GithubIssue4467.cs diff --git a/src/Nest/Modules/SnapshotAndRestore/Repositories/AzureRepository.cs b/src/Nest/Modules/SnapshotAndRestore/Repositories/AzureRepository.cs index edb52017c3f..06c4d2eae76 100644 --- a/src/Nest/Modules/SnapshotAndRestore/Repositories/AzureRepository.cs +++ b/src/Nest/Modules/SnapshotAndRestore/Repositories/AzureRepository.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.Serialization; +using Elasticsearch.Net.Utf8Json; namespace Nest { @@ -46,6 +47,7 @@ public interface IAzureRepositorySettings : IRepositorySettings /// affect index files that are already compressed by default. Defaults to false. /// [DataMember(Name ="compress")] + [JsonFormatter(typeof(NullableStringBooleanFormatter))] bool? Compress { get; set; } /// diff --git a/src/Nest/Modules/SnapshotAndRestore/Repositories/HdfsRepository.cs b/src/Nest/Modules/SnapshotAndRestore/Repositories/HdfsRepository.cs index 6bef32e40d6..ce4a478f4f2 100644 --- a/src/Nest/Modules/SnapshotAndRestore/Repositories/HdfsRepository.cs +++ b/src/Nest/Modules/SnapshotAndRestore/Repositories/HdfsRepository.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Runtime.Serialization; +using Elasticsearch.Net.Utf8Json; namespace Nest { @@ -39,12 +40,14 @@ public interface IHdfsRepositorySettings : IRepositorySettings /// affect index files that are already compressed by default. Defaults to false. /// [DataMember(Name ="compress")] + [JsonFormatter(typeof(NullableStringBooleanFormatter))] bool? Compress { get; set; } /// /// Throttles the number of streams (per node) preforming snapshot operation. Defaults to 5 /// [DataMember(Name ="concurrent_streams")] + [JsonFormatter(typeof(NullableStringIntFormatter))] int? ConcurrentStreams { get; set; } /// @@ -63,6 +66,7 @@ public interface IHdfsRepositorySettings : IRepositorySettings /// Whether to load the default Hadoop configuration (default) or not /// [DataMember(Name ="load_defaults")] + [JsonFormatter(typeof(NullableStringBooleanFormatter))] bool? LoadDefaults { get; set; } /// diff --git a/src/Nest/Modules/SnapshotAndRestore/Repositories/ReadOnlyUrlRepository.cs b/src/Nest/Modules/SnapshotAndRestore/Repositories/ReadOnlyUrlRepository.cs index 0667ecc9e9f..217dbc02e2b 100644 --- a/src/Nest/Modules/SnapshotAndRestore/Repositories/ReadOnlyUrlRepository.cs +++ b/src/Nest/Modules/SnapshotAndRestore/Repositories/ReadOnlyUrlRepository.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.Serialization; +using Elasticsearch.Net.Utf8Json; namespace Nest { @@ -28,6 +29,7 @@ public interface IReadOnlyUrlRepositorySettings : IRepositorySettings /// Throttles the number of streams (per node) preforming snapshot operation. Defaults to 5 /// [DataMember(Name ="concurrent_streams")] + [JsonFormatter(typeof(NullableStringIntFormatter))] int? ConcurrentStreams { get; set; } /// diff --git a/src/Nest/Modules/SnapshotAndRestore/Repositories/S3Repository.cs b/src/Nest/Modules/SnapshotAndRestore/Repositories/S3Repository.cs index 16f4be2424f..0305ee73c41 100644 --- a/src/Nest/Modules/SnapshotAndRestore/Repositories/S3Repository.cs +++ b/src/Nest/Modules/SnapshotAndRestore/Repositories/S3Repository.cs @@ -1,5 +1,6 @@ using System; using System.Runtime.Serialization; +using Elasticsearch.Net.Utf8Json; namespace Nest { @@ -77,6 +78,7 @@ public interface IS3RepositorySettings : IRepositorySettings /// Defaults to false. /// [DataMember(Name ="compress")] + [JsonFormatter(typeof(NullableStringBooleanFormatter))] bool? Compress { get; set; } /// @@ -84,6 +86,7 @@ public interface IS3RepositorySettings : IRepositorySettings /// Defaults to false. /// [DataMember(Name ="server_side_encryption")] + [JsonFormatter(typeof(NullableStringBooleanFormatter))] bool? ServerSideEncryption { get; set; } /// @@ -99,6 +102,7 @@ public interface IS3RepositorySettings : IRepositorySettings // be automatically determined by the AWS Java SDK used internally by Elasticsearch /// [DataMember(Name = "path_style_access")] + [JsonFormatter(typeof(NullableStringBooleanFormatter))] bool? PathStyleAccess { get; set; } /// @@ -108,6 +112,7 @@ public interface IS3RepositorySettings : IRepositorySettings /// encoding. Defaults to false. /// [DataMember(Name = "disable_chunked_encoding")] + [JsonFormatter(typeof(NullableStringBooleanFormatter))] bool? DisableChunkedEncoding { get; set; } } diff --git a/tests/Tests.Reproduce/GithubIssue4467.cs b/tests/Tests.Reproduce/GithubIssue4467.cs new file mode 100644 index 00000000000..4bc02ad5792 --- /dev/null +++ b/tests/Tests.Reproduce/GithubIssue4467.cs @@ -0,0 +1,52 @@ +using System; +using System.Text; +using Elastic.Xunit.XunitPlumbing; +using Elasticsearch.Net; +using FluentAssertions; +using Nest; + +namespace Tests.Reproduce +{ + public class GithubIssue4467 + { + [U] + public void CanDeserializeRepositories() + { + var json = @"{ + ""test_repository"": { + ""type"": ""azure"", + ""settings"": { + ""container"": ""test-backup-container"", + ""client"": ""default"", + ""base_path"": ""test-backups"", + ""chunk_size"": ""64mb"" + } + }, + ""repo_aligncare_v7"": { + ""type"": ""azure"", + ""settings"": { + ""container"": ""aligncare-backup-container-02292020"", + ""base_path"": ""aligncare-backups"", + ""chunk_size"": ""64m"", + ""compress"": ""true"" + } + } + }"; + + var bytes = Encoding.UTF8.GetBytes(json); + var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200")); + var connectionSettings = new ConnectionSettings(pool, new InMemoryConnection(bytes)); + var client = new ElasticClient(connectionSettings); + + Func responseAction = () => client.Snapshot.GetRepository(); + responseAction.Should().NotThrow(); + + var response = responseAction(); + response.Repositories.Should().HaveCount(2); + + var azureRepository = response.Azure("repo_aligncare_v7"); + azureRepository.Should().NotBeNull(); + azureRepository.Settings.Compress.Should().BeTrue(); + } + } +}