Phase 4: cloud backend — licensing, heartbeat, site management

- New cloud_backend/ FastAPI service on port 8001 (SQLite for dev, swappable to PostgreSQL)
- Endpoints: sysadmin auth (JWT), site registration, lock/unlock, heartbeat (X-Site-ID + X-Site-Key headers)
- Default sysadmin seeded on first startup from ADMIN_USERNAME/ADMIN_PASSWORD env vars
- cloud_backend added to docker-compose.yml with persistent data volume at ./data/cloud/
- local_backend cloud_sync.py updated to use correct /api/heartbeat/ endpoint with header auth
- local_backend config.py: added SITE_KEY setting
- Smoke tested: login, register site, heartbeat, lock, unlock, list all pass
This commit is contained in:
2026-04-20 19:05:14 +03:00
parent 10b44d9a1a
commit 9812a25198
20 changed files with 421 additions and 2 deletions

View File

@@ -0,0 +1,18 @@
from fastapi import APIRouter, Depends, HTTPException, status
from sqlalchemy.orm import Session
from auth_utils import verify_password, create_access_token
from database import get_db
from models.admin import Admin
from schemas.admin import LoginRequest, TokenOut
router = APIRouter()
@router.post("/login", response_model=TokenOut)
def login(body: LoginRequest, db: Session = Depends(get_db)):
admin = db.query(Admin).filter(Admin.username == body.username).first()
if not admin or not verify_password(body.password, admin.password_hash):
raise HTTPException(status_code=status.HTTP_401_UNAUTHORIZED, detail="Invalid credentials")
token = create_access_token({"sub": admin.username, "role": admin.role})
return TokenOut(access_token=token)