plugin_host_http_auth.py 852 B

1234567891011121314151617181920212223
  1. """Carry route-local admission over the private plugin-host channel, without credentials."""
  2. from fastapi import HTTPException
  3. def admitted_for_sensitive_route(request) -> bool:
  4. """Preserve the normal guard's decision without changing unguarded plugin routes."""
  5. from hermes_cli.web_server import _require_token
  6. try:
  7. _require_token(request)
  8. except HTTPException as exc:
  9. if exc.status_code != 401:
  10. raise
  11. return False
  12. return True
  13. def with_hosted_admission(app, authenticated):
  14. """Admission belongs to this IPC request, never to the cached plugin app."""
  15. async def scoped(scope, receive, send):
  16. state = dict(scope.get("state") or {})
  17. state["hosted_http_authenticated"] = authenticated is True
  18. await app({**scope, "state": state}, receive, send)
  19. return scoped