| 12345678910111213141516171819202122232425 |
- """
- API密钥模型
- """
- from datetime import datetime
- from app.utils.timezone import beijing_now_naive
- from sqlalchemy import Column, Integer, String, DateTime, Boolean, Text
- from app.database import Base
- class APIKey(Base):
- """API密钥表"""
- __tablename__ = "api_keys"
-
- id = Column(Integer, primary_key=True, autoincrement=True, comment="主键ID")
- public_key = Column(Text, nullable=False, comment="RSA公钥(PEM格式)")
- private_key = Column(Text, nullable=False, comment="RSA私钥(PEM格式,加密存储)")
- key_version = Column(Integer, nullable=False, comment="密钥版本号")
- is_active = Column(Boolean, default=True, comment="是否激活: 1-激活, 0-非激活")
- is_deleted = Column(Boolean, default=False, comment="是否删除: 0-否, 1-是")
- created_at = Column(DateTime, default=beijing_now_naive, comment="创建时间")
- expire_at = Column(DateTime, nullable=True, comment="过期时间(创建时间+10天)")
- updated_at = Column(DateTime, nullable=True, comment="更新时间")
-
- def __repr__(self):
- return f"<APIKey(id={self.id}, key_version={self.key_version}, is_active={self.is_active})>"
|