mirror of
https://github.com/All-Hands-AI/OpenHands.git
synced 2026-04-29 03:00:45 -04:00
35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from datetime import datetime
|
|
from typing import TYPE_CHECKING
|
|
from uuid import UUID
|
|
|
|
from sqlalchemy import DateTime, ForeignKey, String, text
|
|
from sqlalchemy.orm import Mapped, mapped_column, relationship
|
|
from storage.base import Base
|
|
|
|
if TYPE_CHECKING:
|
|
from storage.org import Org
|
|
|
|
|
|
class ApiKey(Base):
|
|
"""
|
|
Represents an API key for a user.
|
|
"""
|
|
|
|
__tablename__ = 'api_keys'
|
|
|
|
id: Mapped[int] = mapped_column(primary_key=True, autoincrement=True)
|
|
key: Mapped[str] = mapped_column(
|
|
String(255), nullable=False, unique=True, index=True
|
|
)
|
|
user_id: Mapped[str] = mapped_column(String(255), nullable=False, index=True)
|
|
org_id: Mapped[UUID | None] = mapped_column(ForeignKey('org.id'), nullable=True)
|
|
name: Mapped[str | None] = mapped_column(String(255), nullable=True)
|
|
created_at: Mapped[datetime] = mapped_column(
|
|
DateTime, server_default=text('CURRENT_TIMESTAMP'), nullable=False
|
|
)
|
|
last_used_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
expires_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
|
|
|
|
# Relationships
|
|
org: Mapped['Org | None'] = relationship('Org', back_populates='api_keys')
|