无论如何,要使用Python SDK获取azure Web应用程序(Azure Function应用程序)的ftpsState吗? [英] Is it anyway to get ftpsState of azure web app (Azure Function app) using Python SDK?

查看:75
本文介绍了无论如何,要使用Python SDK获取azure Web应用程序(Azure Function应用程序)的ftpsState吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题在于,使用python SDK时,我无法列出与Azure函数应用程序相关的所有配置信息.因此,使用python SDK get_configration()API时,其中不包含键ftpsState.所以我想在响应中列出该密钥.

The problem is that with the python SDK I am not able to list all config info related to Azure function app. So with python SDK get_configration() API in not containing a key ftpsState. So I want to list that key in my response.

我正在寻找可以解决我的问题的建议.

I am looking for a suggestion which can solve my problem.

我已经为Web应用程序设置了Azure客户端并调用了get_configuration()函数,但是在响应中,我没有得到必须依靠我的工作的领域.

I have setup azure client for web apps and calling the function get_configuration(), but in the response, I am not getting a field which I have to rely on my work.

我已参考的Python SDK参考.

Reference for Python SDK which I have referred. https://docs.microsoft.com/en-us/python/api/azure-mgmt-web/azure.mgmt.web.operations.web_apps_operations.webappsoperations?view=azure-python#get-configuration-resource-group-name--name--custom-headers-none--raw-false----operation-config-

我的答复是

[
  {
    'id': '/subscriptions/<mysubscription>/resourceGroups/fnf/providers/Microsoft.Web/sites/fnf/config/web',
    'type': 'Microsoft.Web/sites/config',
    'properties': {
      'managedPipelineMode': 'Integrated',
      'autoHealEnabled': False,
      'phpVersion': '5.6',
      'publishingUsername': '$fnf',
      'vnetName': '',
      'scmType': 'None',
      'detailedErrorLoggingEnabled': False,
      'linuxFxVersion': '',
      'experiments': {
        'rampUpRules': [

        ]
      },
      'loadBalancing': 'LeastRequests',
      'numberOfWorkers': 1,
      'cors': {
        'allowedOrigins': [
          'https://functions.azure.com',
          'https://functions-staging.azure.com',
          'https://functions-next.azure.com'
        ]
      },
      'http20Enabled': False,
      'nodeVersion': '',
      'webSocketsEnabled': True,
      'requestTracingEnabled': False,
      'alwaysOn': False,
      'logsDirectorySizeLimit': 35,
      'use32BitWorkerProcess': True,
      'netFrameworkVersion': 'v4.0',
      'minTlsVersion': '1.2',
      'virtualApplications': [
        {
          'preloadEnabled': False,
          'physicalPath': 'site\\wwwroot',
          'virtualPath': '/'
        }
      ],
      'pythonVersion': '',
      'remoteDebuggingVersion': 'VS2017',
      'localMySqlEnabled': False,
      'appCommandLine': '',
      'httpLoggingEnabled': False,
      'defaultDocuments': [
        'Default.htm',
        'Default.html',
        'Default.asp',
        'index.htm',
        'index.html',
        'iisstart.htm',
        'default.aspx',
        'index.php'
      ],
      'remoteDebuggingEnabled': False
    },
    'name': 'fnf'
  }
]

但是,如果我检查了基于Web的API并从我们那里获得了正确的响应,就调用了类似的API.

But If I check the web-based API and call similar API from we getting the proper response.

我的网络参考API: https://docs .microsoft.com/en-us/rest/api/appservice/webapps/getconfiguration

My web base reference API: https://docs.microsoft.com/en-us/rest/api/appservice/webapps/getconfiguration

及其回应

{
  "id": "/subscriptions/<mysubscription>/resourceGroups/fnf/providers/Microsoft.Web/sites/fnf/config/web",
  "name": "fnf",
  "type": "Microsoft.Web/sites/config",
  "location": "Central US",
  "properties": {
    "numberOfWorkers": 1,
    "defaultDocuments": [
      "Default.htm",
      "Default.html",
      "Default.asp",
      "index.htm",
      "index.html",
      "iisstart.htm",
      "default.aspx",
      "index.php"
    ],
    "netFrameworkVersion": "v4.0",
    "phpVersion": "5.6",
    "pythonVersion": "",
    "nodeVersion": "",
    "linuxFxVersion": "",
    "windowsFxVersion": null,
    "requestTracingEnabled": false,
    "remoteDebuggingEnabled": false,
    "remoteDebuggingVersion": "VS2017",
    "httpLoggingEnabled": false,
    "logsDirectorySizeLimit": 35,
    "detailedErrorLoggingEnabled": false,
    "publishingUsername": "$fnf",
    "publishingPassword": null,
    "appSettings": null,
    "metadata": null,
    "connectionStrings": null,
    "machineKey": null,
    "handlerMappings": null,
    "documentRoot": null,
    "scmType": "None",
    "use32BitWorkerProcess": true,
    "webSocketsEnabled": true,
    "alwaysOn": false,
    "javaVersion": null,
    "javaContainer": null,
    "javaContainerVersion": null,
    "appCommandLine": "",
    "managedPipelineMode": 0,
    "virtualApplications": [
      {
        "virtualPath": "/",
        "physicalPath": "site\\wwwroot",
        "preloadEnabled": false,
        "virtualDirectories": null
      }
    ],
    "winAuthAdminState": 0,
    "winAuthTenantState": 0,
    "customAppPoolIdentityAdminState": false,
    "customAppPoolIdentityTenantState": false,
    "runtimeADUser": null,
    "runtimeADUserPassword": null,
    "loadBalancing": 1,
    "routingRules": [],
    "experiments": {
      "rampUpRules": []
    },
    "limits": null,
    "autoHealEnabled": false,
    "autoHealRules": null,
    "tracingOptions": null,
    "vnetName": "",
    "siteAuthEnabled": true,
    "siteAuthSettings": {
      "enabled": null,
      "unauthenticatedClientAction": null,
      "tokenStoreEnabled": null,
      "allowedExternalRedirectUrls": null,
      "defaultProvider": null,
      "clientId": null,
      "clientSecret": null,
      "clientSecretCertificateThumbprint": null,
      "issuer": null,
      "allowedAudiences": null,
      "additionalLoginParams": null,
      "isAadAutoProvisioned": false,
      "googleClientId": null,
      "googleClientSecret": null,
      "googleOAuthScopes": null,
      "facebookAppId": null,
      "facebookAppSecret": null,
      "facebookOAuthScopes": null,
      "twitterConsumerKey": null,
      "twitterConsumerSecret": null,
      "microsoftAccountClientId": null,
      "microsoftAccountClientSecret": null,
      "microsoftAccountOAuthScopes": null
    },
    "cors": {
      "allowedOrigins": [
        "https://functions.azure.com",
        "https://functions-staging.azure.com",
        "https://functions-next.azure.com"
      ],
      "supportCredentials": false
    },
    "push": null,
    "apiDefinition": null,
    "apiManagementConfig": null,
    "autoSwapSlotName": null,
    "localMySqlEnabled": false,
    "managedServiceIdentityId": null,
    "xManagedServiceIdentityId": null,
    "ipSecurityRestrictions": null,
    "scmIpSecurityRestrictions": null,
    "scmIpSecurityRestrictionsUseMain": null,
    "http20Enabled": false,
    "minTlsVersion": "1.2",
    "ftpsState": "FtpsOnly",
    "reservedInstanceCount": 0,
    "preWarmedInstanceCount": null,
    "healthCheckPath": null
  }
}

self.my_client.web是使用python SDK为Web应用程序创建的客户端.

self.my_client.web is client created for the web app with python SDK.

def get_config(self, f_id):
    pf = p_id(f_id) #extract info in a dict
    cnf = self.my_client.web.web_apps.get_configuration(
            resource_group_name=pf['resource_group'],
            name=pf['resource_name'],
            subscription_id=pf.get('subscription')
    )
    return cnf

我期望输出键为"ftpsState".

I am expecting the output with the key "ftpsState".

[
  {
    'id': '/subscriptions/<mysubscription>/resourceGroups/fnf/providers/Microsoft.Web/sites/fnf/config/web',
    'type': 'Microsoft.Web/sites/config',
    'properties': {
      'managedPipelineMode': 'Integrated',
      'autoHealEnabled': False,
      'phpVersion': '5.6',
      'publishingUsername': '$fnf',
      'vnetName': '',
      'scmType': 'None',
      'detailedErrorLoggingEnabled': False,
      'linuxFxVersion': '',
      'experiments': {
        'rampUpRules': [

        ]
      },
      'loadBalancing': 'LeastRequests',
      'numberOfWorkers': 1,
      'cors': {
        'allowedOrigins': [
          'https://functions.azure.com',
          'https://functions-staging.azure.com',
          'https://functions-next.azure.com'
        ]
      },
      'http20Enabled': False,
      'ftpsState': 'FtpsOnly',
      'nodeVersion': '',
      'webSocketsEnabled': True,
      'requestTracingEnabled': False,
      'alwaysOn': False,
      'logsDirectorySizeLimit': 35,
      'use32BitWorkerProcess': True,
      'netFrameworkVersion': 'v4.0',
      'minTlsVersion': '1.2',
      'virtualApplications': [
        {
          'preloadEnabled': False,
          'physicalPath': 'site\\wwwroot',
          'virtualPath': '/'
        }
      ],
      'pythonVersion': '',
      'remoteDebuggingVersion': 'VS2017',
      'localMySqlEnabled': False,
      'appCommandLine': '',
      'httpLoggingEnabled': False,
      'defaultDocuments': [
        'Default.htm',
        'Default.html',
        'Default.asp',
        'index.htm',
        'index.html',
        'iisstart.htm',
        'default.aspx',
        'index.php'
      ],
      'remoteDebuggingEnabled': False
    },
    'name': 'fnf'
  }
]

推荐答案

我尝试成功重现您的问题,并且发现它是由当前软件包azure==4.0.0azure-mgmt-web==0.35.0不支持ftps_state属性引起的您可以通过pip install azurepip install azure-mgmt-web安装它们.您可以参考源代码

I tried to reproduce your issue successfully, and I found it was caused by the current packages azure==4.0.0 and azure-mgmt-web==0.35.0 not support the ftps_state attribute if you install them via pip install azure or pip install azure-mgmt-web. You can refer to the source code site_config_resource.py of azure_4.0.0 and its master version to discover it.

因此,首先,您需要通过pip卸载azure-sdk-for-python的所有软件包,如下所示.

So first, you need to uninstall all packages of azure-sdk-for-python via pip, as below.

pip freeze > packages_uninstalled_requirements.txt
pip uninstall -r packages_uninstalled_requirements.txt -y

然后,您必须必须从 azure-sdk-for-python安装软件包azure-mgmt-web. 源存储库,如下所示.

Then, you must have to install the package azure-mgmt-web from the azure-sdk-for-python source repo, as below.

git clone git://github.com/Azure/azure-sdk-for-python.git
cd azure-sdk-for-python
python setup.py install

cd sdk/appservice/azure-mgmt-web
python setup.py install

然后,运行我的示例代码并获得所需的结果,如下所示.

Then, run my sample code and get the result you want, as below.

from azure.common.credentials import ServicePrincipalCredentials
from azure.mgmt.web import WebSiteManagementClient

subscription_id = '<your subscription id>'
credentials = ServicePrincipalCredentials(
    client_id='<your client id>',
    secret='<your client secret>',
    tenant='<your tenant id>'
)

resource_group_name = '<your resource group name>'
name = '<your webapp or function name>'

client = WebSiteManagementClient(credentials, subscription_id)
conf = client.web_apps.get_configuration(resource_group_name, name)
print(conf.name, conf.ftps_state)

这篇关于无论如何,要使用Python SDK获取azure Web应用程序(Azure Function应用程序)的ftpsState吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆