Skip to content

Commit 9b78387

Browse files
committed
Include Regional Site Name Availability Check for DNL site creations
1 parent c6ce095 commit 9b78387

File tree

3 files changed

+89
-59
lines changed

3 files changed

+89
-59
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,18 @@ def get_site_availability(cmd, name):
334334
"cannot start or end in a hyphen, and must be less than 64 chars.")
335335
return availability
336336

337+
def get_regional_site_availability(cmd, location, name, resource_group_name, auto_generated_domain_name_label_scope):
338+
client = web_client_factory(cmd.cli_ctx)
339+
availability = client.regional_check_name_availability(location, name, "Site", resource_group_name, auto_generated_domain_name_label_scope)
340+
341+
# check for "." in app name. it is valid for hostnames to contain it, but not allowed for webapp names
342+
if "." in name:
343+
availability.name_available = False
344+
availability.reason = "Invalid"
345+
availability.message = ("Site names only allow alphanumeric characters and hyphens, "
346+
"cannot start or end in a hyphen, and must be less than 64 chars.")
347+
return availability
348+
337349

338350
def get_app_details(cmd, name):
339351
client = web_client_factory(cmd.cli_ctx)

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@
7575
_remove_list_duplicates, get_raw_functionapp,
7676
register_app_provider)
7777
from ._create_util import (zip_contents_from_dir, get_runtime_version_details, create_resource_group, get_app_details,
78-
check_resource_group_exists, set_location, get_site_availability, get_profile_username,
78+
check_resource_group_exists, set_location, get_site_availability, get_regional_site_availability, get_profile_username,
7979
get_plan_to_use, get_lang_from_content, get_rg_to_use, get_sku_to_use,
8080
detect_os_from_src, get_current_stack_from_runtime, generate_default_app_name,
8181
get_or_create_default_workspace, get_or_create_default_resource_group,
@@ -167,7 +167,12 @@ def create_webapp(cmd, resource_group_name, name, plan, runtime=None, startup_fi
167167
helper = _StackRuntimeHelper(cmd, linux=is_linux, windows=not is_linux)
168168
location = plan_info.location
169169
# This is to keep the existing appsettings for a newly created webapp on existing webapp name.
170-
name_validation = get_site_availability(cmd, name)
170+
171+
if auto_generated_domain_name_label_scope:
172+
name_validation = get_regional_site_availability(cmd, location, name, resource_group_name, auto_generated_domain_name_label_scope)
173+
else:
174+
name_validation = get_site_availability(cmd, name)
175+
171176
if not name_validation.name_available:
172177
if name_validation.reason == 'Invalid':
173178
raise ValidationError(name_validation.message)

0 commit comments

Comments
 (0)