Skip to content

Commit 6b12553

Browse files
committed
added comments and returning SnapshotReference type from Parse()
1 parent f8033d9 commit 6b12553

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/AzureAppConfigurationProvider.cs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -884,9 +884,9 @@ await CallWithRequestTracing(async () =>
884884
_requestTracingOptions.UpdateSnapshotReferenceTracing(setting.ContentType);
885885
}
886886

887-
var snapshotReference = new SnapshotReference { SnapshotName = SnapshotReferenceParser.Parse(setting) };
887+
var snapshotReference = SnapshotReferenceParser.Parse(setting);
888888

889-
Dictionary<string, ConfigurationSetting> resolvedSettings = await Resolve(snapshotReference, client, cancellationToken).ConfigureAwait(false);
889+
Dictionary<string, ConfigurationSetting> resolvedSettings = await LoadSnapshotData(snapshotReference.SnapshotName, client, cancellationToken).ConfigureAwait(false);
890890

891891
foreach (KeyValuePair<string, ConfigurationSetting> resolvedSetting in resolvedSettings)
892892
{
@@ -926,7 +926,7 @@ await CallWithRequestTracing(async () =>
926926

927927
var snapshotReference = new SnapshotReference { SnapshotName = loadOption.SnapshotName };
928928

929-
Dictionary<string, ConfigurationSetting> resolvedSettings = await Resolve(snapshotReference, client, cancellationToken).ConfigureAwait(false);
929+
Dictionary<string, ConfigurationSetting> resolvedSettings = await LoadSnapshotData(snapshotReference.SnapshotName, client, cancellationToken).ConfigureAwait(false);
930930

931931
foreach (KeyValuePair<string, ConfigurationSetting> resolvedSetting in resolvedSettings)
932932
{
@@ -938,16 +938,16 @@ await CallWithRequestTracing(async () =>
938938
return data;
939939
}
940940

941-
private async Task<Dictionary<string, ConfigurationSetting>> Resolve(SnapshotReference snapshotReference, ConfigurationClient client, CancellationToken cancellationToken)
941+
private async Task<Dictionary<string, ConfigurationSetting>> LoadSnapshotData(string snapshotName, ConfigurationClient client, CancellationToken cancellationToken)
942942
{
943943
var resolvedSettings = new Dictionary<string, ConfigurationSetting>();
944944

945-
if (snapshotReference.SnapshotName == null)
945+
if (snapshotName == null)
946946
{
947947
throw new InvalidOperationException(ErrorMessages.SnapshotReferenceNull);
948948
}
949949

950-
if (snapshotReference.SnapshotName == string.Empty)
950+
if (snapshotName == string.Empty)
951951
{
952952
return resolvedSettings;
953953
}
@@ -956,7 +956,7 @@ private async Task<Dictionary<string, ConfigurationSetting>> Resolve(SnapshotRef
956956

957957
try
958958
{
959-
await CallWithRequestTracing(async () => snapshot = await client.GetSnapshotAsync(snapshotReference.SnapshotName, cancellationToken: cancellationToken).ConfigureAwait(false)).ConfigureAwait(false);
959+
await CallWithRequestTracing(async () => snapshot = await client.GetSnapshotAsync(snapshotName, cancellationToken: cancellationToken).ConfigureAwait(false)).ConfigureAwait(false);
960960
}
961961
catch (RequestFailedException rfe) when (rfe.Status == (int)HttpStatusCode.NotFound)
962962
{
@@ -970,7 +970,7 @@ private async Task<Dictionary<string, ConfigurationSetting>> Resolve(SnapshotRef
970970
}
971971

972972
IAsyncEnumerable<ConfigurationSetting> settingsEnumerable = client.GetConfigurationSettingsForSnapshotAsync(
973-
snapshotReference.SnapshotName,
973+
snapshotName,
974974
cancellationToken);
975975

976976
await CallWithRequestTracing(async () =>
@@ -1028,9 +1028,9 @@ private async Task<Dictionary<KeyValueIdentifier, ConfigurationSetting>> LoadKey
10281028
_requestTracingOptions.UpdateSnapshotReferenceTracing(watchedKv.ContentType);
10291029
}
10301030

1031-
var snapshotReference = new SnapshotReference { SnapshotName = SnapshotReferenceParser.Parse(watchedKv) };
1031+
var snapshotReference = SnapshotReferenceParser.Parse(watchedKv);
10321032

1033-
Dictionary<string, ConfigurationSetting> resolvedSettings = await Resolve(snapshotReference, client, cancellationToken).ConfigureAwait(false);
1033+
Dictionary<string, ConfigurationSetting> resolvedSettings = await LoadSnapshotData(snapshotReference.SnapshotName, client, cancellationToken).ConfigureAwait(false);
10341034

10351035
foreach (KeyValuePair<string, ConfigurationSetting> resolvedSetting in resolvedSettings)
10361036
{

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/Extensions/ContentTypeExtensions.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ public static bool IsKeyVaultReference(this ContentType contentType)
8383
return contentType.MediaType.Equals(KeyVaultConstants.ContentType);
8484
}
8585

86+
/*
87+
Profile and media type are distinct components of the content type.
88+
They aren't required to be space-separated, and their order isn't guaranteed.
89+
This makes raw string matching hard.
90+
*/
8691
public static bool IsSnapshotReference(this ContentType contentType)
8792
{
8893
return contentType.MediaType.Equals(SnapshotReferenceConstants.ContentType);

src/Microsoft.Extensions.Configuration.AzureAppConfiguration/SnapshotReferences/SnapshotReferenceParser.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ internal static class SnapshotReferenceParser
1616
/// Parses a snapshot name from a snapshot reference configuration setting.
1717
/// </summary>
1818
/// <param name="setting">The configuration setting containing the snapshot reference JSON.</param>
19-
/// <returns>The snapshot name if found and valid; otherwise, null.</returns>
19+
/// <returns>The snapshot reference if found and valid; otherwise, null.</returns>
2020
/// <exception cref="FormatException">Thrown when the setting contains invalid JSON or invalid snapshot reference format.</exception>
21-
public static string Parse(ConfigurationSetting setting)
21+
public static SnapshotReference Parse(ConfigurationSetting setting)
2222
{
2323
if (setting == null)
2424
{
@@ -32,7 +32,7 @@ public static string Parse(ConfigurationSetting setting)
3232

3333
try
3434
{
35-
Utf8JsonReader reader = new Utf8JsonReader(System.Text.Encoding.UTF8.GetBytes(setting.Value));
35+
var reader = new Utf8JsonReader(System.Text.Encoding.UTF8.GetBytes(setting.Value));
3636

3737
if (reader.Read() && reader.TokenType != JsonTokenType.StartObject)
3838
{
@@ -50,7 +50,7 @@ public static string Parse(ConfigurationSetting setting)
5050
{
5151
if (reader.Read() && reader.TokenType == JsonTokenType.String)
5252
{
53-
return reader.GetString();
53+
return new SnapshotReference { SnapshotName = reader.GetString() };
5454
}
5555
else
5656
{

0 commit comments

Comments
 (0)