python - 如何使用 Python 将自定义 TLS/SSL 证书绑定(bind)到 Azure 应用服务应用程序?

标签 python azure ssl azure-web-app-service pkcs#12

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/

相关文章:

python - 使用 API key 从 Flask RESTful API 获取

c# - 从代码部署 Azure 函数 (c#)

azure - 在 Flutter 中从 Azure Cosmos DB 获取数据?

php - 配置不允许连接到 http ://packagist. org/packages.json

python - C9 上的第一个 python 应用程序出现错误

python - PyQt lineEdit on textEdited 信号值在函数调用后丢失

azure - 如何使用 contains 将一个数组的属性值与另一个数组逻辑应用表达式进行比较?

python - 直接替换 `urllib2.urlopen` 进行证书验证

java - 在 spring rest Api 中启用 SSL (HTTPS)

python - 如果 header=None,则使用 pandas 确定 csv 文件中的标题