【问题标题】:Not able to generate SAS in Azure APIM using Microsoft sample无法使用 Microsoft 示例在 Azure APIM 中生成 SAS
【发布时间】:2021-03-18 06:49:46
【问题描述】:

有没有人按照下面的示例成功为 Azure APIM 中的 Blob 存储生成 SAS?

https://docs.microsoft.com/en-us/azure/api-management/policies/generate-shared-access-signature

已替换门户中的存储访问密钥(使用密钥 1 和密钥 2),但得到相同的结果。也尝试生成新密钥,但也没有用。

“表达式评估失败。给定的键不存在于 字典。\r\n 在 System.Collections.Generic.Dictionary`2.get_Item(TKey key)", "字典中没有给定的键。"

让像我这样的 azure-apim 初学者更加困惑的是 <set-variable name="resourcePath" value="TableName()" />,TableName() 是做什么的?

【问题讨论】:

    标签: azure azure-api-management azure-sas


    【解决方案1】:

    感谢所有试图提供帮助的人:Anton 和 Doris。

    失败的操作是这个块:

    <set-variable name="StringToSign" value="@{
                return string.Format(
                "GET\n\n\n\n\n{0}\n\n\n\n\n\n\n{1}\n{2}\n{3}",
                (string)context.Variables["Content-Type"],
                (string)context.Variables["x-ms-date"],
                (string)context.Variables["x-ms-version"],
                (string)context.Variables["CanonicalizedResource"]);
            }" />
    

    但是,在示例开始时,设置上下文变量时,缺少 x-ms-version。我添加了操作&lt;set-variable name="x-ms-version" value="2020-02-10" /&gt;,现在正在生成 SAS。

    也许它会帮助其他想要使用 azure 的人:)

    【讨论】:

    • 所以TableName() 它真的有效并且它的一些未记录的内置功能? (特定于 APIM)
    • 对不起@max3d,我到处搜索,但没有找到关于TableName()函数的描述。您能否更新您如何设置“resourcePath”变量并接受您的答案供其他人参考?
    • 感觉 TableName() 只是一个错字——我没有看到它被评估为表达式或调用。正如 Doris 建议的那样,我已将其替换为 containername:&lt;set-variable name="resourcePath" value="containername" /&gt; 在 rewrite-uri 中,指的是该变量:&lt;rewrite-uri template="@{return (string)context.Variables["resourcePath"];}" /&gt; 结果,对后端的调用正确形成:storageaccount.blob.core.windows.net/containername 签名不是虽然有效,但正在生成。这需要更多调查
    【解决方案2】:

    此示例为 Azure 存储帐户中的表生成 SAS 令牌。您可以将其修改为您要访问的资源,如下所示:

    <set-variable name="resourcePath" value="containername/blobname" />
    

    不要忘记更改 rewrite-uri 块。

    【讨论】:

    • 你知道TableName()是什么吗?如果 API 管理使用此代码保存策略,它看起来像 TableName() 一些内置函数.. idk
    • 感谢您的回复。是的,我一直在尝试将它用于 Blob。容器名称的值应该如您所描述的那样 - 仅容器名称,还是还包括顶级域 (.blob.core.windows.net)?无论如何,我会用你的例子 Doris Lv 重试,并更新帖子
    猜你喜欢
    • 2018-12-12
    • 2020-03-29
    • 2023-03-04
    • 1970-01-01
    • 2018-12-18
    • 2020-10-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多