- Add ApiKey model, migration (028), CRUD endpoints (/admin/api-keys/) - get_current_user_or_api_key dependency: JWT Bearer or X-API-Key header - Agent execute endpoint now accepts API keys (super_admin only to create) - ApiKeysTab UI: list, create (one-time key reveal), revoke, delete - Wired ApiKeysTab into admin page (super_admin only) - Add /admin/code-interpreter page with iframe to LibreCodeInterpreter dashboard - Expose code-interpreter on 127.0.0.1:8100 for Apache proxy - deploy.sh: note Apache proxy rule for /nexus-code-interpreter/ Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
28 lines
1.3 KiB
Python
28 lines
1.3 KiB
Python
"""
|
|
API Key model for programmatic access to the agent execution endpoint.
|
|
|
|
Keys are stored as SHA-256 hashes — the raw key is shown once on creation
|
|
and never stored in plaintext.
|
|
"""
|
|
from sqlalchemy import Column, String, Boolean, DateTime, ForeignKey, Text
|
|
from sqlalchemy.dialects.postgresql import UUID
|
|
from sqlalchemy.orm import relationship
|
|
from app.database import Base
|
|
import uuid
|
|
from datetime import datetime
|
|
|
|
|
|
class ApiKey(Base):
|
|
__tablename__ = "api_keys"
|
|
|
|
id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
|
|
name = Column(String(100), nullable=False) # human label
|
|
key_prefix = Column(String(12), nullable=False) # first 8 chars of raw key, shown for identification
|
|
key_hash = Column(String(64), nullable=False, unique=True, index=True) # SHA-256 hex of full raw key
|
|
created_by = Column(UUID(as_uuid=True), ForeignKey("users.id", ondelete="SET NULL"), nullable=True)
|
|
is_active = Column(Boolean, default=True, nullable=False)
|
|
last_used_at = Column(DateTime, nullable=True)
|
|
created_at = Column(DateTime, default=datetime.utcnow, nullable=False)
|
|
updated_at = Column(DateTime, default=datetime.utcnow, onupdate=datetime.utcnow, nullable=False)
|
|
|
|
creator = relationship("User", foreign_keys=[created_by])
|