mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-08-09 04:40:57 +00:00
chore(merge): sync master into dev/4.11.x
This commit is contained in:
@@ -18,6 +18,8 @@ from hypercorn.config import Config
|
||||
from quart import Quart
|
||||
|
||||
from langbot.pkg.api.mcp.mount import MCPMount
|
||||
from langbot.pkg.api.http.authz import Permission
|
||||
from langbot.pkg.api.http.service.apikey import ApiKeyIdentity
|
||||
|
||||
PORT = 5399
|
||||
GLOBAL_KEY = 'test-global-key-123'
|
||||
@@ -31,11 +33,26 @@ def build_ap() -> SimpleNamespace:
|
||||
ap.ver_mgr = SimpleNamespace(get_current_version=lambda: '4.5.0-test')
|
||||
ap.logger = SimpleNamespace(info=print, error=print, warning=print)
|
||||
|
||||
# API key verification: reuse real logic shape (global key match)
|
||||
async def verify_api_key(key: str) -> bool:
|
||||
return bool(key) and key == GLOBAL_KEY
|
||||
# API key authentication derives the trusted Workspace carried into tools.
|
||||
async def authenticate_api_key(key: str) -> ApiKeyIdentity | None:
|
||||
if key != GLOBAL_KEY:
|
||||
return None
|
||||
return ApiKeyIdentity(
|
||||
instance_uuid='inst-1',
|
||||
workspace_uuid='workspace-1',
|
||||
placement_generation=1,
|
||||
api_key_uuid='global-test-key',
|
||||
permissions=frozenset(permission.value for permission in Permission),
|
||||
)
|
||||
|
||||
ap.apikey_service = SimpleNamespace(verify_api_key=verify_api_key)
|
||||
ap.apikey_service = SimpleNamespace(authenticate_api_key=authenticate_api_key)
|
||||
|
||||
@contextlib.asynccontextmanager
|
||||
async def tenant_scope(workspace_uuid: str):
|
||||
assert workspace_uuid == 'workspace-1'
|
||||
yield
|
||||
|
||||
ap.persistence_mgr = SimpleNamespace(tenant_scope=tenant_scope)
|
||||
ap.bot_service = SimpleNamespace(
|
||||
get_bots=AsyncMock(return_value=[{'uuid': 'bot-1', 'name': 'Demo Bot', 'adapter': 'telegram'}]),
|
||||
list_event_route_statuses=AsyncMock(return_value={'routes': [], 'unmatched_events': [], 'stale_routes': []}),
|
||||
|
||||
Reference in New Issue
Block a user