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

Use Fixed Format String to Serialize Timestamp into Query String #26388

Closed
wants to merge 4 commits into from
Closed
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
2 changes: 1 addition & 1 deletion .azure-pipelines/powershell-core.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ variables:
LinuxAgentPoolVMImage: ''
MacOSName: macOS
MacOSAgentPoolName: 'Azure Pipelines'
MacOSAgentPoolVMImage: macOS-13
MacOSAgentPoolVMImage: macOS-latest
TestFramework: net6.0
TestTarget: Test
Configuration: Debug
Expand Down
1 change: 1 addition & 0 deletions src/CosmosDB/CosmosDB/ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
-->

## Upcoming Release
* Serialized timestamp into query string by invariant culture for `Restore-AzCosmosDBAccount` and `Restore-AzCosmosDBTable`.

## Version 1.15.0
* Added new parameter `DisableTtl` to `Restore-AzCosmosDBAccount`.
Expand Down
24 changes: 13 additions & 11 deletions src/CosmosDB/CosmosDB/CosmosDBAccount/RestoreAzCosmosDBAccount.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Management.Automation;
using Microsoft.Azure.Commands.Common;
using Microsoft.Azure.Commands.CosmosDB.Helpers;
using Microsoft.Azure.Commands.CosmosDB.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.CosmosDB.Models;
using Microsoft.Extensions.Azure;

using Newtonsoft.Json.Converters;

using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Management.Automation;

using SDKModel = Microsoft.Azure.Management.CosmosDB.Models;

namespace Microsoft.Azure.Commands.CosmosDB
Expand Down Expand Up @@ -138,7 +140,7 @@ public override void ExecuteCmdlet()
sourceAccountToRestore.Location,
sourceAccountToRestore.Name,
Location,
utcRestoreDateTime.ToString()).GetAwaiter().GetResult().Body;
utcRestoreDateTime.ToInvariantString()).GetAwaiter().GetResult().Body;

restorableResourcesNotFound = restorableResources == null || !restorableResources.Any();
}
Expand All @@ -156,7 +158,7 @@ public override void ExecuteCmdlet()
sourceAccountToRestore.Location,
sourceAccountToRestore.Name,
Location,
utcRestoreDateTime.ToString()).GetAwaiter().GetResult().Body;
utcRestoreDateTime.ToInvariantString()).GetAwaiter().GetResult().Body;

restorableResourcesNotFound = restorableResources == null || !restorableResources.Any();
}
Expand All @@ -174,7 +176,7 @@ public override void ExecuteCmdlet()
sourceAccountToRestore.Location,
sourceAccountToRestore.Name,
Location,
utcRestoreDateTime.ToString()).GetAwaiter().GetResult().Body;
utcRestoreDateTime.ToInvariantString()).GetAwaiter().GetResult().Body;

restorableResourcesNotFound = restorableResources == null || !restorableResources.Any();
}
Expand All @@ -192,7 +194,7 @@ public override void ExecuteCmdlet()
sourceAccountToRestore.Location,
sourceAccountToRestore.Name,
Location,
utcRestoreDateTime.ToString()).GetAwaiter().GetResult().Body;
utcRestoreDateTime.ToInvariantString()).GetAwaiter().GetResult().Body;

restorableResourcesNotFound = restorableResources == null || !restorableResources.Any();
}
Expand Down
4 changes: 2 additions & 2 deletions src/CosmosDB/CosmosDB/Table/RestoreAzCosmosDBTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
using System;
using System.Collections.Generic;
using System.Management.Automation;
using Microsoft.Azure.Commands.Common;
using Microsoft.Azure.Commands.CosmosDB.Models;
using Microsoft.Azure.Commands.ResourceManager.Common.ArgumentCompleters;
using Microsoft.Azure.Management.CosmosDB.Models;
using Microsoft.Azure.Management.Internal.Resources.Utilities.Models;
using Microsoft.Azure.Commands.CosmosDB.Helpers;
using Microsoft.Azure.Commands.CosmosDB.Exceptions;
using Microsoft.Rest.Azure;
Expand Down Expand Up @@ -170,7 +170,7 @@ public override void ExecuteCmdlet()

string accountInstanceId = databaseAccount.Name;

IEnumerable restorableTables = CosmosDBManagementClient.RestorableTables.ListWithHttpMessagesAsync(databaseAccount.Location, accountInstanceId, databaseAccount.CreationTime.ToString(), DateTime.MaxValue.ToString()).GetAwaiter().GetResult().Body;
IEnumerable restorableTables = CosmosDBManagementClient.RestorableTables.ListWithHttpMessagesAsync(databaseAccount.Location, accountInstanceId, databaseAccount.CreationTime?.ToInvariantString(), DateTime.MaxValue.ToInvariantString()).GetAwaiter().GetResult().Body;
(DateTime latestDatabaseDeleteTime, DateTime latestDatabaseCreateOrRecreateTime, string databaseRid) = ProcessRestorableDatabases(restorableTables);

if (databaseRid == null)
Expand Down
14 changes: 8 additions & 6 deletions src/Monitor/Monitor.Test/CustomPrinterTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@
// limitations under the License.
// ----------------------------------------------------------------------------------

using Microsoft.Azure.Commands.Common;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;

using System;
using System.Globalization;
using System.Collections.Generic;
using System.Diagnostics;
using System.Xml;
using Microsoft.Azure.ServiceManagement.Common.Models;
using Microsoft.WindowsAzure.Commands.ScenarioTest;

using Xunit;
using Xunit.Abstractions;

Expand Down Expand Up @@ -51,10 +53,10 @@ public void CustomPrinterTest_SimpleTypes()
Assert.Equal(" : " + XmlConvert.ToString(ts) + Environment.NewLine, OutputClasses.CustomPrinter.Print(ts));

// Must be dt.ToUniversalTime().ToString("O") in the future
Assert.Equal(" : " + dt.ToString(CultureInfo.InvariantCulture) + Environment.NewLine, OutputClasses.CustomPrinter.Print(dt));
Assert.Equal(" : " + dt.ToInvariantString() + Environment.NewLine, OutputClasses.CustomPrinter.Print(dt));

// Must be dtUtc.ToString("O") in the future
Assert.Equal(" : " + dtUtc.ToString(CultureInfo.InvariantCulture) + Environment.NewLine, OutputClasses.CustomPrinter.Print(dtUtc));
Assert.Equal(" : " + dtUtc.ToInvariantString() + Environment.NewLine, OutputClasses.CustomPrinter.Print(dtUtc));

// Both must be string.Empty in the future
Assert.Equal($" :{Environment.NewLine}", OutputClasses.CustomPrinter.Print(null));
Expand Down Expand Up @@ -87,7 +89,7 @@ public void CustomPrinterTest_ComplexTypes()

// Must be [\r\nAuthorization : [\r\n Action : PUT\r\n Role : Sender\r\n Scope : None\r\n ]\r\nClaims : {\r\n [aud, https://management.core.windows.net/]\r\n [iss, https://sts.windows.net/123456/]\r\n [iat, h123445]\r\n }\r\nCaller : caller\r\nDescription : fake event\r\nId : ac7d2ab5-698a-4c33-9c19-0a93d3d7f527\r\nEventDataId : \r\nCorrelationId : correlation\r\nEventName : [\r\n Value : Start request\r\n LocalizedValue : Start request\r\n ]\r\nCategory : [\r\n Value : Microsoft Resources\r\n LocalizedValue : Microsoft Resources\r\n ]\r\nHttpRequest : [\r\n ClientRequestId : 1234\r\n ClientIpAddress : 123.123.123.123\r\n Method : PUT\r\n Uri : http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy\r\n ]\r\nLevel : Informational\r\nResourceGroupName : Default-Web-EastUS\r\nResourceProviderName : [\r\n Value : Microsoft Resources\r\n LocalizedValue : Microsoft Resources\r\n ]\r\nResourceId : /subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/garyyang1\r\nResourceType : \r\nOperationId : c0f2e85f-efb0-47d0-bf90-f983ec8be91d\r\nOperationName : [\r\n Value : Microsoft.Resources/subscriptions/resourcegroups/deployments/write\r\n LocalizedValue : Microsoft.Resources/subscriptions/resourcegroups/deployments/write\r\n ]\r\nProperties : {}\r\nStatus : [\r\n Value : Succeeded\r\n LocalizedValue : Succeeded\r\n ]\r\nSubStatus : [\r\n Value : Created\r\n LocalizedValue : Created\r\n ]\r\nEventTimestamp : 2017-06-07T22:54:00.0000000Z\r\nSubmissionTimestamp : 2017-06-07T22:54:00.0000000Z\r\nSubscriptionId : \r\nTenantId : \r\n] in the future
Assert.Equal(
expected: $"Authorization {Environment.NewLine}Action : PUT{Environment.NewLine}Role : Sender{Environment.NewLine}Scope : None{Environment.NewLine}{Environment.NewLine}Claims {Environment.NewLine} : [aud, https://management.core.windows.net/]{Environment.NewLine} : [iss, https://sts.windows.net/123456/]{Environment.NewLine} : [iat, h123445]{Environment.NewLine}Caller : caller{Environment.NewLine}Description : fake event{Environment.NewLine}Id : ac7d2ab5-698a-4c33-9c19-0a93d3d7f527{Environment.NewLine}EventDataId :{Environment.NewLine}CorrelationId : correlation{Environment.NewLine}EventName {Environment.NewLine}Value : Start request{Environment.NewLine}LocalizedValue : Start request{Environment.NewLine}{Environment.NewLine}Category {Environment.NewLine}Value : Microsoft Resources{Environment.NewLine}LocalizedValue : Microsoft Resources{Environment.NewLine}{Environment.NewLine}HttpRequest {Environment.NewLine}ClientRequestId : 1234{Environment.NewLine}ClientIpAddress : 123.123.123.123{Environment.NewLine}Method : PUT{Environment.NewLine}Uri : http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy{Environment.NewLine}{Environment.NewLine}Level : Informational{Environment.NewLine}ResourceGroupName : Default-Web-EastUS{Environment.NewLine}ResourceProviderName{Environment.NewLine}Value : Microsoft Resources{Environment.NewLine}LocalizedValue : Microsoft Resources{Environment.NewLine}{Environment.NewLine}ResourceId : /subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/garyyang1{Environment.NewLine}ResourceType :{Environment.NewLine}OperationId : c0f2e85f-efb0-47d0-bf90-f983ec8be91d{Environment.NewLine}OperationName {Environment.NewLine}Value : Microsoft.Resources/subscriptions/resourcegroups/deployments/write{Environment.NewLine}LocalizedValue : Microsoft.Resources/subscriptions/resourcegroups/deployments/write{Environment.NewLine}{Environment.NewLine}Properties {Environment.NewLine}Status {Environment.NewLine}Value : Succeeded{Environment.NewLine}LocalizedValue : Succeeded{Environment.NewLine}{Environment.NewLine}SubStatus {Environment.NewLine}Value : Created{Environment.NewLine}LocalizedValue : Created{Environment.NewLine}{Environment.NewLine}EventTimestamp : 06/07/{year} 22:54:00{Environment.NewLine}SubmissionTimestamp : 06/07/{year} 22:54:00{Environment.NewLine}SubscriptionId :{Environment.NewLine}TenantId :{Environment.NewLine}{Environment.NewLine}",
expected: $"Authorization {Environment.NewLine}Action : PUT{Environment.NewLine}Role : Sender{Environment.NewLine}Scope : None{Environment.NewLine}{Environment.NewLine}Claims {Environment.NewLine} : [aud, https://management.core.windows.net/]{Environment.NewLine} : [iss, https://sts.windows.net/123456/]{Environment.NewLine} : [iat, h123445]{Environment.NewLine}Caller : caller{Environment.NewLine}Description : fake event{Environment.NewLine}Id : ac7d2ab5-698a-4c33-9c19-0a93d3d7f527{Environment.NewLine}EventDataId :{Environment.NewLine}CorrelationId : correlation{Environment.NewLine}EventName {Environment.NewLine}Value : Start request{Environment.NewLine}LocalizedValue : Start request{Environment.NewLine}{Environment.NewLine}Category {Environment.NewLine}Value : Microsoft Resources{Environment.NewLine}LocalizedValue : Microsoft Resources{Environment.NewLine}{Environment.NewLine}HttpRequest {Environment.NewLine}ClientRequestId : 1234{Environment.NewLine}ClientIpAddress : 123.123.123.123{Environment.NewLine}Method : PUT{Environment.NewLine}Uri : http://path/subscriptions/ffce8037-a374-48bf-901d-dac4e3ea8c09/resourcegroups/foo/deployments/testdeploy{Environment.NewLine}{Environment.NewLine}Level : Informational{Environment.NewLine}ResourceGroupName : Default-Web-EastUS{Environment.NewLine}ResourceProviderName{Environment.NewLine}Value : Microsoft Resources{Environment.NewLine}LocalizedValue : Microsoft Resources{Environment.NewLine}{Environment.NewLine}ResourceId : /subscriptions/a93fb07c-6c93-40be-bf3b-4f0deba10f4b/resourceGroups/Default-Web-EastUS/providers/microsoft.web/sites/garyyang1{Environment.NewLine}ResourceType :{Environment.NewLine}OperationId : c0f2e85f-efb0-47d0-bf90-f983ec8be91d{Environment.NewLine}OperationName {Environment.NewLine}Value : Microsoft.Resources/subscriptions/resourcegroups/deployments/write{Environment.NewLine}LocalizedValue : Microsoft.Resources/subscriptions/resourcegroups/deployments/write{Environment.NewLine}{Environment.NewLine}Properties {Environment.NewLine}Status {Environment.NewLine}Value : Succeeded{Environment.NewLine}LocalizedValue : Succeeded{Environment.NewLine}{Environment.NewLine}SubStatus {Environment.NewLine}Value : Created{Environment.NewLine}LocalizedValue : Created{Environment.NewLine}{Environment.NewLine}EventTimestamp : 6/7/{year} 10:54:00 PM{Environment.NewLine}SubmissionTimestamp : 6/7/{year} 10:54:00 PM{Environment.NewLine}SubscriptionId :{Environment.NewLine}TenantId :{Environment.NewLine}{Environment.NewLine}",
actual: result);

dictionarySS.Add("k1", "v1");
Expand Down
4 changes: 3 additions & 1 deletion src/Monitor/Monitor/OutputClasses/CustomPrinter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
using System.Text;
using System.Xml;

using Microsoft.Azure.Commands.Common;

namespace Microsoft.Azure.Commands.Insights.OutputClasses
{
public static class CustomPrinter
Expand Down Expand Up @@ -73,7 +75,7 @@ private static void Print(object obj, string name, string currentIndent, StringB
sb.Append(" : ");
if (obj is DateTime dateTime)
{
sb.AppendLine(dateTime.ToString(System.Globalization.CultureInfo.InvariantCulture));
sb.AppendLine(dateTime.ToInvariantString());
}
else
{
Expand Down
Loading