Files
bambuddy/backend/app/models/api_key.py
T
maziggy 83cbac04b7 - Add interactive API Browser to Settings > API Keys
- New APIBrowser component with full OpenAPI schema integration
    - Fetches and parses /openapi.json automatically
    - Groups endpoints by API tags (printers, archives, settings, etc.)
    - Expandable endpoint sections with color-coded method badges
    - Path parameter, query parameter, and JSON body editors
    - Auto-populates request body with schema examples
    - Live API request execution with response display
    - Response shows status code, timing, and formatted JSON
    - Copy response button with clipboard fallback
    - Search to filter endpoints across all categories
    - Expand All / Collapse All buttons
    - Link to Swagger UI (/docs)

  - Two-column layout for API Keys tab
    - Left: API key management + webhook documentation
    - Right: API Browser with dedicated test key input

  - Parameter validation
    - Shows warning for missing required parameters
    - Validates before sending requests to avoid 422 errors

  - UX improvements
    - "Use in API Browser" button on newly created keys
    - Responsive layout (stacked on mobile, side-by-side on xl+)
2026-01-02 15:00:21 +01:00

31 lines
1.3 KiB
Python

from datetime import datetime
from sqlalchemy import JSON, Boolean, DateTime, String, func
from sqlalchemy.orm import Mapped, mapped_column
from backend.app.core.database import Base
class APIKey(Base):
"""API key for external webhook access."""
__tablename__ = "api_keys"
id: Mapped[int] = mapped_column(primary_key=True)
name: Mapped[str] = mapped_column(String(100)) # User-friendly name
key_hash: Mapped[str] = mapped_column(String(64)) # SHA256 hash of the key
key_prefix: Mapped[str] = mapped_column(String(8)) # First 8 chars for identification
# Permissions
can_queue: Mapped[bool] = mapped_column(Boolean, default=True) # Add to queue
can_control_printer: Mapped[bool] = mapped_column(Boolean, default=False) # Start/stop/cancel
can_read_status: Mapped[bool] = mapped_column(Boolean, default=True) # Query status
# Optional scope limits
printer_ids: Mapped[list | None] = mapped_column(JSON, nullable=True) # null = all printers
enabled: Mapped[bool] = mapped_column(Boolean, default=True)
last_used: Mapped[datetime | None] = mapped_column(DateTime, nullable=True)
created_at: Mapped[datetime] = mapped_column(DateTime, server_default=func.now())
expires_at: Mapped[datetime | None] = mapped_column(DateTime, nullable=True) # Optional expiry