gpt4 book ai didi

azure - 如何使用 Powershell 在 Azure API 管理中禁用订阅 key

转载 作者:行者123 更新时间:2023-12-02 06:44:02 28 4
gpt4 key购买 nike

我们正在使用 Azure API 管理和 Powershell 通过脚本导入门户上的配置,但是每当导入 API 时,都会启用门户中的“需要订阅”检查(API 需要订阅 key )。目前我们还没有在 API 上使用订阅功能,因此我们需要在导入时禁用此功能。我们使用 Import-AzApiManagementApiSet-AzApiManagementApi 以及以下代码:

Set-AzApiManagementApi -ApiId $apiId -Context $context -Protocols @('https') -ServiceUrl $serviceBase$path -Name $api.Name
Set-AzApiManagementPolicy -Context $context -ApiId $apiId -PolicyFilePath "$pwd/src/private/security_policy.xml"

我们还没有在 documentation 中找到无需此检查即可导入 API 的方式。是否有任何脚本可以通过 powershell 禁用此功能?

最佳答案

对此进行快速补充。以下 Powershell 命令将 API 的“需要订阅”属性设置为 false。但需要注意的是:这目前不适用于 Azure DevOps 管道。管道将声明任务已成功运行,如果您在管道中运行 $api 的 echo,它将显示 api 具有 SubscriptionRequired : False。但是,如果你去检查Azure中的api,它仍然会被设置为True(默认行为)。

# get context
$apimContext = New-AzApiManagementContext -ResourceGroupName "targetResourceGroup" -ServiceName "targetApimInstance"
$api = Get-AzApiManagementApi -Context $apimContext -Name "Name of Api"

# set subscriptionRequired to false
$api.SubscriptionRequired=$false

关于azure - 如何使用 Powershell 在 Azure API 管理中禁用订阅 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56081563/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com