Skip to content

Commit 241e787

Browse files
dgao97Daniel Gao
andauthored
[CosmosDB] az cosmosdb update: Add support for Microsoft Fabric workspace resource IDs in --network-acl-bypass-resource-ids (#32797)
Co-authored-by: Daniel Gao <danielgao@microsoft.com>
1 parent 7ddc82c commit 241e787

4 files changed

Lines changed: 1306 additions & 2 deletions

File tree

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -605,3 +605,40 @@ 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+
return str(uuid.UUID(value)) == value.lower()
615+
except ValueError:
616+
return False
617+
618+
619+
def is_valid_network_acl_bypass_resource_id(resource_id):
620+
"""Validates a resource ID for network ACL bypass.
621+
622+
Supports standard Azure resource IDs and Fabric resource IDs with /tenants/ prefix.
623+
Fabric format: /tenants/{tenantId}/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Fabric/providers/Microsoft.Fabric/workspaces/{workspaceGuid}
624+
625+
:param resource_id: The resource ID to validate.
626+
:return: True if valid, False otherwise.
627+
"""
628+
import re
629+
from azure.mgmt.core.tools import is_valid_resource_id
630+
631+
if not resource_id:
632+
return False
633+
634+
if is_valid_resource_id(resource_id):
635+
return True
636+
637+
# Check for Fabric resource ID format - extract GUIDs and validate them
638+
pattern = r'^/tenants/(.+)/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Fabric/providers/Microsoft\.Fabric/workspaces/(.+)$'
639+
match = re.match(pattern, resource_id, re.IGNORECASE)
640+
641+
if not match:
642+
return False
643+
644+
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)