Bash Azure存储表API REST with Curl

Bash Azure存储表API REST with Curl,bash,rest,azure,curl,azure-table-storage,Bash,Rest,Azure,Curl,Azure Table Storage,我需要帮助打印一个实体与壳脚本休息。我尝试了几种方法,但都没有成功 这是我的代码,运行它,它将返回表中的所有实体 但我需要它只返回一个特定的值,这只是使用PartitionKey #!/bin/bash # List the tables in an Azure storage container. storage_account="Secret" table_name="teste" access_key="Secret" table_store_url="table.core.wind

我需要帮助打印一个实体与壳脚本休息。我尝试了几种方法,但都没有成功

这是我的代码,运行它,它将返回表中的所有实体

但我需要它只返回一个特定的值,这只是使用PartitionKey

#!/bin/bash

# List the tables in an Azure storage container.

storage_account="Secret"
table_name="teste"
access_key="Secret"

table_store_url="table.core.windows.net"
authorization="SharedKey"

request_method="GET"
request_date=$(TZ=GMT LC_ALL=en_US.utf8 date "+%a, %d %h %Y %H:%M:%S %Z")
#request_date="Mon, 18 Apr 2016 05:16:09 GMT"
storage_service_version="2018-03-28"

# HTTP Request headers
x_ms_date_h="x-ms-date:$request_date"
x_ms_version_h="x-ms-version:$storage_service_version"

# Build the signature string
canonicalized_resource="/${storage_account}/${table_name}"


string_to_sign="${request_method}\n\n\n$request_date\n${canonicalized_resource}"

# Decode the Base64 encoded access key, convert to Hex.
decoded_hex_key="$(echo -n $access_key | base64 -d -w0 | xxd -p -c256)"


# Create the HMAC signature for the Authorization header
signature=$(printf "$string_to_sign" | openssl dgst -sha256 -mac HMAC -macopt "hexkey:$decoded_hex_key" -binary |  base64 -w0)

authorization_header="Authorization: $authorization $storage_account:$signature"

curl -s \
  -H "$authorization_header" \
  -H "$x_ms_date_h" \
  -H "$x_ms_version_h" \
  -H "Content-Length: 0" \
  -H "accept: application/json;odata=nometadata" \
 "https://${storage_account}.${table_store_url}/${table_name}"
在这种情况下,我需要将字符串的末尾“string_改为_符号”和卷曲的最后一行

如果我在末尾插入(PartitionKey='name',RowKey='Gabriel')”

得到如下两行:

string_to_sign = "$ {request_method} \ n \ n \ n $ request_date \ n $ {canonicalized_resource} (PartitionKey = 'name', RowKey = Gabriel)"

"https://${storage_account}.${table_store_url}/${table_name}(PartitionKey='nome',RowKey='Gabriel')"
它将只返回PartitionKey为“name”且Rowkey为“Gabriel”的实体

但正如我前面所说的,我必须只使用分区键。如果我将两行的末尾更改为(PartitionKey='name'),它将返回以下错误:

The number of keys specified in the URI does not match number of key properties for the resource
我尝试使用$filter选项,将两行的末尾更改为
()$filter=(PartitionKey%20ge%20'Name')
,但是在通过Printf时会发生错误

通过将
()$filter=(PartitionKey%%20ge%%20'Name')
,它通过了2%,但在请求时发生身份验证错误

Server failed to authenticate the request. Make sure the value of Authorization header is formed correctly including the signature
有人能帮我吗

我需要使用PartitionKey,因为在这些测试中,我使用的是我创建的一个表,并且我有用于测试的RowKey值,但是在我需要实现的地方,我没有访问RowKey的权限,我将传递PartitionKey的值,这是一个电话号码,以获得RowKey的结果,这是一个Id

使用了以下文档:


查询实体时,无需将
字符串更改为符号
,请参阅

查询字符串应包括问号和comp参数(例如,comp=metadata)。查询字符串上不应包括其他参数

如果要使用PartitionKey获取整个实体,请将url更改为($need encoding to%24)

或者,如果您只想检索RowKey,请在此之后追加
&%24select=RowKey


另外
-H“Content Length:0”
没有用,只需删除它。

非常感谢,Jerry!看到这段代码,我发现问题出在“$filter”部分,然后改为“%24filter”就可以了。
https://${storage_account}.${table_store_url}/${table_name}?%24filter=PartitionKey%20eq%20'YourPartitionKey'