Azure ARM模板API管理部署策略内容
我正在尝试使用ARM模板部署我的API管理服务,并使除policyContent之外的所有内容都正常工作。基本上,它希望policyContent作为“策略的Json转义Xml编码内容”。这很难维护,并且试图找到一种方法来获取Xml文件并将内容注入到这个字符串中,或者找到更好的方法。我不想写一个程序来维护这些字符串,因为它感觉不应该这么复杂Azure ARM模板API管理部署策略内容,azure,azure-resource-manager,azure-api-management,azure-resource-group,Azure,Azure Resource Manager,Azure Api Management,Azure Resource Group,我正在尝试使用ARM模板部署我的API管理服务,并使除policyContent之外的所有内容都正常工作。基本上,它希望policyContent作为“策略的Json转义Xml编码内容”。这很难维护,并且试图找到一种方法来获取Xml文件并将内容注入到这个字符串中,或者找到更好的方法。我不想写一个程序来维护这些字符串,因为它感觉不应该这么复杂 { “名称”:“政策”, “类型”:“Microsoft.ApiManagement/service/API/Policys”, “apiVersion
{
“名称”:“政策”,
“类型”:“Microsoft.ApiManagement/service/API/Policys”,
“apiVersion”:“2017-03-01”,
“财产”:{
“policyContent”:“字符串”
}
}
我能想到的唯一一件事(因为arm模板中没有任何本机内容可以帮助您)是从文件中读取输入并将其转换为JSON:
$xml = (Get-Content file -Raw).ToString()
($xml | ConvertTo-Json -Compress) -replace '\\u003c','<' ) -replace '\\u003e','>'
$xml=(获取内容文件-Raw).ToString()
($xml | ConvertTo Json-Compress)-替换“\\u003c”
不需要将这些Unicode替换回
,它就可以工作,不知道。您可以将策略维护到XML文件中,并像这样引用它:
{
"apiVersion": "2018-01-01",
"name": "policy",
"type": "Microsoft.ApiManagement/service/policies",
"properties": {
"policyContent": "[concat(parameters('repoBaseUrl'), '/policy.xml')]",
"contentFormat": "rawxml-link"
},
"dependsOn": [
"[resourceId('Microsoft.ApiManagement/service/', parameters('ApimServiceName'))]"
]
}
<policies>
<inbound>
<rate-limit calls="3" renewal-period="10" />
<base />
</inbound>
<outbound>
<base />
</outbound>
<backend>
<base />
</backend>
<on-error>
<base />
</on-error>
</policies>
您的policy.xml
文件必须在线可用,并且如下所示:
{
"apiVersion": "2018-01-01",
"name": "policy",
"type": "Microsoft.ApiManagement/service/policies",
"properties": {
"policyContent": "[concat(parameters('repoBaseUrl'), '/policy.xml')]",
"contentFormat": "rawxml-link"
},
"dependsOn": [
"[resourceId('Microsoft.ApiManagement/service/', parameters('ApimServiceName'))]"
]
}
<policies>
<inbound>
<rate-limit calls="3" renewal-period="10" />
<base />
</inbound>
<outbound>
<base />
</outbound>
<backend>
<base />
</backend>
<on-error>
<base />
</on-error>
</policies>
是的,我写了一个powershell来做类似的事情。没有一个好的方法来正确加载xml,这让人感觉很不舒服。谢谢。我希望有人能反驳我,但我恐怕现在就是这样:(我们同意这是丑陋和痛苦的。但是,我们需要生活在只使用JSON的ARM模板的约束下。我们正在计划编写工具,这将使从OpenAPI描述和策略文档创建部署模板变得更容易。请容忍我们,我们正在努力让它变得更好。这看起来很简单很好。我在这里找到了相关文档:。