Skip to content

Commit 144a0cf

Browse files
author
Daniel Gao
committed
Implement
1 parent d012873 commit 144a0cf

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

src/azure-cli/azure/cli/command_modules/cosmosdb/_validators.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,3 +605,41 @@ def validate_fleetspaceAccount_body(cmd, ns):
605605
raise InvalidArgumentValueError('"armLocation" must be a valid string.')
606606

607607
ns.fleetspace_account_body = body
608+
609+
610+
def _is_valid_guid(value):
611+
"""Check if a string is a valid GUID."""
612+
import uuid
613+
try:
614+
uuid.UUID(value)
615+
return True
616+
except ValueError:
617+
return False
618+
619+
620+
def is_valid_network_acl_bypass_resource_id(resource_id):
621+
"""Validates a resource ID for network ACL bypass.
622+
623+
Supports standard Azure resource IDs and Fabric resource IDs with /tenants/ prefix.
624+
Fabric format: /tenants/{tenantId}/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Fabric/providers/Microsoft.Fabric/workspaces/{workspaceGuid}
625+
626+
:param resource_id: The resource ID to validate.
627+
:return: True if valid, False otherwise.
628+
"""
629+
import re
630+
from azure.mgmt.core.tools import is_valid_resource_id
631+
632+
if not resource_id:
633+
return False
634+
635+
if is_valid_resource_id(resource_id):
636+
return True
637+
638+
# Check for Fabric resource ID format - extract GUIDs and validate them
639+
pattern = r'^/tenants/(.+)/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Fabric/providers/Microsoft\.Fabric/workspaces/(.+)$'
640+
match = re.match(pattern, resource_id, re.IGNORECASE)
641+
642+
if not match:
643+
return False
644+
645+
return _is_valid_guid(match.group(1)) and _is_valid_guid(match.group(2))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -460,10 +460,10 @@ def cli_cosmosdb_update(client,
460460
update_consistency_policy = True
461461

462462
if network_acl_bypass_resource_ids is not None:
463-
from azure.mgmt.core.tools import is_valid_resource_id
464463
from azure.cli.core.azclierror import InvalidArgumentValueError
464+
from azure.cli.command_modules.cosmosdb._validators import is_valid_network_acl_bypass_resource_id
465465
for resource_id in network_acl_bypass_resource_ids:
466-
if not is_valid_resource_id(resource_id):
466+
if not is_valid_network_acl_bypass_resource_id(resource_id):
467467
raise InvalidArgumentValueError(
468468
f'{resource_id} is not a valid resource ID for --network-acl-bypass-resource-ids')
469469

0 commit comments

Comments
 (0)