Refactoring to eliminate models. Moved to SQLAlchemy Mapped annotations
This commit is contained in:
@@ -8,7 +8,6 @@ from sqlalchemy.orm import Session
|
||||
from core.auth import decrypt_secret
|
||||
from core.database import ApiCredential, GateAccessLog, GateDB, Keypass, get_db
|
||||
from core.dependencies import require_admin, require_manager, require_keypass
|
||||
from models import Credential, Gate as GateModel, Status
|
||||
from core.schemas import GateCreate, GateResponse
|
||||
from services.gates import call_open_gate
|
||||
|
||||
@@ -86,17 +85,15 @@ async def admin_open_gate(
|
||||
if not cred_db:
|
||||
raise HTTPException(503, "AVConnect credentials not configured")
|
||||
|
||||
credential = Credential(
|
||||
username=cred_db.username,
|
||||
password=decrypt_secret(cred_db.password_enc),
|
||||
)
|
||||
credential.sessionid = cred_db.session_id
|
||||
|
||||
gate = GateModel(id=gate_db.avconnect_macro_id, name=gate_db.name, status=Status.ENABLED)
|
||||
ip = request.headers.get("X-Forwarded-For", request.client.host if request.client else None)
|
||||
ua = request.headers.get("User-Agent")
|
||||
|
||||
success, error_msg, new_sid = call_open_gate(gate, credential)
|
||||
success, error_msg, new_sid = call_open_gate(
|
||||
gate_db.avconnect_macro_id,
|
||||
cred_db.username,
|
||||
decrypt_secret(cred_db.password_enc),
|
||||
cred_db.session_id,
|
||||
)
|
||||
|
||||
db.add(GateAccessLog(
|
||||
timestamp=datetime.utcnow(),
|
||||
@@ -150,14 +147,6 @@ async def open_gate(
|
||||
if not cred_db:
|
||||
raise HTTPException(503, "AVConnect credentials not configured")
|
||||
|
||||
credential = Credential(
|
||||
username=cred_db.username,
|
||||
password=decrypt_secret(cred_db.password_enc),
|
||||
)
|
||||
credential.sessionid = cred_db.session_id
|
||||
|
||||
gate_status = Status.ENABLED if gate_db.status == "enabled" else Status.DISABLED
|
||||
gate = GateModel(id=gate_db.avconnect_macro_id, name=gate_db.name, status=gate_status)
|
||||
ip = request.headers.get("X-Forwarded-For", request.client.host if request.client else None)
|
||||
ua = request.headers.get("User-Agent")
|
||||
|
||||
@@ -165,7 +154,12 @@ async def open_gate(
|
||||
if allowed is not None and gate_id not in allowed:
|
||||
raise HTTPException(403, "This keypass does not have access to this gate")
|
||||
|
||||
success, error_msg, new_sid = call_open_gate(gate, credential)
|
||||
success, error_msg, new_sid = call_open_gate(
|
||||
gate_db.avconnect_macro_id,
|
||||
cred_db.username,
|
||||
decrypt_secret(cred_db.password_enc),
|
||||
cred_db.session_id,
|
||||
)
|
||||
|
||||
db.add(GateAccessLog(
|
||||
timestamp=datetime.utcnow(),
|
||||
|
||||
Reference in New Issue
Block a user