0

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.

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.

Reference for Python SDK which I have referred. https://learn.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-

My response is

[
  {
    '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'
  }
]

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

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

and its response

{
  "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 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

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'
  }
]
  • You could try with the REST api,[Get Configuration](https://learn.microsoft.com/en-us/rest/api/appservice/webapps/getconfiguration) – George Chen Jun 19 '19 at 06:23
  • @GeorgeChen I do not want to use Rest API. I want to get that info with Python SDK since all code is running over the python SDK. – Kamlesh Hingwe Jun 19 '19 at 08:29

1 Answers1

0

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.

site_config_resource.py of azure 4.0.0 tag

enter image description here

site_config_resource.py of master branch

enter image description here

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

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)

enter image description here

Peter Pan
  • 23,476
  • 4
  • 25
  • 43