【问题标题】:Update azure api inbound policy from powershell从 powershell 更新 azure api 入站策略
【发布时间】:2021-04-12 14:22:52
【问题描述】:

首先感谢您对此进行调查。

我需要从 Powershell 更新由 Azuremanagementservice 管理的 API 的入站策略。为此,我尝试从 powershell 访问 API,不幸的是没有任何进展。

我正在通过 powershell 寻找什么 a) AzuremanagementService下的访问API b) 更新入站操作策略

谢谢

【问题讨论】:

  • 怎么样?你的问题解决了吗?

标签: azure azure-powershell policy inbound


【解决方案1】:
【解决方案2】:

如果您想通过 Azure PowerShell 设置策略,请尝试以下代码(为演示添加根级别入站 IP 阻止策略):

$newPolicy = '<policies>
                <inbound>
                    <ip-filter action="forbid">
                        <address-range from="192.168.0.1" to="192.168.0.2" />
                    </ip-filter>
                </inbound>
                <backend>
                    <forward-request />
                </backend>
                <outbound />
                <on-error />
             </policies>'

$apim_context = New-AzApiManagementContext -ResourceGroupName "<resource group name>" -ServiceName "<API management service name>"

Set-AzApiManagementPolicy -Context $apim_context  -Policy $newPolicy

结果:

有关Set-AzApiManagementPolicy操作的更多信息,请参阅this reference doc

更新

如果你想在API级别修改策略,你需要使用下面的命令来获取所有ApiId

Get-AzApiManagementApi -Context $apim_context | Select-Object Name,ApiId

我将 ApiID 指定为“echo-api”:

Set-AzApiManagementPolicy -Context $apim_context  -Policy $newPolicy -ApiId 'echo-api'

结果:

有关使用 PowerShell 设置策略的更多信息,请参阅here

【讨论】:

  • 感谢您的回复。我希望更改该 API 管理服务下的特定 API。
  • @user14846304,我已经上传了关于如何修改 API 级别策略的答案。如果我的帖子解决了您的问题,请您舔一下我的答案旁边的标记图标以接受它吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-02
  • 2021-10-24
  • 1970-01-01
  • 2021-06-08
  • 1970-01-01
  • 2019-10-08
  • 2022-11-02
相关资源
最近更新 更多