Skip to content

Commit 8d0c503

Browse files
authored
[App Service] az webapp create: Include regional site name availability check for DNL site creations (#32184)
1 parent eecf802 commit 8d0c503

File tree

3 files changed

+100
-59
lines changed

3 files changed

+100
-59
lines changed

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,25 @@ def get_site_availability(cmd, name):
335335
return availability
336336

337337

338+
def get_regional_site_availability(cmd, location, name, resource_group_name, auto_generated_domain_name_label_scope):
339+
""" This is used by az webapp up to verify if a site needs to be created or should just be deployed
340+
(regional check)"""
341+
client = web_client_factory(cmd.cli_ctx)
342+
availability = client.regional_check_name_availability(location,
343+
name,
344+
"Site",
345+
resource_group_name,
346+
auto_generated_domain_name_label_scope)
347+
348+
# check for "." in app name. it is valid for hostnames to contain it, but not allowed for webapp names
349+
if "." in name:
350+
availability.name_available = False
351+
availability.reason = "Invalid"
352+
availability.message = ("Site names only allow alphanumeric characters and hyphens, "
353+
"cannot start or end in a hyphen, and must be less than 64 chars.")
354+
return availability
355+
356+
338357
def get_app_details(cmd, name):
339358
client = web_client_factory(cmd.cli_ctx)
340359
data = (list(filter(lambda x: name.lower() == x.name.lower(), client.web_apps.list())))

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,8 @@
7676
_remove_list_duplicates, get_raw_functionapp,
7777
register_app_provider)
7878
from ._create_util import (zip_contents_from_dir, get_runtime_version_details, create_resource_group, get_app_details,
79-
check_resource_group_exists, set_location, get_site_availability, get_profile_username,
79+
check_resource_group_exists, set_location, get_site_availability,
80+
get_regional_site_availability, get_profile_username,
8081
get_plan_to_use, get_lang_from_content, get_rg_to_use, get_sku_to_use,
8182
detect_os_from_src, get_current_stack_from_runtime, generate_default_app_name,
8283
get_or_create_default_workspace, get_or_create_default_resource_group,
@@ -168,7 +169,15 @@ def create_webapp(cmd, resource_group_name, name, plan, runtime=None, startup_fi
168169
helper = _StackRuntimeHelper(cmd, linux=is_linux, windows=not is_linux)
169170
location = plan_info.location
170171
# This is to keep the existing appsettings for a newly created webapp on existing webapp name.
171-
name_validation = get_site_availability(cmd, name)
172+
if auto_generated_domain_name_label_scope:
173+
name_validation = get_regional_site_availability(cmd,
174+
location,
175+
name,
176+
resource_group_name,
177+
auto_generated_domain_name_label_scope)
178+
else:
179+
name_validation = get_site_availability(cmd, name)
180+
172181
if not name_validation.name_available:
173182
if name_validation.reason == 'Invalid':
174183
raise ValidationError(name_validation.message)

0 commit comments

Comments
 (0)