Spaces:
Running
Running
Download app/security/context.py from basyx/Whisper: direct link, hf CLI and curl.
- Browser
- Download file 1.04 kB
-
https://huggingface.co/spaces/basyx/Whisper/resolve/main/app/security/context.py
- Command line
-
hf download hf://spaces/basyx/Whisper/app/security/context.py
-
curl -L -o context.py https://huggingface.co/spaces/basyx/Whisper/resolve/main/app/security/context.py
1.04 kB
| from __future__ import annotations | |
| import contextvars | |
| from dataclasses import dataclass | |
| from datetime import datetime | |
| class AuthContext: | |
| api_key_id: str | |
| key_name: str | |
| key_prefix: str | |
| environment: str | |
| role: str | None | |
| scopes: frozenset[str] | |
| requests_per_minute: int | |
| concurrent_jobs: int | |
| uploads_per_hour: int | |
| processing_bytes_per_day: int | |
| expires_at: datetime | None | |
| def allows(self, required_scope: str) -> bool: | |
| return "admin" in self.scopes or required_scope in self.scopes | |
| auth_context: contextvars.ContextVar[AuthContext | None] = contextvars.ContextVar( | |
| "auth_context", default=None | |
| ) | |
| # HTTP authentication already applies request and concurrency limits before the | |
| # MCP ASGI application runs. Standalone stdio MCP calls use this marker to apply | |
| # the same limiter exactly once inside the transport-neutral registry. | |
| http_auth_applied: contextvars.ContextVar[bool] = contextvars.ContextVar( | |
| "http_auth_applied", default=False | |
| ) | |