使用管道应用API策略

发布于 2025-02-05 01:57:14 字数 114 浏览 4 评论 0原文

问候大家!

我正在尝试将外部API部署到APIM,但是我不确定如何部署我创建的XML文件。

我当时认为也许使用CLI可能是可能的,但是我找不到任何东西。

有人有任何想法吗?

Greeting everyone!

I'm trying to deploy an external api to an APIM, however I'm not sure how I could deploy the policies xml file that I created.

I was thinking maybe this could be possible using CLI, however I can't find anything.

Anyone has any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青衫儰鉨ミ守葔 2025-02-12 01:57:14

您还不能通过CLI做到这一点。您可以使用PowerShell脚本。在这里,我从Inline XML中获取它,但是您可以使用XML从存储库中做类似的事情。

- task: AzurePowerShell@5
displayName: "Add API policy in APIM"
inputs:
    azureSubscription: 'YourSubscription'
    ScriptType: 'InlineScript'
    Inline: |
    Install-Module Az.ApiManagement -Scope CurrentUser -Force
    Import-Module Az.ApiManagement -Force
    $PolicyString = "<policies>
        <inbound>
            <base />
            <authentication-certificate thumbprint=`"$(certificateThumbprint)`" />
        </inbound>
        <backend>
            <base />
        </backend>
        <outbound>
            <base />
        </outbound>
        <on-error>
            <base />
        </on-error>
    </policies>"
    $apimContext = New-AzApiManagementContext -ResourceGroupName $(apimResourceGroup) -ServiceName $(apimPortal)
    Set-AzApiManagementPolicy -Context $apimContext -ApiId $(apimRestApiId) -Policy $PolicyString
    azurePowerShellVersion: 'LatestVersion'

You cannot do this through the CLI yet. You can use a powershell script instead. Here I take it from inline xml but you can do a similar thing with a xml from your repo.

- task: AzurePowerShell@5
displayName: "Add API policy in APIM"
inputs:
    azureSubscription: 'YourSubscription'
    ScriptType: 'InlineScript'
    Inline: |
    Install-Module Az.ApiManagement -Scope CurrentUser -Force
    Import-Module Az.ApiManagement -Force
    $PolicyString = "<policies>
        <inbound>
            <base />
            <authentication-certificate thumbprint=`"$(certificateThumbprint)`" />
        </inbound>
        <backend>
            <base />
        </backend>
        <outbound>
            <base />
        </outbound>
        <on-error>
            <base />
        </on-error>
    </policies>"
    $apimContext = New-AzApiManagementContext -ResourceGroupName $(apimResourceGroup) -ServiceName $(apimPortal)
    Set-AzApiManagementPolicy -Context $apimContext -ApiId $(apimRestApiId) -Policy $PolicyString
    azurePowerShellVersion: 'LatestVersion'
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文