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
26 changes: 26 additions & 0 deletions src/core/config_loader.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,32 @@ def get_tenant_by_subdomain(subdomain: str) -> dict[str, Any] | None:
raise


def get_tenant_by_id(tenant_id: str) -> dict[str, Any] | None:
"""Get tenant by tenant_id.

Args:
tenant_id: The tenant_id to look up (e.g., 'tenant_wonderstruck')

Returns:
Tenant dict if found, None otherwise
"""
try:
with get_db_session() as db_session:
stmt = select(Tenant).filter_by(tenant_id=tenant_id, is_active=True)
tenant = db_session.scalars(stmt).first()

if tenant:
from src.core.utils.tenant_utils import serialize_tenant_to_dict

return serialize_tenant_to_dict(tenant)
return None
except Exception as e:
# If table doesn't exist or other DB errors, return None
if "no such table" in str(e) or "does not exist" in str(e):
return None
raise


def get_tenant_by_virtual_host(virtual_host: str) -> dict[str, Any] | None:
"""Get tenant by virtual host."""
try:
Expand Down
9 changes: 8 additions & 1 deletion src/core/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
# Other imports
from src.core.config_loader import (
get_current_tenant,
get_tenant_by_id,
get_tenant_by_subdomain,
get_tenant_by_virtual_host,
load_config,
Expand Down Expand Up @@ -405,7 +406,13 @@ def get_principal_from_context(context: Context | None) -> str | None:
# Fallback: assume it's already a tenant_id
requested_tenant_id = tenant_hint
detection_method = "x-adcp-tenant header (direct)"
console.print(f"[yellow]Using x-adcp-tenant as tenant_id directly: {requested_tenant_id}[/yellow]")
# Need to look up and set tenant context
tenant_context = get_tenant_by_id(tenant_hint)
if tenant_context:
set_current_tenant(tenant_context)
console.print(f"[green]Tenant context set for tenant_id: {requested_tenant_id}[/green]")
else:
console.print(f"[yellow]Using x-adcp-tenant as tenant_id directly: {requested_tenant_id}[/yellow]")

# 3. Check Apx-Incoming-Host header (for Approximated.app virtual hosts)
if not requested_tenant_id:
Expand Down
62 changes: 0 additions & 62 deletions test_webhook_url.py

This file was deleted.