Websocket的APIM策略验证错误



我试图通过ARM模板将策略添加到Azure API管理中的websocket端点,但我得到错误

"error": {
"code": "ValidationError",
"message": "Not allowed at 'Api' scope for 'WEBSOCKET' api type"
}

我可以手动添加策略,但我无法通过ARM模板将策略添加到web套接字。我尝试了同样的策略到web api,它成功了。

for just policy的ARM模板我想看看它是否可以在websocket配置后部署:

{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"ApimServiceName": {
"type": "String"
},
"policypath": {
"type": "String"
},
"Environment": {
"type": "String"
},
},
"variables": {
"env": "[concat('test-', parameters('Environment'))]",
"svc": "[concat('testsvc-', parameters('Environment'))]"
},
"resources": [
{
"type": "Microsoft.ApiManagement/service/apis/policies",
"apiVersion": "2022-04-01-preview",
"name": "[concat(parameters('ApimServiceName'), '/', variables('env'), '/policy')]",
"dependsOn": [],
"properties": {
"value": "[parameters('policypath')]",
"format": "rawxml-link"
}
}
]
}

我用来部署websocket和策略的整个arm模板在这里(我试图直接添加策略,而不是为策略添加sas链接)。

我能够找出一个解决方法,当我直接将策略添加到操作时,它就工作了。即使这样,我也必须直接在同一文件中编写策略,而提供SAS文件的arm模板方式不起作用。以下是当前版本的代码。

{
"properties": {
"value": "<!--rn    IMPORTANT:rn    - Policy elements can appear only within the <inbound>, <outbound>, <backend> section elements.rn    - To apply a policy to the incoming request (before it is forwarded to the backend service), place a corresponding policy element within the <inbound> section element.rn    - To apply a policy to the outgoing response (before it is sent back to the caller), place a corresponding policy element within the <outbound> section element.rn    - To add a policy, place the cursor at the desired insertion point and select a policy from the sidebar.rn    - To remove a policy, delete the corresponding policy statement from the policy document.rn    - Position the <base> element within a section element to inherit all policies from the corresponding section element in the enclosing scope.rn    - Remove the <base> element to prevent inheriting policies from the corresponding section element in the enclosing scope.rn    - Policies are applied in the order of their appearance, from the top down.rn    - Comments within policy elements are not supported and may disappear. Place your comments between policy elements or at a higher level scope.rn-->rn<policies>rn  <inbound>rn    <base />rn  </inbound>rn  <backend>rn    <retry condition="@(context.Response.StatusCode &gt;= 400)" count="2" interval="1" first-fast-retry="true">rn      <choose>rn        <when condition="@(context.Response != null &amp;&amp; context.Response.StatusCode &gt;= 400)">rn          <set-backend-service base-url="wss://" />rn        </when>rn        <otherwise />rn      </choose>rn      <forward-request />rn    </retry>rn  </backend>rn  <outbound>rn    <base />rn  </outbound>rn  <on-error>rn    <base />rn  </on-error>rn</policies>",
"format": "xml"
},
"type": "Microsoft.ApiManagement/service/apis/operations/policies",
"apiVersion": "2022-04-01-preview",
"name": "[concat(parameters('ApimServiceName'), '/', variables('env'), '/onHandshake/policy')]",
"dependsOn": [
"[resourceId('Microsoft.ApiManagement/service/apis', parameters('ApimServiceName'), variables('env'))]"
]
},

最新更新