使用APIOPS如何将命名值添加到policies.xml中

问题描述 投票:0回答:1

我现在正在与 https://github.com/Azure/apiops 在项目上与 APIM 资源交互。 这意味着我需要处理的任何 API 都会通过 apiops 存储库。 我们有文件

configuration.<env>.yaml
其中包含类似的内容:

apimServiceName: nameofapimresource
namedValues:
  - name: azureTenantNameId
    properties:
      value: "xxx"
  - name: azureEnvironmentId
    properties:
      value: "dev"

从文档来看,这些变量应该可以使用括号来工作和解析。例如:

{{azureTenantNameId}}
不过,如果我将其应用于policy.xml,它不会转换为任何值。

我们应该如何使用 apiops 中的变量?

顺便说一句,这些变量使用

Specifications.json
文件中的括号来工作

azure azure-api-management apim
1个回答
0
投票

我们也在使用 ApiOps,并且有一个类似的场景,我们需要覆盖 API 的 Web 服务 URL,我们使用命名值实现了这一点,如下所示:

  1. 在我们的测试 APIM 实例中创建一个命名值,例如ApiServiceUrl
  2. 添加了后端策略以使用新创建的ApiServiceUrl
  3. 更新了 configuration.{env}.yaml 文件以在某些环境下覆盖 ApiServiceUrl

然后,我们运行 ApiOp 的提取器管道,因此这些更改保存在 ApiOp 存储库的源代码管理中。

以下是我们的工件文件夹中致力于实现此目的的相关文件:

1。创建命名值

namedValueInformation.json(位于命名值文件夹内的 ApiServiceUrl 文件夹中)

{
  "properties": {
    "displayName": "ApiServiceUrl",
    "secret": false,
    "tags": [],
    "value": "https://our-api-url.azurewebsites.net"
  }
}

2。后端政策

policy.xml(在相关 API 的文件夹中)

<policies>
    <!-- Throttle, authorize, validate, cache, or transform the requests -->
    <inbound>
        <base />
        <set-backend-service base-url="{{ApiServiceUrl}}" />
    </inbound>
    <!-- Control if and how the requests are forwarded to services  -->
    <backend>
        <base />
    </backend>
    <!-- Customize the responses -->
    <outbound>
        <base />
    </outbound>
    <!-- Handle exceptions and customize error responses  -->
    <on-error>
        <base />
    </on-error>
</policies>

3.配置.{env}.yaml

配置.quality.yaml

apimServiceName: our-quality-apim-service
namedValues:
  - name: ApiServiceUrl
    properties:
      displayName: ApiServiceUrl
      value: https://our-quality-api-app.azurewebsites.net
loggers:
diagnostics:
backends:
apis:
© www.soinside.com 2019 - 2024. All rights reserved.