我正在使用 KeyVault 存储 Ocp-Apim-Subscription-Key
。应用程序从 KeyVault 获取此 key 并成功向 API 管理发出请求。
但现在,我想在 Runbook 中经常使用 powershell 脚本轮换此 Ocp-Apim-Subscription-Key
。我找不到通过 powershell 重新生成 Ocp-Apim-Subscription-Key
的方法。这可能吗 ?如果有其他选项可以轮换此 key ,请告诉我。
最佳答案
# Get API Management Services information and set context
$ApiManagements = Get-AzApiManagement
foreach ($ApiManagement in $ApiManagements)
{
$ApiManagementContext = New-AzApiManagementContext -ResourceId $ApiManagement.Id
# Get all API Management Subscriptions
$ApiManagementSubscriptions = Get-AzApiManagementSubscription -Context $ApiManagementContext
foreach ($ApiManagementSubscription in $ApiManagementSubscriptions)
{
# Update the Keys
$PrimaryKey = (New-Guid) -replace '-',''
$SecondaryKey = (New-Guid) -replace '-',''
Set-AzApiManagementSubscription -Context $ApiManagementContext -SubscriptionId $ApiManagementSubscription.SubscriptionId -PrimaryKey $PrimaryKey `
-SecondaryKey $SecondaryKey -State Active
}
}
关于azure-api-management - 具有 key 轮换功能的 Azure API 管理,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51593055/