Validate AVConnect credentials on saving. Improved AVConnect login method. Fixed issue with UTC datetimes

This commit is contained in:
Ettore
2026-05-09 18:18:10 +02:00
parent 69e4f594de
commit 0cb35a30cb
8 changed files with 60 additions and 16 deletions

View File

@@ -7,6 +7,7 @@ from typing import Optional
from fastapi import APIRouter, Depends, HTTPException
from sqlalchemy.orm import Session
from core.config import utcnow
from core.database import Keypass, get_db
from core.dependencies import require_manager
from core.schemas import KeypassCreate, KeypassPatch, KeypassResponse, keypass_to_response
@@ -38,7 +39,7 @@ async def create_keypass(
kp = Keypass(
code=code,
description=req.description,
created_at=datetime.now(timezone.utc),
created_at=utcnow(),
expires_at=req.expires_at,
revoked=False,
allowed_gates=json.dumps(req.gate_ids) if req.gate_ids else None,
@@ -80,10 +81,10 @@ async def revoke_keypass(
kp: Optional[Keypass] = db.query(Keypass).filter(Keypass.id == kp_id).first()
if not kp:
raise HTTPException(404, "Keypass not found")
if kp.expires_at is not None and kp.expires_at < datetime.now(timezone.utc):
if kp.expires_at is not None and kp.expires_at < utcnow():
raise HTTPException(409, "Expired keypasses cannot be revoked")
if kp.revoked:
raise HTTPException(409, "Keypass is already revoked")
kp.revoked = True
kp.revoked_at = datetime.now(timezone.utc)
kp.revoked_at = utcnow()
db.commit()