Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow access to MatchConditions for GetConfigurationSetting #21703

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 10 additions & 5 deletions sdk/appconfiguration/Azure.Data.AppConfiguration/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
# Release History

## 1.0.3 (2021-05-14)
## 1.1.0-beta.3 (2021-06-08)

### Changes

- Dependency versions updated.

## 1.1.0-beta.3 (2021-05-11)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We didn't actually ship last time.

#### New Features
- Added a `GetConfigurationSettingAsync` overload that takes an instance of `MatchConditions`.

### Key Bug Fixes
#### Key Bug Fixes

- `FeatureFlagFilter` now allows parameter modification.

## 1.0.3 (2021-05-14)

### Changes

- Dependency versions updated.

## 1.1.0-beta.2 (2021-04-06)

### Breaking changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,11 @@ public ConfigurationClient(System.Uri endpoint, Azure.Core.TokenCredential crede
public override bool Equals(object obj) { throw null; }
public virtual Azure.Response<Azure.Data.AppConfiguration.ConfigurationSetting> GetConfigurationSetting(Azure.Data.AppConfiguration.ConfigurationSetting setting, bool onlyIfChanged = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Data.AppConfiguration.ConfigurationSetting> GetConfigurationSetting(Azure.Data.AppConfiguration.ConfigurationSetting setting, System.DateTimeOffset acceptDateTime, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Data.AppConfiguration.ConfigurationSetting> GetConfigurationSetting(string key, string label, System.DateTimeOffset? acceptDateTime, Azure.MatchConditions conditions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Response<Azure.Data.AppConfiguration.ConfigurationSetting> GetConfigurationSetting(string key, string label = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Data.AppConfiguration.ConfigurationSetting>> GetConfigurationSettingAsync(Azure.Data.AppConfiguration.ConfigurationSetting setting, bool onlyIfChanged = false, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Data.AppConfiguration.ConfigurationSetting>> GetConfigurationSettingAsync(Azure.Data.AppConfiguration.ConfigurationSetting setting, System.DateTimeOffset acceptDateTime, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Data.AppConfiguration.ConfigurationSetting>> GetConfigurationSettingAsync(string key, string label, System.DateTimeOffset? acceptDateTime, Azure.MatchConditions conditions, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual System.Threading.Tasks.Task<Azure.Response<Azure.Data.AppConfiguration.ConfigurationSetting>> GetConfigurationSettingAsync(string key, string label = null, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.Pageable<Azure.Data.AppConfiguration.ConfigurationSetting> GetConfigurationSettings(Azure.Data.AppConfiguration.SettingSelector selector, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
public virtual Azure.AsyncPageable<Azure.Data.AppConfiguration.ConfigurationSetting> GetConfigurationSettingsAsync(Azure.Data.AppConfiguration.SettingSelector selector, System.Threading.CancellationToken cancellationToken = default(System.Threading.CancellationToken)) { throw null; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ private Request CreateDeleteRequest(string key, string label, MatchConditions re
public virtual async Task<Response<ConfigurationSetting>> GetConfigurationSettingAsync(string key, string label = default, CancellationToken cancellationToken = default)
{
Argument.AssertNotNullOrEmpty(key, nameof(key));
return await GetConfigurationSettingAsync(key, label, acceptDateTime: default, requestOptions: default, cancellationToken).ConfigureAwait(false);
return await GetConfigurationSettingAsync(key, label, acceptDateTime: default, conditions: default, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -496,7 +496,7 @@ public virtual async Task<Response<ConfigurationSetting>> GetConfigurationSettin
public virtual Response<ConfigurationSetting> GetConfigurationSetting(string key, string label = default, CancellationToken cancellationToken = default)
{
Argument.AssertNotNullOrEmpty(key, nameof(key));
return GetConfigurationSetting(key, label, acceptDateTime: default, requestOptions: default, cancellationToken);
return GetConfigurationSetting(key, label, acceptDateTime: default, conditions: default, cancellationToken);
}

/// <summary>
Expand Down Expand Up @@ -543,7 +543,7 @@ public virtual Response<ConfigurationSetting> GetConfigurationSetting(Configurat
public virtual async Task<Response<ConfigurationSetting>> GetConfigurationSettingAsync(ConfigurationSetting setting, DateTimeOffset acceptDateTime, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(setting, nameof(setting));
return await GetConfigurationSettingAsync(setting.Key, setting.Label, acceptDateTime, requestOptions: default, cancellationToken).ConfigureAwait(false);
return await GetConfigurationSettingAsync(setting.Key, setting.Label, acceptDateTime, conditions: default, cancellationToken).ConfigureAwait(false);
}

/// <summary>
Expand All @@ -556,18 +556,27 @@ public virtual async Task<Response<ConfigurationSetting>> GetConfigurationSettin
public virtual Response<ConfigurationSetting> GetConfigurationSetting(ConfigurationSetting setting, DateTimeOffset acceptDateTime, CancellationToken cancellationToken = default)
{
Argument.AssertNotNull(setting, nameof(setting));
return GetConfigurationSetting(setting.Key, setting.Label, acceptDateTime, requestOptions: default, cancellationToken);
return GetConfigurationSetting(setting.Key, setting.Label, acceptDateTime, conditions: default, cancellationToken);
}

private async Task<Response<ConfigurationSetting>> GetConfigurationSettingAsync(string key, string label, DateTimeOffset acceptDateTime, MatchConditions requestOptions, CancellationToken cancellationToken = default)
/// <summary>
/// Retrieve an existing <see cref="ConfigurationSetting"/>, uniquely identified by key and label, from the configuration store.
/// </summary>
/// <param name="key">The primary identifier of the configuration setting to retrieve.</param>
/// <param name="label">A label used to group this configuration setting with others.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <param name="acceptDateTime">The setting will be retrieved exactly as it existed at the provided time.</param>
/// <param name="conditions">The match conditions to apply to request.</param>
/// <returns>A response containing the retrieved <see cref="ConfigurationSetting"/>.</returns>
public virtual async Task<Response<ConfigurationSetting>> GetConfigurationSettingAsync(string key, string label, DateTimeOffset? acceptDateTime, MatchConditions conditions, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ConfigurationClient)}.{nameof(GetConfigurationSetting)}");
scope.AddAttribute(nameof(key), key);
scope.Start();

try
{
using Request request = CreateGetRequest(key, label, acceptDateTime, requestOptions);
using Request request = CreateGetRequest(key, label, acceptDateTime, conditions);
Response response = await _pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false);

return response.Status switch
Expand All @@ -584,15 +593,24 @@ private async Task<Response<ConfigurationSetting>> GetConfigurationSettingAsync(
}
}

private Response<ConfigurationSetting> GetConfigurationSetting(string key, string label, DateTimeOffset acceptDateTime, MatchConditions requestOptions, CancellationToken cancellationToken = default)
/// <summary>
/// Retrieve an existing <see cref="ConfigurationSetting"/>, uniquely identified by key and label, from the configuration store.
/// </summary>
/// <param name="key">The primary identifier of the configuration setting to retrieve.</param>
/// <param name="label">A label used to group this configuration setting with others.</param>
/// <param name="cancellationToken">A <see cref="CancellationToken"/> controlling the request lifetime.</param>
/// <param name="acceptDateTime">The setting will be retrieved exactly as it existed at the provided time.</param>
/// <param name="conditions">The match conditions to apply to request.</param>
/// <returns>A response containing the retrieved <see cref="ConfigurationSetting"/>.</returns>
public virtual Response<ConfigurationSetting> GetConfigurationSetting(string key, string label, DateTimeOffset? acceptDateTime, MatchConditions conditions, CancellationToken cancellationToken = default)
{
using DiagnosticScope scope = _clientDiagnostics.CreateScope($"{nameof(ConfigurationClient)}.{nameof(GetConfigurationSetting)}");
scope.AddAttribute(nameof(key), key);
scope.Start();

try
{
using Request request = CreateGetRequest(key, label, acceptDateTime, requestOptions);
using Request request = CreateGetRequest(key, label, acceptDateTime, conditions);
Response response = _pipeline.SendRequest(request, cancellationToken);

return response.Status switch
Expand Down Expand Up @@ -678,7 +696,7 @@ public virtual Pageable<ConfigurationSetting> GetRevisions(SettingSelector selec
return PageResponseEnumerator.CreateEnumerable(nextLink => GetRevisionsPage(selector, nextLink, cancellationToken));
}

private Request CreateGetRequest(string key, string label, DateTimeOffset acceptDateTime, MatchConditions requestOptions)
private Request CreateGetRequest(string key, string label, DateTimeOffset? acceptDateTime, MatchConditions requestOptions)
{
Argument.AssertNotNullOrEmpty(key, nameof(key));

Expand All @@ -687,9 +705,9 @@ private Request CreateGetRequest(string key, string label, DateTimeOffset accept
BuildUriForKvRoute(request.Uri, key, label);
request.Headers.Add(s_mediaTypeKeyValueApplicationHeader);

if (acceptDateTime != default)
if (acceptDateTime.HasValue)
{
var dateTime = acceptDateTime.UtcDateTime.ToString(AcceptDateTimeFormat, CultureInfo.InvariantCulture);
var dateTime = acceptDateTime.Value.UtcDateTime.ToString(AcceptDateTimeFormat, CultureInfo.InvariantCulture);
request.Headers.SetValue(AcceptDatetimeHeader, dateTime);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,103 @@ public async Task GetSettingWithLabel()
}
}

[RecordedTest]
public async Task GetSettingWithIfMatch_Matches()
{
ConfigurationClient service = GetClient();
ConfigurationSetting testSetting = CreateSetting();

try
{
testSetting = await service.SetConfigurationSettingAsync(testSetting);

// Test
ConfigurationSetting responseSetting = await service.GetConfigurationSettingAsync(testSetting.Key, testSetting.Label, acceptDateTime: null, new MatchConditions()
{
IfMatch = testSetting.ETag
});

Assert.True(ConfigurationSettingEqualityComparer.Instance.Equals(testSetting, responseSetting));
}
finally
{
AssertStatus200(await service.DeleteConfigurationSettingAsync(testSetting.Key, testSetting.Label));
}
}

[RecordedTest]
public async Task GetSettingWithIfMatch_NoMatch()
{
ConfigurationClient service = GetClient();
ConfigurationSetting testSetting = CreateSetting();

try
{
testSetting = await service.SetConfigurationSettingAsync(testSetting);

// Test
RequestFailedException exception = Assert.ThrowsAsync<RequestFailedException>(async () =>
await service.GetConfigurationSettingAsync(testSetting.Key, testSetting.Label, acceptDateTime: null, new MatchConditions()
{
IfMatch = new ETag("this won't match")
}));

Assert.AreEqual(412, exception.Status);
}
finally
{
AssertStatus200(await service.DeleteConfigurationSettingAsync(testSetting.Key, testSetting.Label));
}
}

[RecordedTest]
public async Task GetSettingWithIfNoneMatch_Matches()
{
ConfigurationClient service = GetClient();
ConfigurationSetting testSetting = CreateSetting();

try
{
testSetting = await service.SetConfigurationSettingAsync(testSetting);

// Test
Response<ConfigurationSetting> responseSetting = await service.GetConfigurationSettingAsync(testSetting.Key, testSetting.Label, acceptDateTime: null, new MatchConditions()
{
IfNoneMatch = testSetting.ETag
});

Assert.Catch<Exception>(() => _ = responseSetting.Value);
}
finally
{
AssertStatus200(await service.DeleteConfigurationSettingAsync(testSetting.Key, testSetting.Label));
}
}

[RecordedTest]
public async Task GetSettingWithIfNoneMatch_NoMatch()
{
ConfigurationClient service = GetClient();
ConfigurationSetting testSetting = CreateSetting();

try
{
testSetting = await service.SetConfigurationSettingAsync(testSetting);

// Test
ConfigurationSetting responseSetting = await service.GetConfigurationSettingAsync(testSetting.Key, testSetting.Label, acceptDateTime: null, new MatchConditions()
{
IfNoneMatch = new ETag("this won't match")
});

Assert.True(ConfigurationSettingEqualityComparer.Instance.Equals(testSetting, responseSetting));
}
finally
{
AssertStatus200(await service.DeleteConfigurationSettingAsync(testSetting.Key, testSetting.Label));
}
}

[RecordedTest]
public async Task GetWithAcceptDateTime()
{
Expand Down
Loading