azure-api-management - 具有 key 轮换功能的 Azure API 管理

标签 azure-api-management azure-keyvault azure-runbook

我正在使用 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/

相关文章:

azure - Swashbuckle 生成的 Swagger 在 Azure API 管理中创建重复的版本路径

azure - 我可以使用管理 azure api 进行 Azure APIM 分析吗

python - Azure KeyVault : get_secret() - Python TypeError: string indices must be integers

azure - 获取-AzStorageFileContent : Can not find your azure storage credential

c# - 使用另一个服务中的托管身份对服务调用者进行身份验证

c# - 使用azure API管理重定向到URL

c# - 无法从函数访问 Azure Key Vault - 返回禁止

azure - 使用 Terraform 为虚拟 secret 码创建 Key Vault secret

Azure Runbook 由于存储帐户防火墙而失败

Azure 自动化 - 无法删除-AzResourceLock