Skip to content

Commit 5f4ab8c

Browse files
Deserialize string bool and int repository setting values (#4468) (#4474)
This commit updates the repository settings to deserialize nullable bool and int values from strings. Fixes #4467 Co-authored-by: Russ Cam <russ.cam@elastic.co>
1 parent 39cff66 commit 5f4ab8c

File tree

5 files changed

+65
-0
lines changed

5 files changed

+65
-0
lines changed

src/Nest/Modules/SnapshotAndRestore/Repositories/AzureRepository.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Runtime.Serialization;
3+
using Elasticsearch.Net.Utf8Json;
34

45
namespace Nest
56
{
@@ -46,6 +47,7 @@ public interface IAzureRepositorySettings : IRepositorySettings
4647
/// affect index files that are already compressed by default. Defaults to <c>false</c>.
4748
/// </summary>
4849
[DataMember(Name ="compress")]
50+
[JsonFormatter(typeof(NullableStringBooleanFormatter))]
4951
bool? Compress { get; set; }
5052

5153
/// <summary>

src/Nest/Modules/SnapshotAndRestore/Repositories/HdfsRepository.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Runtime.Serialization;
4+
using Elasticsearch.Net.Utf8Json;
45

56
namespace Nest
67
{
@@ -39,12 +40,14 @@ public interface IHdfsRepositorySettings : IRepositorySettings
3940
/// affect index files that are already compressed by default. Defaults to <c>false</c>.
4041
/// </summary>
4142
[DataMember(Name ="compress")]
43+
[JsonFormatter(typeof(NullableStringBooleanFormatter))]
4244
bool? Compress { get; set; }
4345

4446
/// <summary>
4547
/// Throttles the number of streams (per node) preforming snapshot operation. Defaults to 5
4648
/// </summary>
4749
[DataMember(Name ="concurrent_streams")]
50+
[JsonFormatter(typeof(NullableStringIntFormatter))]
4851
int? ConcurrentStreams { get; set; }
4952

5053
/// <summary>
@@ -63,6 +66,7 @@ public interface IHdfsRepositorySettings : IRepositorySettings
6366
/// Whether to load the default Hadoop configuration (default) or not
6467
/// </summary>
6568
[DataMember(Name ="load_defaults")]
69+
[JsonFormatter(typeof(NullableStringBooleanFormatter))]
6670
bool? LoadDefaults { get; set; }
6771

6872
/// <summary>

src/Nest/Modules/SnapshotAndRestore/Repositories/ReadOnlyUrlRepository.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Runtime.Serialization;
3+
using Elasticsearch.Net.Utf8Json;
34

45
namespace Nest
56
{
@@ -28,6 +29,7 @@ public interface IReadOnlyUrlRepositorySettings : IRepositorySettings
2829
/// Throttles the number of streams (per node) preforming snapshot operation. Defaults to 5
2930
/// </summary>
3031
[DataMember(Name ="concurrent_streams")]
32+
[JsonFormatter(typeof(NullableStringIntFormatter))]
3133
int? ConcurrentStreams { get; set; }
3234

3335
/// <summary>

src/Nest/Modules/SnapshotAndRestore/Repositories/S3Repository.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Runtime.Serialization;
3+
using Elasticsearch.Net.Utf8Json;
34

45
namespace Nest
56
{
@@ -77,13 +78,15 @@ public interface IS3RepositorySettings : IRepositorySettings
7778
/// Defaults to false.
7879
/// </summary>
7980
[DataMember(Name ="compress")]
81+
[JsonFormatter(typeof(NullableStringBooleanFormatter))]
8082
bool? Compress { get; set; }
8183

8284
/// <summary>
8385
/// When set to true files are encrypted on server side using AES256 algorithm.
8486
/// Defaults to false.
8587
/// </summary>
8688
[DataMember(Name ="server_side_encryption")]
89+
[JsonFormatter(typeof(NullableStringBooleanFormatter))]
8790
bool? ServerSideEncryption { get; set; }
8891

8992
/// <summary>
@@ -99,6 +102,7 @@ public interface IS3RepositorySettings : IRepositorySettings
99102
// be automatically determined by the AWS Java SDK used internally by Elasticsearch
100103
/// </summary>
101104
[DataMember(Name = "path_style_access")]
105+
[JsonFormatter(typeof(NullableStringBooleanFormatter))]
102106
bool? PathStyleAccess { get; set; }
103107

104108
/// <summary>
@@ -108,6 +112,7 @@ public interface IS3RepositorySettings : IRepositorySettings
108112
/// encoding. Defaults to false.
109113
/// </summary>
110114
[DataMember(Name = "disable_chunked_encoding")]
115+
[JsonFormatter(typeof(NullableStringBooleanFormatter))]
111116
bool? DisableChunkedEncoding { get; set; }
112117
}
113118

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
using System;
2+
using System.Text;
3+
using Elastic.Xunit.XunitPlumbing;
4+
using Elasticsearch.Net;
5+
using FluentAssertions;
6+
using Nest;
7+
8+
namespace Tests.Reproduce
9+
{
10+
public class GithubIssue4467
11+
{
12+
[U]
13+
public void CanDeserializeRepositories()
14+
{
15+
var json = @"{
16+
""test_repository"": {
17+
""type"": ""azure"",
18+
""settings"": {
19+
""container"": ""test-backup-container"",
20+
""client"": ""default"",
21+
""base_path"": ""test-backups"",
22+
""chunk_size"": ""64mb""
23+
}
24+
},
25+
""repo_aligncare_v7"": {
26+
""type"": ""azure"",
27+
""settings"": {
28+
""container"": ""aligncare-backup-container-02292020"",
29+
""base_path"": ""aligncare-backups"",
30+
""chunk_size"": ""64m"",
31+
""compress"": ""true""
32+
}
33+
}
34+
}";
35+
36+
var bytes = Encoding.UTF8.GetBytes(json);
37+
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
38+
var connectionSettings = new ConnectionSettings(pool, new InMemoryConnection(bytes));
39+
var client = new ElasticClient(connectionSettings);
40+
41+
Func<GetRepositoryResponse> responseAction = () => client.Snapshot.GetRepository();
42+
responseAction.Should().NotThrow();
43+
44+
var response = responseAction();
45+
response.Repositories.Should().HaveCount(2);
46+
47+
var azureRepository = response.Azure("repo_aligncare_v7");
48+
azureRepository.Should().NotBeNull();
49+
azureRepository.Settings.Compress.Should().BeTrue();
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)