我正在尝试使用 cli 获取我的产品的订阅 key 以及默认订阅 key 。我已经浏览了文档https://learn.microsoft.com/en-us/cli/azure/apim/api?view=azure-cli-latest ,但现在我没有看到任何命令来获取订阅 key 。
虽然我可以看到有 powershell 方式来获取它,但我们在 ubuntu 管道中运行任务,并且下面列出的命令在 Linux 代理中不起作用。它说 Set-AzContext 不是已知命令
$subscriptionId = "id"
$RG = "rg"
$service = "apim-name"
Set-AzContext -Subscription $subscriptionId
$apimContext = New-AzApiManagementContext -ResourceGroupName $RG -ServiceName $service
Get-AzApiManagementSubscriptionKey -Context $apimContext -SubscriptionId "master"
更新 我可以通过 DevOps 管道中的 Azure powershell 任务获取详细信息。如果 azure cli 中没有选项,我将使用它作为解决方法。
最佳答案
使用azrest
这是可能的:
APIMID=`az apim show -n apimname -g resourcegroup --query id -o tsv`
az rest --method post --uri ${APIMID}/subscriptions/test-subscription/listSecrets?api-version=2022-08-01 --query primaryKey -o tsv
其中 test-subscription
是订阅的名称。
关于azure - 使用 azure cli 获取 Azure API 管理订阅 key ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/69445513/