[英]Azure WebApp - Multiple Custom Domains in single request
I'm trying to bulk upload custom domains to Azure WebApps (specifically the deployment slots).我正在尝试将自定义域批量上传到 Azure WebApps(特别是部署槽)。 I currently loop through with Azure CLI but it adds 15-20 minutes to CICD process.
我目前使用 Azure CLI 循环,但它增加了 CICD 过程 15-20 分钟。
I've also tried with ARM Templates but it reports a "conflict" during bulk upload.我也尝试过使用 ARM 模板,但它在批量上传期间报告“冲突”。 It requires a condition or dependency on the previous hostname which means it's still configuring the domains one by one.
它需要对先前主机名的条件或依赖,这意味着它仍在逐个配置域。
Does anyone know of a way to bulk configure?有谁知道批量配置的方法?
Powershell and Azure CLI Powershell 和 Azure CLI
#Set Host Names and SSL
$WebApp_HostNames = Import-Csv "$(ConfigFiles_Path)\$WebApp-Hostnames.csv"
if ($null -ne $WebApp_HostNames) {
foreach ($HostName in $WebApp_HostNames) {
az webapp config hostname add --hostname $HostName.Name --resource-group "$(ResourceGroup)" --webapp-name "$WebApp" --slot "$WebApp$(WebApp_Slot_Suffix)"
az webapp config ssl bind --certificate-thumbprint $HostName.Thumbprint --ssl-type SNI --resource-group "$(ResourceGroup)" --name "$WebApp" --slot "$WebApp$(WebApp_Slot_Suffix)"
}
}
EDIT : Got it!编辑:明白了! Will write out the process and provide the answer here for future reference
将写出过程并在此处提供答案以供将来参考
TL;DR TL;博士
I've included the entire Powershell script here including getting your auth token and pushing the json config.我在这里包含了整个 Powershell 脚本,包括获取您的身份验证令牌和推送 json 配置。 There's nothing else you'll need to bulk upload.
您无需批量上传其他任何内容。
Hope this helps希望这可以帮助
# Get auth token from existing Context
$currentAzureContext = Get-AzContext
$azProfile = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile
$profileClient = New-Object Microsoft.Azure.Commands.ResourceManager.Common.RMProfileClient($azProfile)
$token = $profileClient.AcquireAccessToken($currentAzureContext.Tenant.TenantId)
# Authorisation Header
$authHeader = @{
'Content-Type' = 'application/json'
'Authorization' = 'Bearer ' + ($token.AccessToken)
}
# Request URL
$url = "https://management.azure.com/subscriptions/{SubscriptionID}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Web/sites/{WebAppName}/slots/{WebAppSlotName}?api-version=2018-11-01"
# JSON body
$body = '
{
"id":"/subscriptions/{SubscriptionID}/resourceGroups/{ResourceGroupName}/providers/Microsoft.Web/sites/{WebAppName}/slots/{WebAppSlotName}",
"kind":"app",
"location":"Australia East",
"name":"{WebAppName} or {WebAppSlotName}",
"type":"Microsoft.Web/sites/slots", or "Microsoft.Web/sites",
"properties":{
"hostNameSslStates":[
{
"name":"sub1.domain.com",
"sslState":"SniEnabled",
"thumbprint":"IUAHSIUHASD78ASDIUABFKASF79ASUASD8ASFHOANKSL",
"toUpdate":true,
"hostType":"Standard"
},
{
"name":"sub2.domain.com",
"sslState":"SniEnabled",
"thumbprint":"FHISGF8A7SFG9SUGBSA7G9ASHIAOSHDF08ASHDF08AS",
"toUpdate":true,
"hostType":"Standard"
}
],
"hostNames":[
"sub1.domain.com",
"sub2.domain.com",
"{Default WebApp Domain}"
]
}
}
'
# Push to Azure
Invoke-RestMethod -Uri $url -Body $body -Method PUT -Headers $authHeader
Method方法
In the end I just pressed F12 to capture the traffic in the Networking tab in browser developer tools.最后,我只是按 F12 来捕获浏览器开发人员工具中 Networking 选项卡中的流量。
When clicking "Add Binding" in portal there's one PUT
request which has the payload required to replicate.在门户中单击“添加绑定”时,会出现一个
PUT
请求,其中包含复制所需的有效负载。 I found that the request contains ALL of the Custom Domains and SSL bindings for bulk upload, not just the change.我发现该请求包含用于批量上传的所有自定义域和 SSL 绑定,而不仅仅是更改。 The only trick here was to set the
toUpdate
property to true
for all domains.这里唯一的技巧是将所有域的
toUpdate
属性设置为true
。 I stripped out any null
and notConfigured
values to keep it tidier.我删除了所有
null
和notConfigured
值以使其更整洁。
My next progression for this is to fetch my hostnames and certificate thumbprints and dynamically build the body before pushing the change to Azure.我的下一个进展是获取我的主机名和证书指纹并在将更改推送到 Azure 之前动态构建主体。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.