Azure / Azure/azure-powershell
The Operation for DateTime musst be formated correct.
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 3d 14h
- Merged PRs (30d)
- 54
Description
### Description
In Module: CosmosDBSqlRestorableResource Line 66
The call with DateTime creates a wrong URI. It is not possible to use this function.
See line:
IEnumerable restorableSqlResources = CosmosDBManagementClient.RestorableSqlResources.ListWithHttpMessagesAsync(Location, DatabaseAccountInstanceId, RestoreLocation, dateTimeInUtc.ToString()
ToString musst be formated and used as following ToString(yyyy-MM-ddTHH:mm:ssZ)
Following URI was send. See time parameter at end of URI:
https://management.azure.com/subscriptions/xxxxxxxxxxxxxxxxxxxxx/providers/Microsoft.DocumentDB/locations/westeurope/restorableDatabaseAccounts/xxxxxxxxxxxxxxxxxxxxxxxxx/restorableSqlResources?api-version=2022-08-15-preview&restoreLocation=westeurope&restoreTimestampInUtc=07.08.2023 11%3A00%3A00
This is not working as a parameter:
restoreTimestampInUtc should be "2023-08-07T11:00:00Z" or "2023-08-07T11%3A00%3A00Z"
### Issue script & Debug output
```PowerShell
PS C:\Users\xxxxxxx\work> Get-AzCosmosDBSqlRestorableResource -Location "westeurope" -DatabaseAccountInstanceId $account.InstanceId -RestoreTimestampInUtc $time -RestoreLocation "westeurope" -Debug
09:34:47 - GetAzCosmosDBSqlRestorableResource begin processing with ParameterSet 'ByNameParameterSet'.
09:34:47 - using account id 'xxxxxx@xxxxxxxxxxxxxx.com'...
09:34:47 - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
[Common.Authentication]: Authenticating using Account: 'xxxxxx@xxxxxxxxxxxxxx.com', environment: 'AzureCloud', tenant: 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
09:34:47 - [ConfigManager] Got nothing from [EnableLoginByWam], Module = [], Cmdlet = []. Returning default value [False].
09:34:47 - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - TenantId:'xxxxxxxxxxxxxxxxxxxxxx', Scopes:'https://management.core.windows.net//.default', AuthorityHost:'https://login.microsoftonline.com/', UserId:'xxxxxx@xxxxxxxxxxxxxx.com'
SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://management.core.windows.net//.default ] ParentRequestId: ......
=== Request Data ===
Authority Provided? - True
Scopes - https://management.core.windows.net//.default
Extra Query Params Keys (space separated) -
ApiId - AcquireTokenSilent
IsConfidentialClient - False
SendX5C - False
LoginHint ? False
IsBrokerConfigured - False
HomeAccountId - False
CorrelationId - 42eb5183-0635-4298-9e3a-6ab8810a80bc
UserAssertion set: False
LongRunningOboCacheKey set: False
Region configured:.....................
============================ HTTP REQUEST ============================
HTTP Method:
GET
Absolute Uri:
https://management.azure.com/subscriptions/xxxxxxxxxxxxxxxxxxxxx/providers/Microsoft.DocumentDB/locations/westeurope/restorableDatabaseAccounts/xxxxxxxxxxxxxxxxxxxxxxxxx/restorableSqlResources?api-version=2022-08-15-preview&restoreLocation=westeurope&restoreTimestampInUtc=07.08.2023 00%3A00%3A00
Headers:
Accept-Language : en-US
x-ms-client-request-id : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Body:
============================ HTTP RESPONSE ============================
Status Code:
BadRequest
Headers:
Cache-Control : no-store, no-cache
Pragma : no-cache
Strict-Transport-Security : max-age=31536000; includeSubDomains
x-ms-gatewayversion : version=2.14.0
Server : Microsoft-HTTPAPI/2.0
x-ms-ratelimit-remaining-subscription-reads: 11999
x-ms-request-id : xxxxxxxxxxxxxxxxxxxxxxxx
x-ms-correlation-request-id : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
x-ms-routing-request-id : xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
X-Content-Type-Options : nosniff
Date : Tue, 08 Aug 2023 07:34:48 GMT
Body:
{
"code": "BadRequest",
"message": "Invalid restore timestamp. Please provide a time (in UTC) after the account has been created\r\nActivityId: 31212913-aa93-47c6-b138-e2716fa1c4d4, Microsoft.Azure.Documents.Common/2.14.0"
}
09:34:48 - [ConfigManager] Got [True] from [EnableDataCollection], Module = [], Cmdlet = [].
Get-AzCosmosDBSqlRestorableResource: Invalid restore timestamp. Please provide a time (in UTC) after the account has been created
ActivityId: 31212913-aa93-47c6-b138-e2716fa1c4d4, Microsoft.Azure.Documents.Common/2.14.0
09:34:48 - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
09:34:48 - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
AzureQoSEvent: Module: Az.CosmosDB:1.9.1; CommandName: Get-AzCosmosDBSqlRestorableResource; PSVersion: 7.3.4; IsSuccess: False; Duration: 00:00:00.9696702; Exception: Invalid restore timestamp. Please provide a
time (in UTC) after the account has been created
ActivityId: xxxxxxxxxxxxxxxxxxxxxxxxxxxxx, Microsoft.Azure.Documents.Common/2.14.0;
09:34:48 - GetAzCosmosDBSqlRestorableResource end processing.
```
### Environment data
```PowerShell
ame Value
---- -----
PSVersion 7.3.4
PSEdition Core
GitCommitId 7.3.4
OS Microsoft Windows 10.0.19045
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```
### Module versions
```PowerShell
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.12.1 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
Script 1.9.1 Az.CosmosDB {Get-AzCosmosDBAccount, Get-AzCosmosDBAccountKey, Get-AzCosmosDBCassandraKeyspace, Get-AzCosmosDBCassandraKeyspaceThroughput…}
```
### Error output
```PowerShell
RequestId : xxxxxxxxxxxxxxxxxxxxxxxxxx
Message : Invalid restore timestamp. Please provide a time (in UTC) after the account has been created
ActivityId: xxxxxxxxxxxxxxxxxxxxxxxxx, Microsoft.Azure.Documents.Common/2.14.0
ServerMessage : BadRequest: Invalid restore timestamp. Please provide a time (in UTC) after the account has been created
ActivityId: xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx, Microsoft.Azure.Documents.Common/2.14.0 (System.Collections.Generic.List`1[Microsoft.Rest.Azure.CloudError])
ServerResponse : {BadRequest}
RequestMessage : {GET https://management.azure.com/subscriptions/xxxxxxxxxxxxxxxxxxxxxxxx/providers/Microsoft.DocumentDB/locations/west europe/restorableDatabaseAccounts/xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/restorableSqlResources?api-version=2022-08-15-preview&restoreLocation=west europe&restoreTimestampInUtc=07.08.2023 00%3A00%3A00}
InvocationInfo : {Get-AzCosmosDBSqlRestorableResource}
Line : Get-AzCosmosDBSqlRestorableResource -Location "xxxxxxxxxxxxx" -DatabaseAccountInstanceId $account.InstanceId -RestoreTimestampInUtc $time -RestoreLocation "xxxxxxxxxxxxxxxxxxx"
Position : At line:1 char:1
+ Get-AzCosmosDBSqlRestorableResource -Location "xxxxxxxxxxxxxxxxx" -Database …
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
StackTrace : at Microsoft.Azure.Management.CosmosDB.RestorableSqlResourcesOperations.ListWithHttpMessagesAsync(String location, String instanceId, String restoreLocation, String restoreTimestampInUtc, Dictionary`2 customHeaders, CancellationToken cancellationToken)
at Microsoft.Azure.Commands.CosmosDB.GetAzCosmosDBSqlRestorableResource.ExecuteCmdlet()
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.<>c__3`1.b__3_0(T c)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet, Action`1 executor)
at Microsoft.WindowsAzure.Commands.Utilities.Common.CmdletExtensions.ExecuteSynchronouslyOrAsJob[T](T cmdlet)
at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord()
```
Contributor guide
Research direction
Start in the CosmosDBSqlRestorableResource module around line 66 and inspect the call to ListWithHttpMessagesAsync used by Get-AzCosmosDBSqlRestorableResource. Reproduce the request with the issue's PowerShell command and verify that restoreTimestampInUtc uses the required UTC ISO format; done means the generated URI contains the expected timestamp and the request is accepted.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- azure, csharp, powershell
- Domain
- api, cloud
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100