27 lines
828 B
Python
27 lines
828 B
Python
from datetime import datetime
|
|
from typing import Optional, ClassVar
|
|
from pydantic import BaseModel, Field
|
|
from bson import ObjectId
|
|
|
|
from src.models.team import PyObjectId
|
|
|
|
class ApiKeyModel(BaseModel):
|
|
"""Database model for an API key"""
|
|
id: Optional[PyObjectId] = Field(default_factory=PyObjectId, alias="_id")
|
|
key_hash: str
|
|
user_id: PyObjectId
|
|
team_id: PyObjectId
|
|
name: str
|
|
description: Optional[str] = None
|
|
created_at: datetime = Field(default_factory=datetime.utcnow)
|
|
expiry_date: Optional[datetime] = None
|
|
last_used: Optional[datetime] = None
|
|
is_active: bool = True
|
|
|
|
model_config: ClassVar[dict] = {
|
|
"populate_by_name": True,
|
|
"arbitrary_types_allowed": True,
|
|
"json_encoders": {
|
|
ObjectId: str
|
|
}
|
|
} |