45 lines
1.4 KiB
Python
45 lines
1.4 KiB
Python
|
|
"""Build placeholder value maps from TenantContext."""
|
||
|
|
|
||
|
|
from __future__ import annotations
|
||
|
|
|
||
|
|
import json
|
||
|
|
from typing import Any
|
||
|
|
|
||
|
|
from tenant_context import TenantContext
|
||
|
|
|
||
|
|
|
||
|
|
def build_tenant_context_values(ctx: TenantContext) -> dict[str, Any]:
|
||
|
|
return {
|
||
|
|
"tenant_name": ctx.tenant_name or "",
|
||
|
|
"tenant_id": ctx.tenant_id or "",
|
||
|
|
"actor_name": ctx.display_name,
|
||
|
|
"actor_id": ctx.actor_id or "",
|
||
|
|
"actor_type": ctx.actor_type or "",
|
||
|
|
"portal_role": ctx.portal_role,
|
||
|
|
"tenant_role": ctx.tenant_role or "",
|
||
|
|
"capabilities": sorted(ctx.capabilities),
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def build_actor_context_values(ctx: TenantContext) -> dict[str, Any]:
|
||
|
|
return {
|
||
|
|
"actor_id": ctx.actor_id or "",
|
||
|
|
"actor_type": ctx.actor_type or "",
|
||
|
|
"tenant_id": ctx.tenant_id or "",
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
def merge_context_values(ctx: TenantContext, context_kind: str, extra: dict[str, Any]) -> dict[str, Any]:
|
||
|
|
base: dict[str, Any] = {}
|
||
|
|
if context_kind == "kairo.tenant_context":
|
||
|
|
base = build_tenant_context_values(ctx)
|
||
|
|
elif context_kind == "kairo.actor_context":
|
||
|
|
base = build_actor_context_values(ctx)
|
||
|
|
merged = {**base, **extra}
|
||
|
|
for key, value in merged.items():
|
||
|
|
if key == "capabilities" and isinstance(value, list):
|
||
|
|
merged[key] = value
|
||
|
|
elif isinstance(value, (dict, list)) and key != "capabilities":
|
||
|
|
continue
|
||
|
|
return merged
|