Merge Conflicts (#41)
Some checks failed
Production Readiness / backend-contracts (push) Failing after 1m47s
Production Readiness / webos-typecheck (push) Successful in 1m57s
Production Readiness / ipad-parse (push) Successful in 1m32s

Co-authored-by: Sayan Datta <sayan@Sayans-MacBook-Air.local>
Reviewed-on: #41
This commit was merged in pull request #41.
This commit is contained in:
2026-04-28 11:32:56 +05:30
parent 61258978e1
commit 7ee51543d9
158 changed files with 23889 additions and 87196 deletions

View File

@@ -0,0 +1,49 @@
from __future__ import annotations
import os
from typing import Mapping
_SUPPORTED_ENV_KEYS = (
"DREAM_WEAVER_GATEWAY_API_KEY",
"DREAM_WEAVER_API_KEY",
)
def load_gateway_api_key(env: Mapping[str, str] | None = None) -> str | None:
values = env if env is not None else os.environ
for key in _SUPPORTED_ENV_KEYS:
raw = values.get(key)
if raw is None:
continue
trimmed = raw.strip()
if trimmed:
return trimmed
return None
def extract_gateway_api_key(headers: Mapping[str, str]) -> str | None:
for header_name in ("x-dream-weaver-api-key", "x-api-key"):
value = headers.get(header_name)
if value:
trimmed = value.strip()
if trimmed:
return trimmed
authorization = headers.get("authorization", "")
if authorization.lower().startswith("bearer "):
token = authorization[7:].strip()
if token:
return token
return None
def is_gateway_request_authorized(
headers: Mapping[str, str],
required_api_key: str | None,
) -> bool:
if required_api_key is None:
return True
presented = extract_gateway_api_key(headers)
return presented == required_api_key