Skip to content

Commit 095014b

Browse files
authored
[App Service] az webapp up: Add parameter --domain-name-scope to support specifying the scope of uniqueness for the default hostname during resource creation (#32930)
1 parent c480281 commit 095014b

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

src/azure-cli/azure/cli/command_modules/appservice/_help.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2615,6 +2615,9 @@
26152615
- name: Create a web app and deploy as a static HTML app.
26162616
text: >
26172617
az webapp up --html
2618+
- name: Create a web app with a specified domain name scope for unique hostname generation
2619+
text: >
2620+
az webapp up -n MyUniqueAppName --domain-name-scope TenantReuse
26182621
"""
26192622

26202623
helps['webapp update'] = """

src/azure-cli/azure/cli/command_modules/appservice/_params.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,7 @@ def load_arguments(self, _):
972972
arg_type=get_three_state_flag())
973973
c.argument('enable_kudu_warmup', help="If true, kudu will be warmed up before performing deployment for a linux webapp.",
974974
arg_type=get_three_state_flag())
975+
c.argument('auto_generated_domain_name_label_scope', options_list=['--domain-name-scope'], help="Specify the scope of uniqueness for the default hostname during resource creation.", arg_type=get_enum_type(AutoGeneratedDomainNameLabelScope))
975976

976977
with self.argument_context('webapp ssh') as c:
977978
c.argument('port', options_list=['--port', '-p'],

src/azure-cli/azure/cli/command_modules/appservice/custom.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9082,7 +9082,8 @@ def get_history_triggered_webjob(cmd, resource_group_name, name, webjob_name, sl
90829082

90839083
def webapp_up(cmd, name=None, resource_group_name=None, plan=None, location=None, sku=None, # pylint: disable=too-many-statements,too-many-branches
90849084
os_type=None, runtime=None, dryrun=False, logs=False, launch_browser=False, html=False,
9085-
app_service_environment=None, track_status=True, enable_kudu_warmup=True, basic_auth=""):
9085+
app_service_environment=None, track_status=True, enable_kudu_warmup=True, basic_auth="",
9086+
auto_generated_domain_name_label_scope=None):
90869087
if not name:
90879088
name = generate_default_app_name(cmd)
90889089

@@ -9228,7 +9229,8 @@ def webapp_up(cmd, name=None, resource_group_name=None, plan=None, location=None
92289229
if _create_new_app:
92299230
logger.warning("Creating webapp '%s' ...", name)
92309231
create_webapp(cmd, rg_name, name, plan, runtime_version if not html else None,
9231-
using_webapp_up=True, language=language)
9232+
using_webapp_up=True, language=language,
9233+
auto_generated_domain_name_label_scope=auto_generated_domain_name_label_scope)
92329234
_configure_default_logging(cmd, rg_name, name)
92339235
else: # for existing app if we might need to update the stack runtime settings
92349236
helper = _StackRuntimeHelper(cmd, linux=_is_linux, windows=not _is_linux)

src/azure-cli/azure/cli/command_modules/appservice/tests/latest/test_webapp_up_commands.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import unittest
1010
import os
11+
import re
1112
from pytest import skip
1213
import requests
1314
from knack.util import CLIError
@@ -1369,6 +1370,58 @@ def test_webapp_up_track_runtimestatus_runtimefailed(self, resource_group):
13691370
import shutil
13701371
shutil.rmtree(temp_dir)
13711372

1373+
@live_only()
1374+
@AllowLargeResponse(8192)
1375+
@ResourceGroupPreparer(random_name_length=24, name_prefix='clitest', location=LINUX_ASP_LOCATION_WEBAPP)
1376+
def test_webapp_up_with_domain_name_scope(self, resource_group):
1377+
plan = self.create_random_name('up-dnlplan', 24)
1378+
webapp_name = self.create_random_name('up-dnl-app', 24)
1379+
zip_file_name = os.path.join(TEST_DIR, 'node-Express-up.zip')
1380+
1381+
import zipfile
1382+
import tempfile
1383+
temp_dir = tempfile.mkdtemp()
1384+
zip_ref = zipfile.ZipFile(zip_file_name, 'r')
1385+
zip_ref.extractall(temp_dir)
1386+
current_working_dir = os.getcwd()
1387+
1388+
up_working_dir = os.path.join(temp_dir, 'myExpressApp')
1389+
os.chdir(up_working_dir)
1390+
1391+
# test dryrun with --domain-name-scope
1392+
result = self.cmd('webapp up -n {} --dryrun --domain-name-scope TenantReuse'.format(
1393+
webapp_name)).get_output_in_json()
1394+
self.assertTrue(result['name'].startswith(webapp_name))
1395+
self.assertIn("node|", result['runtime_version'].lower())
1396+
self.assertEqual(result['os'].lower(), 'linux')
1397+
1398+
# test the full E2E operation works
1399+
self.cmd('webapp up -n {} -g {} --plan {} --domain-name-scope TenantReuse'.format(
1400+
webapp_name, resource_group, plan)).get_output_in_json()
1401+
1402+
# Verify app is created with domain name scope
1403+
result = self.cmd('webapp show -n {} -g {}'.format(webapp_name, resource_group), checks=[
1404+
JMESPathCheck('name', webapp_name),
1405+
JMESPathCheck('state', 'Running'),
1406+
JMESPathCheck('resourceGroup', resource_group),
1407+
JMESPathCheck('autoGeneratedDomainNameLabelScope', 'TenantReuse')
1408+
]).get_output_in_json()
1409+
1410+
# Verify the default hostname matches the regional pattern with hash
1411+
default_hostname = result.get('defaultHostName')
1412+
pattern = r'^([a-zA-Z0-9\-]+)-([a-z0-9]{16})\.([a-z]+-\d{2})\.azurewebsites\.net$'
1413+
match = re.match(pattern, default_hostname)
1414+
self.assertIsNotNone(match, "defaultHostName '{}' does not match expected pattern".format(default_hostname))
1415+
app_name, hash_part, region = match.groups()
1416+
self.assertTrue(len(hash_part) == 16 and hash_part.islower(), "Hash is not 16 chars or not lowercase.")
1417+
self.assertIn('-', region, "Region part does not have '-' separator.")
1418+
self.assertEqual(app_name, webapp_name, "App name and defaultHostName app name do not match.")
1419+
1420+
# cleanup
1421+
os.chdir(current_working_dir)
1422+
import shutil
1423+
shutil.rmtree(temp_dir)
1424+
13721425

13731426
if __name__ == '__main__':
13741427
unittest.main()

0 commit comments

Comments
 (0)