Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions src/azure-cli/azure/cli/command_modules/cosmosdb/_validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -605,3 +605,40 @@ def validate_fleetspaceAccount_body(cmd, ns):
raise InvalidArgumentValueError('"armLocation" must be a valid string.')

ns.fleetspace_account_body = body


def _is_valid_guid(value):
"""Check if a string is a valid GUID."""
import uuid
try:
return str(uuid.UUID(value)) == value.lower()
except ValueError:
return False


def is_valid_network_acl_bypass_resource_id(resource_id):
"""Validates a resource ID for network ACL bypass.

Supports standard Azure resource IDs and Fabric resource IDs with /tenants/ prefix.
Fabric format: /tenants/{tenantId}/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Fabric/providers/Microsoft.Fabric/workspaces/{workspaceGuid}

:param resource_id: The resource ID to validate.
:return: True if valid, False otherwise.
"""
import re
from azure.mgmt.core.tools import is_valid_resource_id

if not resource_id:
return False

if is_valid_resource_id(resource_id):
return True

# Check for Fabric resource ID format - extract GUIDs and validate them
pattern = r'^/tenants/(.+)/subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/Fabric/providers/Microsoft\.Fabric/workspaces/(.+)$'
match = re.match(pattern, resource_id, re.IGNORECASE)

if not match:
return False

return _is_valid_guid(match.group(1)) and _is_valid_guid(match.group(2))
4 changes: 2 additions & 2 deletions src/azure-cli/azure/cli/command_modules/cosmosdb/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,10 +460,10 @@ def cli_cosmosdb_update(client,
update_consistency_policy = True

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

Expand Down
Loading
Loading