我正在尝试使用cli获取产品的订阅密钥以及默认订阅密钥。我已经浏览了文档https://learn.microsoft.com/en-us/cli/azure/apim/api?view=azure-cli-latest,但是现在我没有看到任何命令来获取订阅密钥。
虽然我可以看到有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中没有选项,我会使用这个作为解决方案。
使用az rest
是可能的:
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
为订阅的名称。
目前无法使用AZ CLI命令获取订阅密钥。使用PowerShell命令是正确的方法。如果有帮助的话,另一种获取订阅键的方法是使用Management API调用