未找到指定标识符的实体,当在 Azure API Management 中应用策略于 API 操作时。

huangapple go评论57阅读模式
英文:

Entity with specified identifier not found when applying policy on API operation with Bicep in Azure API Management

问题

我想要将出站策略应用于我的API的某些操作。我使用一个Bicep文件来完成这个操作,但是我收到了以下错误信息:

"statusMessage": {
    "status": "Failed",
    "error": {
      "code": "ValidationError",
      "message": "指定的标识符对应的实体未找到"
    }
  }

这是策略的代码片段:

resource relationApiSym 'Microsoft.ApiManagement/service/apis@2022-08-01' existing = {
  name: relationsApi.name
  parent: apiManagementInstance
  resource operationRegisterId 'operations@2022-08-01' existing = {
    name: 'post-registerrelation-id'
    resource policyId 'policies@2022-08-01' = {
      name: 'policy'
      properties: {
        format: 'xml'
        value:'<policies>\r\n<inbound>\r\n<base />\r\n</inbound>\r\n<backend>\r\n<base />\r\n</backend>\r\n<outbound>\r\n<base />\r\n<choose>\r\n<when condition="@(context.Response.StatusCode == 200)">\r\n<set-body>@{var response = context.Response.Body.As<JObject>();foreach (var key in new [] {"RelatieId"}) {response.Property (key).Remove ();}return response.ToString();}\r\n</set-body>\r\n</when>\r\n</choose>\r\n</outbound>\r\n<on-error>\r\n<base />\r\n</on-error>\r\n</policies>'      
      }
    }
  }
}

我注意到操作的名称是'post-register-relation-id',但当我检查部署日志中的目标URL时,我注意到没有策略(尚未)。

英文:

I would like to apply an outbound policy to some of the operations of my API. I use a Bicep file to accomplish that but I get the following error:

&quot;statusMessage&quot;: {
        &quot;status&quot;: &quot;Failed&quot;,
        &quot;error&quot;: {
          &quot;code&quot;: &quot;ValidationError&quot;,
          &quot;message&quot;: &quot;Entity with specified identifier not found&quot;
        }
      }

This is the snippet for the policy:

resource relationApiSym &#39;Microsoft.ApiManagement/service/apis@2022-08-01&#39; existing = {
  name: relationsApi.name
  parent: apiManagementInstance
  resource operationRegisterId &#39;operations@2022-08-01&#39; existing = {
    name : &#39;post-registerrelation-id&#39;
    resource policyId &#39;policies@2022-08-01&#39; = {
      name: &#39;policy&#39;
      properties: {
        format: &#39;xml&#39;
        value:&#39;&lt;policies&gt;\r\n&lt;inbound&gt;\r\n&lt;base /&gt;\r\n&lt;/inbound&gt;\r\n&lt;backend&gt;\r\n&lt;base /&gt;\r\n&lt;/backend&gt;\r\n&lt;outbound&gt;\r\n&lt;base /&gt;\r\n&lt;choose&gt;\r\n&lt;when condition=&quot;@(context.Response.StatusCode == 200)&quot;&gt;\r\n&lt;set-body&gt;@{var response = context.Response.Body.As&amp;lt;JObject&amp;gt;();foreach (var key in new [] {&quot;RelatieId&quot;}) {response.Property (key).Remove ();}return response.ToString();}\r\n&lt;/set-body&gt;\r\n&lt;/when&gt;\r\n&lt;/choose&gt;\r\n&lt;/outbound&gt;\r\n&lt;on-error&gt;\r\n&lt;base /&gt;\r\n&lt;/on-error&gt;\r\n&lt;/policies&gt;&#39;      
      }
    }
  }
}

I see that the operation exisits with the name 'post-register-relation-id' but when i check the target url from the deploymentlog, I notice that there are no policies (yet)

未找到指定标识符的实体,当在 Azure API Management 中应用策略于 API 操作时。

答案1

得分: 0

我已经使用了您的代码,并进行了一些修改,它对我起作用。

这里 afreen-apimgmt-001 是 Azure API Management 实例名称,echo-api 是 API 名称,create-resource 是我想应用策略的操作名称。

请确保您所选取的操作名称是正确的,并且在 Azure API 管理门户中存在。

英文:

I have used your code with few modifications and it worked for me.

Here afreen-apimgmt-001 is the Azure API Management instance name, echo-api is the API name and create-resource is the operation name where I want to apply the policy.

Make sure, the operation name you have taken is correct and present in Azure API management portal.

未找到指定标识符的实体,当在 Azure API Management 中应用策略于 API 操作时。

Code-

resource relationApiSym &#39;Microsoft.ApiManagement/service/apis@2022-08-01&#39; existing = {
  name: &#39;afreen-apimgmt-001/echo-api&#39;
  resource operationRegisterId &#39;operations@2022-08-01&#39; existing = {
    name : &#39;create-resource&#39;
    resource policyId &#39;policies@2022-08-01&#39; = {
      name: &#39;policy&#39;
      properties: {
        format: &#39;xml&#39;
        value:&#39;&lt;policies&gt;\r\n&lt;inbound&gt;\r\n&lt;base /&gt;\r\n&lt;/inbound&gt;\r\n&lt;backend&gt;\r\n&lt;base /&gt;\r\n&lt;/backend&gt;\r\n&lt;outbound&gt;\r\n&lt;base /&gt;\r\n&lt;choose&gt;\r\n&lt;when condition=&quot;@(context.Response.StatusCode == 200)&quot;&gt;\r\n&lt;set-body&gt;@{var response = context.Response.Body.As&amp;lt;JObject&amp;gt;();foreach (var key in new [] {&quot;RelatieId&quot;}) {response.Property (key).Remove ();}return response.ToString();}\r\n&lt;/set-body&gt;\r\n&lt;/when&gt;\r\n&lt;/choose&gt;\r\n&lt;/outbound&gt;\r\n&lt;on-error&gt;\r\n&lt;base /&gt;\r\n&lt;/on-error&gt;\r\n&lt;/policies&gt;&#39;      
      }
    }
  }
}

Output-

未找到指定标识符的实体,当在 Azure API Management 中应用策略于 API 操作时。

huangapple
  • 本文由 发表于 2023年6月2日 14:50:22
  • 转载请务必保留本文链接:https://go.coder-hub.com/76387779.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定