api_key.py 1.1 KB

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