We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Switch to using Node 8.9 as the default version for az webapp new


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/webapp/azext_webapp/custom.py`
Content:
```
1 # --------------------------------------------------------------------------------------------
2 # Copyright (c) Microsoft Corporation. All rights reserved.
3 # Licensed under the MIT License. See License.txt in the project root for license information.
4 # --------------------------------------------------------------------------------------------
5 
6 from __future__ import print_function
7 from knack.log import get_logger
8 
9 from azure.mgmt.web.models import (AppServicePlan, SkuDescription)
10 
11 from azure.cli.command_modules.appservice.custom import (
12     enable_zip_deploy,
13     create_webapp,
14     update_app_settings,
15     _get_site_credential,
16     _get_scm_url,
17     _get_sku_name)
18 
19 from .create_util import (
20     zip_contents_from_dir,
21     get_runtime_version_details,
22     create_resource_group,
23     check_resource_group_exists,
24     check_resource_group_supports_os,
25     check_if_asp_exists,
26     check_app_exists,
27     get_lang_from_content,
28     web_client_factory
29 )
30 
31 from ._constants import (NODE_RUNTIME_NAME, OS_DEFAULT)
32 
33 logger = get_logger(__name__)
34 
35 # pylint:disable=no-member,too-many-lines,too-many-locals,too-many-statements
36 
37 
38 def create_deploy_webapp(cmd, name, location=None, dryrun=False):
39     import os
40     import json
41 
42     client = web_client_factory(cmd.cli_ctx)
43     # the code to deploy is expected to be the current directory the command is running from
44     src_dir = os.getcwd()
45 
46     # if dir is empty, show a message in dry run
47     do_deployment = False if os.listdir(src_dir) == [] else True
48 
49     # determine the details for app to be created from src contents
50     lang_details = get_lang_from_content(src_dir)
51     # we support E2E create and deploy for Node & dotnetcore, any other stack, set defaults for os & runtime
52     # and skip deployment
53     if lang_details['language'] is None:
54         do_deployment = False
55         sku = 'F1'
56         os_val = OS_DEFAULT
57         detected_version = '-'
58         runtime_version = '-'
59     else:
60         sku = lang_details.get("default_sku")
61         language = lang_details.get("language")
62         os_val = "Linux" if language.lower() == NODE_RUNTIME_NAME else OS_DEFAULT
63         # detect the version
64         data = get_runtime_version_details(lang_details.get('file_loc'), language)
65         version_used_create = data.get('to_create')
66         detected_version = data.get('detected')
67         runtime_version = "{}|{}".format(language, version_used_create)
68 
69     if location is None:
70         locs = client.list_geo_regions(sku, True)
71         available_locs = []
72         for loc in locs:
73             available_locs.append(loc.geo_region_name)
74         location = available_locs[0]
75     # Remove spaces from the location string, incase the GeoRegion string is used
76     loc_name = location.replace(" ", "")
77     full_sku = _get_sku_name(sku)
78 
79     is_linux = True if os_val == 'Linux' else False
80 
81     asp = "appsvc_asp_{}_{}".format(os_val, loc_name)
82     rg_name = "appsvc_rg_{}_{}".format(os_val, loc_name)
83 
84     str_no_contents_warn = ""
85     if not do_deployment:
86         str_no_contents_warn = "[Empty directory, no deployment will be triggered]"
87 
88     # Resource group: check if default RG is set
89     default_rg = cmd.cli_ctx.config.get('defaults', 'group', fallback=None)
90     if default_rg and check_resource_group_supports_os(cmd, default_rg, location, is_linux):
91         rg_name = default_rg
92         rg_mssg = "[Using default Resource group]"
93     else:
94         rg_mssg = ""
95 
96     src_path = "{} {}".format(src_dir.replace("\\", "\\\\"), str_no_contents_warn)
97     rg_str = "{} {}".format(rg_name, rg_mssg)
98 
99     dry_run_str = r""" {
100             "name" : "%s",
101             "serverfarm" : "%s",
102             "resourcegroup" : "%s",
103             "sku": "%s",
104             "os": "%s",
105             "location" : "%s",
106             "src_path" : "%s",
107             "version_detected": "%s",
108             "version_to_create": "%s"
109             }
110             """ % (name, asp, rg_str, full_sku, os_val, location, src_path,
111                    detected_version, runtime_version)
112 
113     create_json = json.dumps(json.loads(dry_run_str), indent=4, sort_keys=True)
114     if dryrun:
115         logger.warning("Web app will be created with the below configuration,re-run command "
116                        "without the --dryrun flag to create & deploy a new app")
117         logger.warning(create_json)
118         return None
119 
120     # create RG if the RG doesn't already exist
121     if not check_resource_group_exists(cmd, rg_name):
122         logger.warning("Creating Resource group '%s' ...", rg_name)
123         create_resource_group(cmd, rg_name, location)
124         logger.warning("Resource group creation complete")
125     else:
126         logger.warning("Resource group '%s' already exists.", rg_name)
127 
128     # create asp
129     if not check_if_asp_exists(cmd, rg_name, asp):
130         logger.warning("Creating App service plan '%s' ...", asp)
131         sku_def = SkuDescription(tier=full_sku, name=sku, capacity=(1 if is_linux else None))
132         plan_def = AppServicePlan(loc_name, app_service_plan_name=asp,
133                                   sku=sku_def, reserved=(is_linux or None))
134         client.app_service_plans.create_or_update(rg_name, asp, plan_def)
135         logger.warning("App service plan creation complete")
136     else:
137         logger.warning("App service plan '%s' already exists.", asp)
138 
139     # create the app
140     if not check_app_exists(cmd, rg_name, name):
141         logger.warning("Creating app '%s' ....", name)
142         create_webapp(cmd, rg_name, name, asp, runtime_version if is_linux else None)
143         logger.warning("Webapp creation complete")
144     else:
145         logger.warning("App '%s' already exists", name)
146 
147     if do_deployment:
148         # setting to build after deployment
149         logger.warning("Updating app settings to enable build after deployment")
150         update_app_settings(cmd, rg_name, name, ["SCM_DO_BUILD_DURING_DEPLOYMENT=true"])
151         # work around until the timeout limits issue for linux is investigated & fixed
152         # wakeup kudu, by making an SCM call
153 
154         import requests
155         # work around until the timeout limits issue for linux is investigated & fixed
156         user_name, password = _get_site_credential(cmd.cli_ctx, rg_name, name)
157         scm_url = _get_scm_url(cmd, rg_name, name)
158         import urllib3
159         authorization = urllib3.util.make_headers(basic_auth='{0}:{1}'.format(user_name, password))
160         requests.get(scm_url + '/api/settings', headers=authorization)
161 
162         logger.warning("Creating zip with contents of dir %s ...", src_dir)
163         # zip contents & deploy
164         zip_file_path = zip_contents_from_dir(src_dir, language)
165 
166         logger.warning("Deploying and building contents to app."
167                        "This operation can take some time to finish...")
168         enable_zip_deploy(cmd, rg_name, name, zip_file_path)
169     else:
170         logger.warning("No 'NODE' or 'DOTNETCORE' package detected, skipping zip and deploy process")
171 
172     logger.warning("All done. %s", create_json)
173     return None
174
```

Path: `src/webapp/azext_webapp/_constants.py`
Content:
```
1 # --------------------------------------------------------------------------------------------
2 # Copyright (c) Microsoft Corporation. All rights reserved.
3 # Licensed under the MIT License. See License.txt in the project root for license information.
4 # --------------------------------------------------------------------------------------------
5 
6 NODE_VERSION_DEFAULT = "8.1"
7 NETCORE_VERSION_DEFAULT = "2.0"
8 # TODO: Remove this once we have the api returning the versions
9 NODE_VERSIONS = ['4.4', '4.5', '6.2', '6.6', '6.9', '6.11', '8.0', '8.1']
10 NETCORE_VERSIONS = ['1.0', '1.1', '2.0']
11 NODE_RUNTIME_NAME = "node"
12 NETCORE_RUNTIME_NAME = "dotnetcore"
13 OS_DEFAULT = "Windows"
14
```

Path: `src/webapp/setup.py`
Content:
```
1 #!/usr/bin/env python
2 
3 # --------------------------------------------------------------------------------------------
4 # Copyright (c) Microsoft Corporation. All rights reserved.
5 # Licensed under the MIT License. See License.txt in the project root for license information.
6 # --------------------------------------------------------------------------------------------
7 
8 from codecs import open
9 from setuptools import setup, find_packages
10 
11 VERSION = "0.1.1"
12 
13 CLASSIFIERS = [
14     'Development Status :: 4 - Beta',
15     'Intended Audience :: Developers',
16     'Intended Audience :: System Administrators',
17     'Programming Language :: Python',
18     'Programming Language :: Python :: 2',
19     'Programming Language :: Python :: 2.7',
20     'Programming Language :: Python :: 3',
21     'Programming Language :: Python :: 3.4',
22     'Programming Language :: Python :: 3.5',
23     'Programming Language :: Python :: 3.6',
24     'License :: OSI Approved :: MIT License',
25 ]
26 
27 DEPENDENCIES = []
28 
29 setup(
30     name='webapp',
31     version=VERSION,
32     description='An Azure CLI Extension to manage appservice resources',
33     long_description='An Azure CLI Extension to manage appservice resources',
34     license='MIT',
35     author='Sisira Panchagnula',
36     author_email='sisirap@microsoft.com',
37     url='https://github.com/Azure/azure-cli-extensions',
38     classifiers=CLASSIFIERS,
39     packages=find_packages(exclude=["tests"]),
40     install_requires=DEPENDENCIES
41 )
42
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/src/webapp/azext_webapp/_constants.py b/src/webapp/azext_webapp/_constants.py
--- a/src/webapp/azext_webapp/_constants.py
+++ b/src/webapp/azext_webapp/_constants.py
@@ -3,7 +3,7 @@
 # Licensed under the MIT License. See License.txt in the project root for license information.
 # --------------------------------------------------------------------------------------------
 
-NODE_VERSION_DEFAULT = "8.1"
+NODE_VERSION_DEFAULT = "8.9"
 NETCORE_VERSION_DEFAULT = "2.0"
 # TODO: Remove this once we have the api returning the versions
 NODE_VERSIONS = ['4.4', '4.5', '6.2', '6.6', '6.9', '6.11', '8.0', '8.1']
diff --git a/src/webapp/azext_webapp/custom.py b/src/webapp/azext_webapp/custom.py
--- a/src/webapp/azext_webapp/custom.py
+++ b/src/webapp/azext_webapp/custom.py
@@ -109,13 +109,12 @@
             }
             """ % (name, asp, rg_str, full_sku, os_val, location, src_path,
                    detected_version, runtime_version)
+    create_json = json.loads(dry_run_str)
 
-    create_json = json.dumps(json.loads(dry_run_str), indent=4, sort_keys=True)
     if dryrun:
         logger.warning("Web app will be created with the below configuration,re-run command "
                        "without the --dryrun flag to create & deploy a new app")
-        logger.warning(create_json)
-        return None
+        return create_json
 
     # create RG if the RG doesn't already exist
     if not check_resource_group_exists(cmd, rg_name):
@@ -139,7 +138,10 @@
     # create the app
     if not check_app_exists(cmd, rg_name, name):
         logger.warning("Creating app '%s' ....", name)
-        create_webapp(cmd, rg_name, name, asp, runtime_version if is_linux else None)
+        app_created = create_webapp(cmd, rg_name, name, asp, runtime_version if is_linux else None)
+        # update create_json to include the app_url
+        url = app_created.enabled_host_names[0]  # picks the custom domain URL incase a domain is assigned
+        url = 'https://' + url
         logger.warning("Webapp creation complete")
     else:
         logger.warning("App '%s' already exists", name)
@@ -166,8 +168,13 @@
         logger.warning("Deploying and building contents to app."
                        "This operation can take some time to finish...")
         enable_zip_deploy(cmd, rg_name, name, zip_file_path)
+        # Remove the file afer deployment, handling exception if user removed the file manually
+        try:
+            os.remove(zip_file_path)
+        except OSError:
+            pass
     else:
         logger.warning("No 'NODE' or 'DOTNETCORE' package detected, skipping zip and deploy process")
-
-    logger.warning("All done. %s", create_json)
-    return None
+    create_json.update({'app_url': url})
+    logger.warning("All done.")
+    return create_json
diff --git a/src/webapp/setup.py b/src/webapp/setup.py
--- a/src/webapp/setup.py
+++ b/src/webapp/setup.py
@@ -8,7 +8,7 @@
 from codecs import open
 from setuptools import setup, find_packages
 
-VERSION = "0.1.1"
+VERSION = "0.1.2"
 
 CLASSIFIERS = [
     'Development Status :: 4 - Beta',

{"golden_diff": "diff --git a/src/webapp/azext_webapp/_constants.py b/src/webapp/azext_webapp/_constants.py\n--- a/src/webapp/azext_webapp/_constants.py\n+++ b/src/webapp/azext_webapp/_constants.py\n@@ -3,7 +3,7 @@\n # Licensed under the MIT License. See License.txt in the project root for license information.\n # --------------------------------------------------------------------------------------------\n \n-NODE_VERSION_DEFAULT = \"8.1\"\n+NODE_VERSION_DEFAULT = \"8.9\"\n NETCORE_VERSION_DEFAULT = \"2.0\"\n # TODO: Remove this once we have the api returning the versions\n NODE_VERSIONS = ['4.4', '4.5', '6.2', '6.6', '6.9', '6.11', '8.0', '8.1']\ndiff --git a/src/webapp/azext_webapp/custom.py b/src/webapp/azext_webapp/custom.py\n--- a/src/webapp/azext_webapp/custom.py\n+++ b/src/webapp/azext_webapp/custom.py\n@@ -109,13 +109,12 @@\n             }\n             \"\"\" % (name, asp, rg_str, full_sku, os_val, location, src_path,\n                    detected_version, runtime_version)\n+    create_json = json.loads(dry_run_str)\n \n-    create_json = json.dumps(json.loads(dry_run_str), indent=4, sort_keys=True)\n     if dryrun:\n         logger.warning(\"Web app will be created with the below configuration,re-run command \"\n                        \"without the --dryrun flag to create & deploy a new app\")\n-        logger.warning(create_json)\n-        return None\n+        return create_json\n \n     # create RG if the RG doesn't already exist\n     if not check_resource_group_exists(cmd, rg_name):\n@@ -139,7 +138,10 @@\n     # create the app\n     if not check_app_exists(cmd, rg_name, name):\n         logger.warning(\"Creating app '%s' ....\", name)\n-        create_webapp(cmd, rg_name, name, asp, runtime_version if is_linux else None)\n+        app_created = create_webapp(cmd, rg_name, name, asp, runtime_version if is_linux else None)\n+        # update create_json to include the app_url\n+        url = app_created.enabled_host_names[0]  # picks the custom domain URL incase a domain is assigned\n+        url = 'https://' + url\n         logger.warning(\"Webapp creation complete\")\n     else:\n         logger.warning(\"App '%s' already exists\", name)\n@@ -166,8 +168,13 @@\n         logger.warning(\"Deploying and building contents to app.\"\n                        \"This operation can take some time to finish...\")\n         enable_zip_deploy(cmd, rg_name, name, zip_file_path)\n+        # Remove the file afer deployment, handling exception if user removed the file manually\n+        try:\n+            os.remove(zip_file_path)\n+        except OSError:\n+            pass\n     else:\n         logger.warning(\"No 'NODE' or 'DOTNETCORE' package detected, skipping zip and deploy process\")\n-\n-    logger.warning(\"All done. %s\", create_json)\n-    return None\n+    create_json.update({'app_url': url})\n+    logger.warning(\"All done.\")\n+    return create_json\ndiff --git a/src/webapp/setup.py b/src/webapp/setup.py\n--- a/src/webapp/setup.py\n+++ b/src/webapp/setup.py\n@@ -8,7 +8,7 @@\n from codecs import open\n from setuptools import setup, find_packages\n \n-VERSION = \"0.1.1\"\n+VERSION = \"0.1.2\"\n \n CLASSIFIERS = [\n     'Development Status :: 4 - Beta',\n", "issue": "Switch to using Node 8.9 as the default version for az webapp new\n\n", "before_files": [{"content": "# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\nfrom __future__ import print_function\nfrom knack.log import get_logger\n\nfrom azure.mgmt.web.models import (AppServicePlan, SkuDescription)\n\nfrom azure.cli.command_modules.appservice.custom import (\n    enable_zip_deploy,\n    create_webapp,\n    update_app_settings,\n    _get_site_credential,\n    _get_scm_url,\n    _get_sku_name)\n\nfrom .create_util import (\n    zip_contents_from_dir,\n    get_runtime_version_details,\n    create_resource_group,\n    check_resource_group_exists,\n    check_resource_group_supports_os,\n    check_if_asp_exists,\n    check_app_exists,\n    get_lang_from_content,\n    web_client_factory\n)\n\nfrom ._constants import (NODE_RUNTIME_NAME, OS_DEFAULT)\n\nlogger = get_logger(__name__)\n\n# pylint:disable=no-member,too-many-lines,too-many-locals,too-many-statements\n\n\ndef create_deploy_webapp(cmd, name, location=None, dryrun=False):\n    import os\n    import json\n\n    client = web_client_factory(cmd.cli_ctx)\n    # the code to deploy is expected to be the current directory the command is running from\n    src_dir = os.getcwd()\n\n    # if dir is empty, show a message in dry run\n    do_deployment = False if os.listdir(src_dir) == [] else True\n\n    # determine the details for app to be created from src contents\n    lang_details = get_lang_from_content(src_dir)\n    # we support E2E create and deploy for Node & dotnetcore, any other stack, set defaults for os & runtime\n    # and skip deployment\n    if lang_details['language'] is None:\n        do_deployment = False\n        sku = 'F1'\n        os_val = OS_DEFAULT\n        detected_version = '-'\n        runtime_version = '-'\n    else:\n        sku = lang_details.get(\"default_sku\")\n        language = lang_details.get(\"language\")\n        os_val = \"Linux\" if language.lower() == NODE_RUNTIME_NAME else OS_DEFAULT\n        # detect the version\n        data = get_runtime_version_details(lang_details.get('file_loc'), language)\n        version_used_create = data.get('to_create')\n        detected_version = data.get('detected')\n        runtime_version = \"{}|{}\".format(language, version_used_create)\n\n    if location is None:\n        locs = client.list_geo_regions(sku, True)\n        available_locs = []\n        for loc in locs:\n            available_locs.append(loc.geo_region_name)\n        location = available_locs[0]\n    # Remove spaces from the location string, incase the GeoRegion string is used\n    loc_name = location.replace(\" \", \"\")\n    full_sku = _get_sku_name(sku)\n\n    is_linux = True if os_val == 'Linux' else False\n\n    asp = \"appsvc_asp_{}_{}\".format(os_val, loc_name)\n    rg_name = \"appsvc_rg_{}_{}\".format(os_val, loc_name)\n\n    str_no_contents_warn = \"\"\n    if not do_deployment:\n        str_no_contents_warn = \"[Empty directory, no deployment will be triggered]\"\n\n    # Resource group: check if default RG is set\n    default_rg = cmd.cli_ctx.config.get('defaults', 'group', fallback=None)\n    if default_rg and check_resource_group_supports_os(cmd, default_rg, location, is_linux):\n        rg_name = default_rg\n        rg_mssg = \"[Using default Resource group]\"\n    else:\n        rg_mssg = \"\"\n\n    src_path = \"{} {}\".format(src_dir.replace(\"\\\\\", \"\\\\\\\\\"), str_no_contents_warn)\n    rg_str = \"{} {}\".format(rg_name, rg_mssg)\n\n    dry_run_str = r\"\"\" {\n            \"name\" : \"%s\",\n            \"serverfarm\" : \"%s\",\n            \"resourcegroup\" : \"%s\",\n            \"sku\": \"%s\",\n            \"os\": \"%s\",\n            \"location\" : \"%s\",\n            \"src_path\" : \"%s\",\n            \"version_detected\": \"%s\",\n            \"version_to_create\": \"%s\"\n            }\n            \"\"\" % (name, asp, rg_str, full_sku, os_val, location, src_path,\n                   detected_version, runtime_version)\n\n    create_json = json.dumps(json.loads(dry_run_str), indent=4, sort_keys=True)\n    if dryrun:\n        logger.warning(\"Web app will be created with the below configuration,re-run command \"\n                       \"without the --dryrun flag to create & deploy a new app\")\n        logger.warning(create_json)\n        return None\n\n    # create RG if the RG doesn't already exist\n    if not check_resource_group_exists(cmd, rg_name):\n        logger.warning(\"Creating Resource group '%s' ...\", rg_name)\n        create_resource_group(cmd, rg_name, location)\n        logger.warning(\"Resource group creation complete\")\n    else:\n        logger.warning(\"Resource group '%s' already exists.\", rg_name)\n\n    # create asp\n    if not check_if_asp_exists(cmd, rg_name, asp):\n        logger.warning(\"Creating App service plan '%s' ...\", asp)\n        sku_def = SkuDescription(tier=full_sku, name=sku, capacity=(1 if is_linux else None))\n        plan_def = AppServicePlan(loc_name, app_service_plan_name=asp,\n                                  sku=sku_def, reserved=(is_linux or None))\n        client.app_service_plans.create_or_update(rg_name, asp, plan_def)\n        logger.warning(\"App service plan creation complete\")\n    else:\n        logger.warning(\"App service plan '%s' already exists.\", asp)\n\n    # create the app\n    if not check_app_exists(cmd, rg_name, name):\n        logger.warning(\"Creating app '%s' ....\", name)\n        create_webapp(cmd, rg_name, name, asp, runtime_version if is_linux else None)\n        logger.warning(\"Webapp creation complete\")\n    else:\n        logger.warning(\"App '%s' already exists\", name)\n\n    if do_deployment:\n        # setting to build after deployment\n        logger.warning(\"Updating app settings to enable build after deployment\")\n        update_app_settings(cmd, rg_name, name, [\"SCM_DO_BUILD_DURING_DEPLOYMENT=true\"])\n        # work around until the timeout limits issue for linux is investigated & fixed\n        # wakeup kudu, by making an SCM call\n\n        import requests\n        # work around until the timeout limits issue for linux is investigated & fixed\n        user_name, password = _get_site_credential(cmd.cli_ctx, rg_name, name)\n        scm_url = _get_scm_url(cmd, rg_name, name)\n        import urllib3\n        authorization = urllib3.util.make_headers(basic_auth='{0}:{1}'.format(user_name, password))\n        requests.get(scm_url + '/api/settings', headers=authorization)\n\n        logger.warning(\"Creating zip with contents of dir %s ...\", src_dir)\n        # zip contents & deploy\n        zip_file_path = zip_contents_from_dir(src_dir, language)\n\n        logger.warning(\"Deploying and building contents to app.\"\n                       \"This operation can take some time to finish...\")\n        enable_zip_deploy(cmd, rg_name, name, zip_file_path)\n    else:\n        logger.warning(\"No 'NODE' or 'DOTNETCORE' package detected, skipping zip and deploy process\")\n\n    logger.warning(\"All done. %s\", create_json)\n    return None\n", "path": "src/webapp/azext_webapp/custom.py"}, {"content": "# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\nNODE_VERSION_DEFAULT = \"8.1\"\nNETCORE_VERSION_DEFAULT = \"2.0\"\n# TODO: Remove this once we have the api returning the versions\nNODE_VERSIONS = ['4.4', '4.5', '6.2', '6.6', '6.9', '6.11', '8.0', '8.1']\nNETCORE_VERSIONS = ['1.0', '1.1', '2.0']\nNODE_RUNTIME_NAME = \"node\"\nNETCORE_RUNTIME_NAME = \"dotnetcore\"\nOS_DEFAULT = \"Windows\"\n", "path": "src/webapp/azext_webapp/_constants.py"}, {"content": "#!/usr/bin/env python\n\n# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\nfrom codecs import open\nfrom setuptools import setup, find_packages\n\nVERSION = \"0.1.1\"\n\nCLASSIFIERS = [\n    'Development Status :: 4 - Beta',\n    'Intended Audience :: Developers',\n    'Intended Audience :: System Administrators',\n    'Programming Language :: Python',\n    'Programming Language :: Python :: 2',\n    'Programming Language :: Python :: 2.7',\n    'Programming Language :: Python :: 3',\n    'Programming Language :: Python :: 3.4',\n    'Programming Language :: Python :: 3.5',\n    'Programming Language :: Python :: 3.6',\n    'License :: OSI Approved :: MIT License',\n]\n\nDEPENDENCIES = []\n\nsetup(\n    name='webapp',\n    version=VERSION,\n    description='An Azure CLI Extension to manage appservice resources',\n    long_description='An Azure CLI Extension to manage appservice resources',\n    license='MIT',\n    author='Sisira Panchagnula',\n    author_email='sisirap@microsoft.com',\n    url='https://github.com/Azure/azure-cli-extensions',\n    classifiers=CLASSIFIERS,\n    packages=find_packages(exclude=[\"tests\"]),\n    install_requires=DEPENDENCIES\n)\n", "path": "src/webapp/setup.py"}], "after_files": [{"content": "# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\nfrom __future__ import print_function\nfrom knack.log import get_logger\n\nfrom azure.mgmt.web.models import (AppServicePlan, SkuDescription)\n\nfrom azure.cli.command_modules.appservice.custom import (\n    enable_zip_deploy,\n    create_webapp,\n    update_app_settings,\n    _get_site_credential,\n    _get_scm_url,\n    _get_sku_name)\n\nfrom .create_util import (\n    zip_contents_from_dir,\n    get_runtime_version_details,\n    create_resource_group,\n    check_resource_group_exists,\n    check_resource_group_supports_os,\n    check_if_asp_exists,\n    check_app_exists,\n    get_lang_from_content,\n    web_client_factory\n)\n\nfrom ._constants import (NODE_RUNTIME_NAME, OS_DEFAULT)\n\nlogger = get_logger(__name__)\n\n# pylint:disable=no-member,too-many-lines,too-many-locals,too-many-statements\n\n\ndef create_deploy_webapp(cmd, name, location=None, dryrun=False):\n    import os\n    import json\n\n    client = web_client_factory(cmd.cli_ctx)\n    # the code to deploy is expected to be the current directory the command is running from\n    src_dir = os.getcwd()\n\n    # if dir is empty, show a message in dry run\n    do_deployment = False if os.listdir(src_dir) == [] else True\n\n    # determine the details for app to be created from src contents\n    lang_details = get_lang_from_content(src_dir)\n    # we support E2E create and deploy for Node & dotnetcore, any other stack, set defaults for os & runtime\n    # and skip deployment\n    if lang_details['language'] is None:\n        do_deployment = False\n        sku = 'F1'\n        os_val = OS_DEFAULT\n        detected_version = '-'\n        runtime_version = '-'\n    else:\n        sku = lang_details.get(\"default_sku\")\n        language = lang_details.get(\"language\")\n        os_val = \"Linux\" if language.lower() == NODE_RUNTIME_NAME else OS_DEFAULT\n        # detect the version\n        data = get_runtime_version_details(lang_details.get('file_loc'), language)\n        version_used_create = data.get('to_create')\n        detected_version = data.get('detected')\n        runtime_version = \"{}|{}\".format(language, version_used_create)\n\n    if location is None:\n        locs = client.list_geo_regions(sku, True)\n        available_locs = []\n        for loc in locs:\n            available_locs.append(loc.geo_region_name)\n        location = available_locs[0]\n    # Remove spaces from the location string, incase the GeoRegion string is used\n    loc_name = location.replace(\" \", \"\")\n    full_sku = _get_sku_name(sku)\n\n    is_linux = True if os_val == 'Linux' else False\n\n    asp = \"appsvc_asp_{}_{}\".format(os_val, loc_name)\n    rg_name = \"appsvc_rg_{}_{}\".format(os_val, loc_name)\n\n    str_no_contents_warn = \"\"\n    if not do_deployment:\n        str_no_contents_warn = \"[Empty directory, no deployment will be triggered]\"\n\n    # Resource group: check if default RG is set\n    default_rg = cmd.cli_ctx.config.get('defaults', 'group', fallback=None)\n    if default_rg and check_resource_group_supports_os(cmd, default_rg, location, is_linux):\n        rg_name = default_rg\n        rg_mssg = \"[Using default Resource group]\"\n    else:\n        rg_mssg = \"\"\n\n    src_path = \"{} {}\".format(src_dir.replace(\"\\\\\", \"\\\\\\\\\"), str_no_contents_warn)\n    rg_str = \"{} {}\".format(rg_name, rg_mssg)\n\n    dry_run_str = r\"\"\" {\n            \"name\" : \"%s\",\n            \"serverfarm\" : \"%s\",\n            \"resourcegroup\" : \"%s\",\n            \"sku\": \"%s\",\n            \"os\": \"%s\",\n            \"location\" : \"%s\",\n            \"src_path\" : \"%s\",\n            \"version_detected\": \"%s\",\n            \"version_to_create\": \"%s\"\n            }\n            \"\"\" % (name, asp, rg_str, full_sku, os_val, location, src_path,\n                   detected_version, runtime_version)\n    create_json = json.loads(dry_run_str)\n\n    if dryrun:\n        logger.warning(\"Web app will be created with the below configuration,re-run command \"\n                       \"without the --dryrun flag to create & deploy a new app\")\n        return create_json\n\n    # create RG if the RG doesn't already exist\n    if not check_resource_group_exists(cmd, rg_name):\n        logger.warning(\"Creating Resource group '%s' ...\", rg_name)\n        create_resource_group(cmd, rg_name, location)\n        logger.warning(\"Resource group creation complete\")\n    else:\n        logger.warning(\"Resource group '%s' already exists.\", rg_name)\n\n    # create asp\n    if not check_if_asp_exists(cmd, rg_name, asp):\n        logger.warning(\"Creating App service plan '%s' ...\", asp)\n        sku_def = SkuDescription(tier=full_sku, name=sku, capacity=(1 if is_linux else None))\n        plan_def = AppServicePlan(loc_name, app_service_plan_name=asp,\n                                  sku=sku_def, reserved=(is_linux or None))\n        client.app_service_plans.create_or_update(rg_name, asp, plan_def)\n        logger.warning(\"App service plan creation complete\")\n    else:\n        logger.warning(\"App service plan '%s' already exists.\", asp)\n\n    # create the app\n    if not check_app_exists(cmd, rg_name, name):\n        logger.warning(\"Creating app '%s' ....\", name)\n        app_created = create_webapp(cmd, rg_name, name, asp, runtime_version if is_linux else None)\n        # update create_json to include the app_url\n        url = app_created.enabled_host_names[0]  # picks the custom domain URL incase a domain is assigned\n        url = 'https://' + url\n        logger.warning(\"Webapp creation complete\")\n    else:\n        logger.warning(\"App '%s' already exists\", name)\n\n    if do_deployment:\n        # setting to build after deployment\n        logger.warning(\"Updating app settings to enable build after deployment\")\n        update_app_settings(cmd, rg_name, name, [\"SCM_DO_BUILD_DURING_DEPLOYMENT=true\"])\n        # work around until the timeout limits issue for linux is investigated & fixed\n        # wakeup kudu, by making an SCM call\n\n        import requests\n        # work around until the timeout limits issue for linux is investigated & fixed\n        user_name, password = _get_site_credential(cmd.cli_ctx, rg_name, name)\n        scm_url = _get_scm_url(cmd, rg_name, name)\n        import urllib3\n        authorization = urllib3.util.make_headers(basic_auth='{0}:{1}'.format(user_name, password))\n        requests.get(scm_url + '/api/settings', headers=authorization)\n\n        logger.warning(\"Creating zip with contents of dir %s ...\", src_dir)\n        # zip contents & deploy\n        zip_file_path = zip_contents_from_dir(src_dir, language)\n\n        logger.warning(\"Deploying and building contents to app.\"\n                       \"This operation can take some time to finish...\")\n        enable_zip_deploy(cmd, rg_name, name, zip_file_path)\n        # Remove the file afer deployment, handling exception if user removed the file manually\n        try:\n            os.remove(zip_file_path)\n        except OSError:\n            pass\n    else:\n        logger.warning(\"No 'NODE' or 'DOTNETCORE' package detected, skipping zip and deploy process\")\n    create_json.update({'app_url': url})\n    logger.warning(\"All done.\")\n    return create_json\n", "path": "src/webapp/azext_webapp/custom.py"}, {"content": "# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\nNODE_VERSION_DEFAULT = \"8.9\"\nNETCORE_VERSION_DEFAULT = \"2.0\"\n# TODO: Remove this once we have the api returning the versions\nNODE_VERSIONS = ['4.4', '4.5', '6.2', '6.6', '6.9', '6.11', '8.0', '8.1']\nNETCORE_VERSIONS = ['1.0', '1.1', '2.0']\nNODE_RUNTIME_NAME = \"node\"\nNETCORE_RUNTIME_NAME = \"dotnetcore\"\nOS_DEFAULT = \"Windows\"\n", "path": "src/webapp/azext_webapp/_constants.py"}, {"content": "#!/usr/bin/env python\n\n# --------------------------------------------------------------------------------------------\n# Copyright (c) Microsoft Corporation. All rights reserved.\n# Licensed under the MIT License. See License.txt in the project root for license information.\n# --------------------------------------------------------------------------------------------\n\nfrom codecs import open\nfrom setuptools import setup, find_packages\n\nVERSION = \"0.1.2\"\n\nCLASSIFIERS = [\n    'Development Status :: 4 - Beta',\n    'Intended Audience :: Developers',\n    'Intended Audience :: System Administrators',\n    'Programming Language :: Python',\n    'Programming Language :: Python :: 2',\n    'Programming Language :: Python :: 2.7',\n    'Programming Language :: Python :: 3',\n    'Programming Language :: Python :: 3.4',\n    'Programming Language :: Python :: 3.5',\n    'Programming Language :: Python :: 3.6',\n    'License :: OSI Approved :: MIT License',\n]\n\nDEPENDENCIES = []\n\nsetup(\n    name='webapp',\n    version=VERSION,\n    description='An Azure CLI Extension to manage appservice resources',\n    long_description='An Azure CLI Extension to manage appservice resources',\n    license='MIT',\n    author='Sisira Panchagnula',\n    author_email='sisirap@microsoft.com',\n    url='https://github.com/Azure/azure-cli-extensions',\n    classifiers=CLASSIFIERS,\n    packages=find_packages(exclude=[\"tests\"]),\n    install_requires=DEPENDENCIES\n)\n", "path": "src/webapp/setup.py"}]}