first
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
"""Extrakce per-request přihlašovacích údajů z X- hlaviček.
|
||||
|
||||
Secrets (API klíče) chodí VÝHRADNĚ v hlavičkách, nikdy v těle requestu ani v URL.
|
||||
Nic se neukládá — služba je stateless.
|
||||
"""
|
||||
from dataclasses import dataclass
|
||||
|
||||
from fastapi import Header
|
||||
|
||||
from .errors import CredentialsError
|
||||
|
||||
|
||||
@dataclass
|
||||
class Credentials:
|
||||
deepgram_api_key: str | None
|
||||
openai_api_key: str | None
|
||||
|
||||
def require_deepgram(self) -> str:
|
||||
if not self.deepgram_api_key or not self.deepgram_api_key.strip():
|
||||
raise CredentialsError("Chybí hlavička X-Deepgram-Api-Key.")
|
||||
return self.deepgram_api_key.strip()
|
||||
|
||||
def require_openai(self) -> str:
|
||||
if not self.openai_api_key or not self.openai_api_key.strip():
|
||||
raise CredentialsError("Chybí hlavička X-OpenAI-Api-Key.")
|
||||
return self.openai_api_key.strip()
|
||||
|
||||
|
||||
def get_credentials(
|
||||
x_deepgram_api_key: str | None = Header(
|
||||
default=None,
|
||||
alias="X-Deepgram-Api-Key",
|
||||
description="Deepgram API klíč (secret). Nutný pro Deepgram přepis.",
|
||||
),
|
||||
x_openai_api_key: str | None = Header(
|
||||
default=None,
|
||||
alias="X-OpenAI-Api-Key",
|
||||
description="OpenAI API klíč (secret). Nutný pro Whisper přepis a slučovací chat.",
|
||||
),
|
||||
) -> Credentials:
|
||||
return Credentials(
|
||||
deepgram_api_key=x_deepgram_api_key,
|
||||
openai_api_key=x_openai_api_key,
|
||||
)
|
||||
Reference in New Issue
Block a user