Azure表存储REST查询不显示新条目

时间:2019-11-19 10:38:29

标签: azure powershell azure-table-storage azure-rest-api

我正在为Azure存储帐户(在这种情况下为表格)建立查询。我尝试接收过去一天的最后一个日志条目。

在存储查询构建器中,过滤器如下所示:

{
  "filter": [
    {
      "id": "{ID}",
      "andOr": "And",
      "field": "TIMESTAMP",
      "type": "DateTime",
      "operator": ">=",
      "value": "datetime'2019-11-18T10:08:41.296Z'",
      "timeValue": "Last 24 hours",
      "timestampType": "time",
      "customTimestamp": {
        "lastNumber": 7,
        "lastTimeUnit": "Days"
      },
      "isLocal": true
    }
  ],
  "select": null,
  "group": {
    "id": "{ID}",
    "children": [
      "{CHILD}"
    ]
  },
  "top": null,
  "filterType": "Query Builder",
  "fileVersion": 0.2
}

此查询返回前一天的所有条目。 我试图在Azure REST API调用中使用此筛选器。在这样的Powershell函数中:

function GetTableEntityAll($TableName) {
    $version = "2017-04-17"
    $resource = "$tableName()" 
    $DST =  [DateTime]::Today.AddDays(-1)
    $table_url = "https://$storageAccount.table.core.windows.net/$resource"+ '?$filter=Timestamp gt datetime' + "'"+ $DST.ToString("s") + "'"
write-host $table_url
    $GMTTime = (Get-Date).ToUniversalTime().toString('R')
    $stringToSign = "$GMTTime`n/$storageAccount/$resource"
    $hmacsha = New-Object System.Security.Cryptography.HMACSHA256
    $hmacsha.key = [Convert]::FromBase64String($accesskey)
    $signature = $hmacsha.ComputeHash([Text.Encoding]::UTF8.GetBytes($stringToSign))
    $signature = [Convert]::ToBase64String($signature)
    $headers = @{
        'x-ms-date'    = $GMTTime
        Authorization  = "SharedKeyLite " + $storageAccount + ":" + $signature
        "x-ms-version" = $version
        Accept         = "application/json;odata=fullmetadata"
    }
    $item = Invoke-RestMethod -Method GET -Uri $table_url -Headers $headers -ContentType application/json
    return $item.value
}

由此生成的URL是:

https://{Accountname}.table.core.windows.net/{Tablename}()?$filter=Timestamp gt datetime'2019-11-18T00:00:00'

这不返回任何记录。我也尝试对URL进行编码,但这也不起作用。如果我将日期时间更改为2016,则会收到前几条记录。

Azure文档:https://docs.microsoft.com/en-us/rest/api/storageservices/querying-tables-and-entities

有什么想法吗?

0 个答案:

没有答案