Microsoft Azure 文档中有一篇文章介绍了如何 Add a TLS/SSL certificate in Azure App Service来自门户网站。该页面链接到 how to do the same thing from using the Azure cli 上的文档.
我的目标是做同样的事情,但使用原生 Python。我一直在查看 azure.mgmt.web
的文档包,包括 WebSiteManagementClient
class 的文档.
问题:有没有办法使用 native Python 上传 PKCS12 私钥证书并将其绑定(bind)到 Azure Web 应用程序?我愿意考虑替代方案,例如上传公钥证书或使用 subprocess
module 调用 Azure CLI 工具.
这是我到目前为止的代码:
from azure.mgmt.web import WebSiteManagementClient
from azure.identity import ClientSecretCredential
# Assume client_id, secret, tenant, resource_group, web_app_name are
# appropriately declared and instatiated
credentials = ClientSecretCredential(client_id=client_id,
client_secret=secret,
tenant_id=tenant)
with WebSiteManagementClient(credentials, subscription_id) as mng:
web_app = mng.web_apps.get(resource_group, web_app_name)
app_config = mng.web_apps.get_configuration(resource_group, web_app_name)
# TODO: upload Private Key (PKCS12) here
最佳答案
- Azure cli 确实提供了将证书上传到应用服务的命令。 命令是:
az webapp config ssl upload
- 现在我们可以使用子进程来执行命令。首先,我们将设置订阅,然后我们将执行上传命令
import subprocess
subprocess.call(' az account set -s <subscription name >', shell=True)
subprocess.call(' az webapp config ssl upload --certificate-file <file path of certificate> --certificate-password {certificate-password} --name <name of app> --resource-group <name of resource group>', shell=True)
引用以下documentation在 azure cli 命令上
关于python - 如何使用 Python 将自定义 TLS/SSL 证书绑定(bind)到 Azure 应用服务应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73198310/