Files
dify/api/services/auth/api_key_contracts.py
T
fd2db63184 feat: KnowledgeFS and New Knowledge (#44165)
Co-authored-by: Jyong <76649700+JohnJyong@users.noreply.github.com>
Co-authored-by: hjlarry <hjlarry@163.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
Co-authored-by: zhaohao1004 <zhaohao1004@gmail.com>
Co-authored-by: yyh <yuanyouhuilyz@gmail.com>
Co-authored-by: FFXN <lizy@dify.ai>
2026-10-23 03:34:59 +00:00

35 lines
893 B
Python

"""Framework-neutral data contracts for API key management."""
from dataclasses import dataclass
from datetime import datetime
from typing import Protocol
@dataclass(frozen=True, slots=True)
class ApiKeyRecord:
id: str
type: str
token: str
last_used_at: datetime | None = None
created_at: datetime | None = None
dataset_ids: tuple[str, ...] = ()
knowledge_space_ids: tuple[str, ...] = ()
class ApiKeyCache(Protocol):
def delete(self, token: str, scope: str | None = None) -> bool | None: ...
class ApiKeyResourceNotFoundError(Exception):
pass
class ApiKeyNotFoundError(Exception):
def __init__(self) -> None:
super().__init__("API key not found")
class ApiKeyLimitExceededError(Exception):
def __init__(self, max_keys: int) -> None:
super().__init__(f"Cannot create more than {max_keys} API keys for this resource type.")