共用方式為


ApiCenter生產版本插件

檢查應用程式中所使用的 API 是否為在指定的 Azure API 中心實例中註冊之 API 的生產版本。

命令提示字元的螢幕快照,其中顯示開發人員 Proxy 檢查記錄的 API 要求是否符合在 Azure API 中心註冊的生產版本 API。

外掛程式實例定義

{
  "name": "ApiCenterProductionVersionPlugin",
  "enabled": true,
  "pluginPath": "~appFolder/plugins/DevProxy.Plugins.dll",
  "configSection": "apiCenterProductionVersionPlugin"
}

組態範例

{
  "apiCenterProductionVersionPlugin": {
    "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.0.0/apicenterproductionversionplugin.schema.json",
    "subscriptionId": "aaaa0a0a-bb1b-cc2c-dd3d-eeeeee4e4e4e",
    "resourceGroupName": "resource-group-name",
    "serviceName": "apic-instance",
    "workspaceName": "default"
  }
}

組態屬性

財產 描述 違約
resourceGroupName Azure API 中心所在的資源群組名稱。 沒有
serviceName 開發 Proxy 應該用來檢查應用程式中使用的 API 是否已註冊的 Azure API 中心實例名稱。 沒有
subscriptionId Azure API 中心實例所在的 Azure 訂用帳戶標識碼。 沒有
workspace 要使用的 Azure API 中心工作區名稱。 default

命令行選項

沒有

言論

ApiCenterProductionVersionPlugin 外掛程式會檢查應用程式中所使用的 API 是否為在指定的 Azure API 中心實例中註冊之 API 的生產版本。 如果 API 符合非生產版本,外掛程式會顯示警告。

若要連線到 Azure API 中心,外掛程式會使用 Azure 認證(依此順序):

  • 環境
  • 工作負載身分識別
  • 受控識別
  • Visual Studio
  • Visual Studio Code
  • Azure 命令列介面 (Azure CLI)
  • Azure PowerShell
  • Azure 開發人員 CLI

如果外掛程式無法取得存取令牌來存取 Azure,它會顯示錯誤,而開發人員 Proxy 會停用它。 使用這些工具之一登入 Azure,然後重新啟動 Dev Proxy 以使用 ApiCenterProductionVersionPlugin 外掛程式。

如果您在 CI/CD 管線中使用開發 Proxy,您可以將 subscriptionIdresourceGroupNameserviceNameworkspaceName 屬性的值傳遞為環境變數。 若要使用環境變數,請使用 @前面加上值的名稱,例如:

{
  "apiCenterProductionVersionPlugin": {
    "$schema": "https://raw.githubusercontent.com/dotnet/dev-proxy/main/schemas/v1.0.0/apicenterproductionversionplugin.schema.json",
    "subscriptionId": "@AZURE_SUBSCRIPTION_ID",
    "resourceGroupName": "@AZURE_RESOURCE_GROUP_NAME",
    "serviceName": "@AZURE_APIC_INSTANCE_NAME",
    "workspaceName": "@AZURE_APIC_WORKSPACE_NAME"
  }
}

在此範例中,ApiCenterProductionVersionPlugin 外掛程式會將 subscriptionIdresourceGroupNameserviceNameworkspaceName 屬性分別設定為 AZURE_SUBSCRIPTION_IDAZURE_RESOURCE_GROUP_NAMEAZURE_APIC_INSTANCE_NAMEAZURE_APIC_WORKSPACE_NAME 環境變數的值。

後續步驟