Skip to content

Commit

Permalink
Fix deserialization of S3 snapshot repository without settings (#587)
Browse files Browse the repository at this point in the history
* Add failing reproduction test case

Signed-off-by: Thomas Farr <[email protected]>

* Add parameterless constructor to S3Repository

Signed-off-by: Thomas Farr <[email protected]>

---------

Signed-off-by: Thomas Farr <[email protected]>
  • Loading branch information
Xtansia authored Apr 10, 2024
1 parent 0e106ca commit df942ab
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 1 deletion.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Removed the `Features` API which is not supported by OpenSearch from the low-level client ([#331](https://github.com/opensearch-project/opensearch-net/pull/331))
- Removed the deprecated low-level `IndexTemplateV2` APIs in favour of the `ComposableIndexTemplate` APIs ([#437](https://github.com/opensearch-project/opensearch-net/pull/437))

### Fixed
- Fixed the deserialization of S3 snapshot repositories without settings ([#587](https://github.com/opensearch-project/opensearch-net/pull/587))

### Dependencies
- Bumps `System.Diagnostics.DiagnosticSource` from 6.0.1 to 8.0.0
- Bumps `System.Text.Json` from 8.0.1 to 8.0.3
Expand Down Expand Up @@ -162,4 +165,4 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
[1.6.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.5.0...v1.6.0
[1.5.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.4.0...v1.5.0
[1.4.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.3.0...v1.4.0
[1.3.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.2.0...v1.3.0
[1.3.0]: https://github.com/opensearch-project/opensearch-net/compare/v1.2.0...v1.3.0
2 changes: 2 additions & 0 deletions src/OpenSearch.Client/Snapshot/Repositories/S3Repository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public interface IS3Repository : IRepository<IS3RepositorySettings> { }
/// <inheritdoc />
public class S3Repository : IS3Repository
{
public S3Repository() { }

public S3Repository(IS3RepositorySettings settings) => Settings = settings;

public IS3RepositorySettings Settings { get; set; }
Expand Down
58 changes: 58 additions & 0 deletions tests/Tests.Reproduce/GitHubIssue573.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/* SPDX-License-Identifier: Apache-2.0
*
* The OpenSearch Contributors require contributions made to
* this file be licensed under the Apache-2.0 license or a
* compatible open source license.
*/

using System;
using System.Text;
using FluentAssertions;
using OpenSearch.Client;
using OpenSearch.Net;
using OpenSearch.OpenSearch.Xunit.XunitPlumbing;
using Tests.Core.Extensions;

namespace Tests.Reproduce;

/// <summary>
/// S3 Snapshot Repository Without Settings Fails to Deserialize: <a href="https://github.com/opensearch-project/opensearch-net/issues/573">Issue #573</a>
/// </summary>
public class GitHubIssue573
{
[U] public void DeserializingS3SnapshotRepositoryWithoutSettingsShouldSucceed()
{
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));

const string json = @"{
""cs-automated"": {
""type"": ""s3""
},
""authoring-service-snapshots"": {
""type"": ""s3"",
""settings"": {
""bucket"": ""some-bucket"",
""region"": ""us-west-2"",
""role_arn"": ""arn:aws:iam::123456789:role/SomeRole""
}
}
}";

var connection = new InMemoryConnection(Encoding.UTF8.GetBytes(json), 200);
var settings = new ConnectionSettings(pool, connection);
var client = new OpenSearchClient(settings);

var response = client.Snapshot.GetRepository();
response.ShouldBeValid();
response.Repositories
.Should()
.NotBeNull()
.And.HaveCount(2)
.And.ContainKeys("cs-automated", "authoring-service-snapshots")
.And.AllSatisfy(p => p.Value.Should().BeOfType<S3Repository>());

((S3Repository) response.Repositories["cs-automated"]).Settings.Should().BeNull();

((S3Repository) response.Repositories["authoring-service-snapshots"]).Settings.Should().NotBeNull();
}
}

0 comments on commit df942ab

Please sign in to comment.