diff --git a/CHANGELOG.md b/CHANGELOG.md index a2265a9085..095b1a5d1c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## [Unreleased] +### Fixed +- Fixed the deserialization of S3 snapshot repositories without settings ([#587](https://github.com/opensearch-project/opensearch-net/pull/587)) + ### Dependencies - Bumps `System.Text.Json` from 8.0.1 to 8.0.3 - Bumps `Argu` from 6.2.1 to 6.2.3 diff --git a/src/OpenSearch.Client/Modules/SnapshotAndRestore/Repositories/S3Repository.cs b/src/OpenSearch.Client/Modules/SnapshotAndRestore/Repositories/S3Repository.cs index eb231bc869..4063321c28 100644 --- a/src/OpenSearch.Client/Modules/SnapshotAndRestore/Repositories/S3Repository.cs +++ b/src/OpenSearch.Client/Modules/SnapshotAndRestore/Repositories/S3Repository.cs @@ -42,6 +42,8 @@ public interface IS3Repository : IRepository { } /// public class S3Repository : IS3Repository { + public S3Repository() { } + public S3Repository(IS3RepositorySettings settings) => Settings = settings; public IS3RepositorySettings Settings { get; set; } diff --git a/tests/Tests.Reproduce/GitHubIssue573.cs b/tests/Tests.Reproduce/GitHubIssue573.cs new file mode 100644 index 0000000000..143d86d87b --- /dev/null +++ b/tests/Tests.Reproduce/GitHubIssue573.cs @@ -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; + +/// +/// S3 Snapshot Repository Without Settings Fails to Deserialize: Issue #573 +/// +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) response.Repositories["cs-automated"]).Settings.Should().BeNull(); + + ((S3Repository) response.Repositories["authoring-service-snapshots"]).Settings.Should().NotBeNull(); + } +}