Fix user delete flow 6
This commit is contained in:
@@ -6,6 +6,7 @@ Tenant access control utilities for microservices
|
||||
Provides both gateway-level and service-level tenant access verification
|
||||
"""
|
||||
|
||||
import re
|
||||
from typing import Dict, Any, Optional
|
||||
import httpx
|
||||
import structlog
|
||||
@@ -306,24 +307,15 @@ async def verify_tenant_permission_dep(
|
||||
|
||||
def extract_tenant_id_from_path(path: str) -> Optional[str]:
|
||||
"""
|
||||
Extract tenant_id from URL path like /api/v1/tenants/{tenant_id}/...
|
||||
BUT NOT from tenant management endpoints like /api/v1/tenants/register
|
||||
More robust tenant ID extraction using regex pattern matching
|
||||
Only matches actual tenant-scoped paths with UUID format
|
||||
"""
|
||||
path_parts = path.split("/")
|
||||
if "tenants" in path_parts:
|
||||
try:
|
||||
tenant_index = path_parts.index("tenants")
|
||||
if tenant_index + 1 < len(path_parts):
|
||||
potential_tenant_id = path_parts[tenant_index + 1]
|
||||
|
||||
# ✅ EXCLUDE tenant management endpoints
|
||||
if potential_tenant_id in ["register", "list"]:
|
||||
return None
|
||||
|
||||
return potential_tenant_id
|
||||
except (ValueError, IndexError):
|
||||
pass
|
||||
return None
|
||||
# Pattern for tenant-scoped paths: /api/v1/tenants/{uuid}/...
|
||||
tenant_pattern = r'/api/v1/tenants/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})/.*'
|
||||
|
||||
match = re.match(tenant_pattern, path, re.IGNORECASE)
|
||||
if match:
|
||||
return match.group(1)
|
||||
|
||||
def is_tenant_scoped_path(path: str) -> bool:
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user