如何以编程方式将现有SSL证书应用于Azure Web应用
我正在使用 Azure Fluent Management API 自动化我们的部署过程.到目前为止,我的问题很少.
I'm using the Azure Fluent Management API to automate our deployment process. Up until now, I've had minimal problems.
我们已经将SSL证书上载到Azure,并且可以通过Azure门户手动将它们绑定到网站.但是我找不到以编程方式执行此操作的机制.
We have SSL certificates already uploaded into Azure and can manually bind them to a web site through the Azure portal. But I can't find a mechanism for doing this programmatically.
The closest I can find is below and in the documentation here.
webApp.Update()
.DefineSslBinding()
.ForHostname(domainName)
.WithPfxCertificateToUpload(pfxFile, password)
.WithSniBasedSsl()
.Attach();
但是,这显然是在上传新证书,而不是使用现有证书.
ForHostName()
调用之后还有两个其他选项:
However, this is obviously uploading a new certificate, not using an existing one.
There are two other options after the ForHostName()
call:
WithExistingAppServiceCertificateOrder(certificateOrder)
和
WithNewStandardSslCertificateOrder(certificateOrderName)
但是我的理解是,这些与通过Azure/Microsoft购买证书有关.
But my understanding is that these are related to purchasing the certificates through Azure/Microsoft.
我也看不到REST API中的任何内容文档.
I also can't see anything in the REST API documentation.
那么,如何用代码将现有证书与Web应用程序关联起来?
So, how can I associate an existing certificate with a web app, in code?
Obviously this was not critical given I've only found an answer 9 months later.
无论如何,下面的答案是从提供的链接中复制的.
Anyhow, the answer below is copied from the link provided.
await azure
.WebApps
.Inner
.CreateOrUpdateHostNameBindingWithHttpMessagesAsync(
resourceGroupName,
webAppName,
domain,
new HostNameBindingInner(
azureResourceType: AzureResourceType.Website,
hostNameType: HostNameType.Verified,
customHostNameDnsRecordType: CustomHostNameDnsRecordType.CName,
sslState: SslState.SniEnabled,
thumbprint: thumbprint));