从PowerShell更新Azure API入站策略 [英] Update azure api inbound policy from powershell

查看:0
本文介绍了从PowerShell更新Azure API入站策略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

我需要从PowerShell更新由AzureManagementService管理的API的入站策略。为此,我尝试从PowerShell访问该API,但遗憾的是没有任何进展。

我通过PowerShell寻找的内容 A)在AzureManagementService下访问API B)更新入站运营策略

谢谢

推荐答案

如果要通过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

这篇关于从PowerShell更新Azure API入站策略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆