Skip to content

Commit

Permalink
Direct: Adds version 3.29.0 (#3308)
Browse files Browse the repository at this point in the history
* bump direct version

* use new Rfc1123DateTimeCache type

* add benchmark

* add using and update direct dependency

* update dependency test + regions list

* fix regions ordering

* update contract

* renaming benchmark
  • Loading branch information
imanvt authored Jul 5, 2022
1 parent 0a307be commit 1676475
Show file tree
Hide file tree
Showing 17 changed files with 72 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<ClientOfficialVersion>3.28.0</ClientOfficialVersion>
<ClientPreviewVersion>3.28.0</ClientPreviewVersion>
<ClientPreviewSuffixVersion>preview</ClientPreviewSuffixVersion>
<DirectVersion>3.28.2</DirectVersion>
<DirectVersion>3.29.0</DirectVersion>
<EncryptionOfficialVersion>1.0.1</EncryptionOfficialVersion>
<EncryptionPreviewVersion>1.0.1</EncryptionPreviewVersion>
<EncryptionPreviewSuffixVersion>preview</EncryptionPreviewSuffixVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@ public static void CheckTimeRangeIsCurrent(
RMResources.InvalidTokenTimeRange,
startDateTime.ToString("r", CultureInfo.InvariantCulture),
expiryDateTime.ToString("r", CultureInfo.InvariantCulture),
DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture));
Rfc1123DateTimeCache.UtcNow());

DefaultTrace.TraceError(message);

Expand Down Expand Up @@ -482,7 +482,7 @@ public static int SerializeMessagePayload(
throw new UnauthorizedException(RMResources.InvalidDateHeader);
}

headers[HttpConstants.HttpHeaders.XDate] = DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture);
headers[HttpConstants.HttpHeaders.XDate] = Rfc1123DateTimeCache.UtcNow();
xDate = AuthorizationHelper.GetHeaderValue(headers, HttpConstants.HttpHeaders.XDate);
}

Expand Down Expand Up @@ -662,7 +662,7 @@ private static void ValidateInputRequestTime(
RMResources.InvalidTokenTimeRange,
utcStartTime.ToString("r", CultureInfo.InvariantCulture),
DateTime.MaxValue.ToString("r", CultureInfo.InvariantCulture),
DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture));
Rfc1123DateTimeCache.UtcNow());

DefaultTrace.TraceError(message);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public async Task AddSystemAuthorizationHeaderAsync(
string verb,
string resourceId)
{
request.Headers[HttpConstants.HttpHeaders.XDate] = DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture);
request.Headers[HttpConstants.HttpHeaders.XDate] = Rfc1123DateTimeCache.UtcNow();

request.Headers[HttpConstants.HttpHeaders.Authorization] = (await this.GetUserAuthorizationAsync(
resourceId ?? request.ResourceAddress,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public AuthorizationTokenProviderMasterKey(string authKey)
AuthorizationTokenType tokenType)
{
// this is masterkey authZ
headers[HttpConstants.HttpHeaders.XDate] = DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture);
headers[HttpConstants.HttpHeaders.XDate] = Rfc1123DateTimeCache.UtcNow();

string authorizationToken = AuthorizationHelper.GenerateKeyAuthorizationSignature(
requestVerb,
Expand Down Expand Up @@ -97,7 +97,7 @@ public override ValueTask<string> GetUserAuthorizationTokenAsync(
ITrace trace)
{
// this is masterkey authZ
headers[HttpConstants.HttpHeaders.XDate] = DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture);
headers[HttpConstants.HttpHeaders.XDate] = Rfc1123DateTimeCache.UtcNow();

string authorizationToken = AuthorizationHelper.GenerateKeyAuthorizationSignature(
requestVerb,
Expand All @@ -119,7 +119,7 @@ public override ValueTask AddAuthorizationHeaderAsync(
string verb,
AuthorizationTokenType tokenType)
{
string dateTime = DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture);
string dateTime = Rfc1123DateTimeCache.UtcNow();
headersCollection[HttpConstants.HttpHeaders.XDate] = dateTime;

string token = AuthorizationHelper.GenerateKeyAuthorizationSignature(
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/DocumentClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5493,7 +5493,7 @@ private async Task<StoredProcedureResponse<TValue>> ExecuteStoredProcedurePrivat
AuthorizationTokenType.PrimaryMasterKey,
headers))
{
request.Headers[HttpConstants.HttpHeaders.XDate] = DateTime.UtcNow.ToString("r");
request.Headers[HttpConstants.HttpHeaders.XDate] = Rfc1123DateTimeCache.UtcNow();
if (options?.PartitionKeyRangeId == null)
{
await this.AddPartitionKeyInformationAsync(
Expand Down
2 changes: 1 addition & 1 deletion Microsoft.Azure.Cosmos/src/Microsoft.Azure.Cosmos.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
<PackageReference Include="StyleCop.Analyzers" Version="1.1.118" PrivateAssets="All" />

<!--Direct Dependencies-->
<PackageReference Include="System.Configuration.ConfigurationManager" Version="4.7.0" />
<PackageReference Include="System.Configuration.ConfigurationManager" Version="6.0.0" />

<!--HybridRow Dependencies-->
<PackageReference Include="System.Memory" Version="4.5.4" />
Expand Down
12 changes: 11 additions & 1 deletion Microsoft.Azure.Cosmos/src/Regions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ public static class Regions
public const string JioIndiaWest = "Jio India West";

/// <summary>
/// Name of the Azure US SLV region in the Azure Cosmos DB service.
/// Name of the Azure East US SLV region in the Azure Cosmos DB service.
/// </summary>
public const string EastUSSLV = "East US SLV";

Expand All @@ -334,5 +334,15 @@ public static class Regions
/// Name of the Azure Qatar Central region in the Azure Cosmos DB service.
/// </summary>
public const string QatarCentral = "Qatar Central";

/// <summary>
/// Name of the Azure China North 3 region in the Azure Cosmos DB service.
/// </summary>
public const string ChinaNorth3 = "China North 3";

/// <summary>
/// Name of the Azure China East 3 region in the Azure Cosmos DB service.
/// </summary>
public const string ChinaEast3 = "China East 3";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ private async Task<ContainerProperties> ReadCollectionAsync(
AuthorizationTokenType.PrimaryMasterKey,
headers))
{
headers.XDate = DateTime.UtcNow.ToString("r");
headers.XDate = Rfc1123DateTimeCache.UtcNow();

request.RequestContext.ClientRequestStatistics =
clientSideRequestStatistics ?? new ClientSideRequestStatisticsTraceDatum(DateTime.UtcNow);
Expand Down
4 changes: 2 additions & 2 deletions Microsoft.Azure.Cosmos/src/Routing/GatewayAddressCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ private async Task<DocumentServiceResponse> GetMasterAddressesViaGatewayAsync(

string resourceTypeToSign = PathsHelper.GetResourcePath(resourceType);

headers.Set(HttpConstants.HttpHeaders.XDate, DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture));
headers.Set(HttpConstants.HttpHeaders.XDate, Rfc1123DateTimeCache.UtcNow());
using (ITrace trace = Trace.GetRootTrace(nameof(GetMasterAddressesViaGatewayAsync), TraceComponent.Authorization, TraceLevel.Info))
{
string token = await this.tokenProvider.GetUserAuthorizationTokenAsync(
Expand Down Expand Up @@ -545,7 +545,7 @@ private async Task<DocumentServiceResponse> GetServerAddressesViaGatewayAsync(

string resourceTypeToSign = PathsHelper.GetResourcePath(ResourceType.Document);

headers.Set(HttpConstants.HttpHeaders.XDate, DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture));
headers.Set(HttpConstants.HttpHeaders.XDate, Rfc1123DateTimeCache.UtcNow());
string token = null;

using (ITrace trace = Trace.GetRootTrace(nameof(GetMasterAddressesViaGatewayAsync), TraceComponent.Authorization, TraceLevel.Info))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private static string GenerateMasterKeyAuthorizationSignature(

private static string GetUtcDateTime()
{
return DateTime.UtcNow.ToString("r");
return Rfc1123DateTimeCache.UtcNow();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ internal static void AddMasterAuthorizationHeader(this HttpClient client, string
if (string.IsNullOrEmpty(key)) throw new ArgumentException("key");
if (headers == null) throw new ArgumentNullException("headers");

string xDate = DateTime.UtcNow.ToString("r");
string xDate = Rfc1123DateTimeCache.UtcNow();

client.DefaultRequestHeaders.Remove(HttpConstants.HttpHeaders.XDate);
client.DefaultRequestHeaders.Add(HttpConstants.HttpHeaders.XDate, xDate);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
namespace Microsoft.Azure.Cosmos.Benchmarks
{
using System;
using BenchmarkDotNet.Attributes;
using Microsoft.Azure.Documents;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

[MemoryDiagnoser]
public class DateTimeAllocationsBenchmark
{
public DateTimeAllocationsBenchmark()
{
}

[Benchmark]
public void DateTimeToString()
{
_ = DateTime.UtcNow.ToString("r");
}

[Benchmark]
public void Rfc1123DateTimeCacheUtcNow()
{
_ = Rfc1123DateTimeCache.UtcNow();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public MasterKeyAuthorizationBenchmark()
{
this.authKeyHashFunction = new StringHMACSHA256Hash(MockDocumentClient.GenerateRandomKey());
Headers headers = new Headers();
headers[HttpConstants.HttpHeaders.XDate] = DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture);
headers[HttpConstants.HttpHeaders.XDate] = Rfc1123DateTimeCache.UtcNow();

this.testHeaders = headers.CosmosMessageHeaders.INameValueCollection;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ ValueTask<string> ICosmosAuthorizationTokenProvider.GetUserAuthorizationTokenAsy
ITrace trace) // unused, use token based upon what is passed in constructor
{
// this is masterkey authZ
headers[HttpConstants.HttpHeaders.XDate] = DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture);
headers[HttpConstants.HttpHeaders.XDate] = Rfc1123DateTimeCache.UtcNow();

string authorization = AuthorizationHelper.GenerateKeyAuthorizationSignature(
verb: requestVerb,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ namespace Microsoft.Azure.Cosmos.Tests.Authorization
using System.Globalization;
using System.Text;
using Microsoft.Azure.Cosmos;
using Microsoft.Azure.Documents;
using Microsoft.Azure.Documents.Collections;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
Expand All @@ -21,7 +22,7 @@ public class AuthorizationHelperTests
public void TestGenerateAuthorizationTokenWithHashCoreDoesNotEncodeUrl()
{
Mock<INameValueCollection> mockHeaders = new Mock<INameValueCollection>();
mockHeaders.SetupGet(h => h["x-ms-date"]).Returns(DateTime.UtcNow.ToString("r", CultureInfo.InvariantCulture));
mockHeaders.SetupGet(h => h["x-ms-date"]).Returns(Rfc1123DateTimeCache.UtcNow());
Mock<IComputeHash> hashHelperMock = new Mock<IComputeHash>();
hashHelperMock.Setup(
ch => ch.ComputeHash(It.IsAny<ArraySegment<byte>>()))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public void ProjectPackageDependenciesTest()
{ "System.Numerics.Vectors", new Version(4, 5, 0) },
{ "Newtonsoft.Json", new Version(10, 0, 2) },
{ "Microsoft.Bcl.AsyncInterfaces", new Version(1, 0, 0) },
{ "System.Configuration.ConfigurationManager", new Version(4, 7, 0) },
{ "System.Configuration.ConfigurationManager", new Version(6, 0, 0) },
{ "System.Memory", new Version(4, 5, 4) },
{ "System.Buffers", new Version(4, 5, 1) },
{ "System.Runtime.CompilerServices.Unsafe", new Version(4, 6, 0) },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6314,6 +6314,11 @@
"Attributes": [],
"MethodInfo": "System.String ChinaEast2;IsInitOnly:False;IsStatic:True;"
},
"System.String ChinaEast3": {
"Type": "Field",
"Attributes": [],
"MethodInfo": "System.String ChinaEast3;IsInitOnly:False;IsStatic:True;"
},
"System.String ChinaNorth": {
"Type": "Field",
"Attributes": [],
Expand All @@ -6324,6 +6329,11 @@
"Attributes": [],
"MethodInfo": "System.String ChinaNorth2;IsInitOnly:False;IsStatic:True;"
},
"System.String ChinaNorth3": {
"Type": "Field",
"Attributes": [],
"MethodInfo": "System.String ChinaNorth3;IsInitOnly:False;IsStatic:True;"
},
"System.String EastAsia": {
"Type": "Field",
"Attributes": [],
Expand Down

0 comments on commit 1676475

Please sign in to comment.