在Azure API管理中对使用Bicep的API操作应用策略时未找到具有指定标识符的实体

bpzcxfmw  于 2023-06-06  发布在  其他
关注(0)|答案(1)|浏览(140)

我想对API的一些操作应用出站策略。我使用二头肌文件来完成,但我得到以下错误:

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

以下是策略的代码片段:

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&lt;JObject&gt;();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'的名称存在,但当我从deploymentlog检查目标URL时,我注意到没有策略(尚未)

thtygnil

thtygnil1#

我用你的代码与一些修改,它为我工作。
这里,afreen-apimgmt-001是Azure API管理示例名称,echo-api是API名称,create-resource是我要应用策略的操作名称。

请确保您采用的操作名称正确,并且存在于Azure API管理门户中。

编码-

resource relationApiSym 'Microsoft.ApiManagement/service/apis@2022-08-01' existing = {
  name: 'afreen-apimgmt-001/echo-api'
  resource operationRegisterId 'operations@2022-08-01' existing = {
    name : 'create-resource'
    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&lt;JObject&gt;();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>'      
      }
    }
  }
}

输出-

相关问题