mirror of
https://github.com/bunny-lab-io/Borealis.git
synced 2025-10-26 21:41:57 -06:00
Use context manager for device auth lookup
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import annotations
|
|||||||
import functools
|
import functools
|
||||||
import sqlite3
|
import sqlite3
|
||||||
import time
|
import time
|
||||||
|
from contextlib import closing
|
||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from datetime import datetime, timezone
|
from datetime import datetime, timezone
|
||||||
from typing import Any, Callable, Dict, Optional
|
from typing import Any, Callable, Dict, Optional
|
||||||
@@ -103,8 +104,7 @@ class DeviceAuthManager:
|
|||||||
|
|
||||||
context_label = _canonical_context(request.headers.get(AGENT_CONTEXT_HEADER))
|
context_label = _canonical_context(request.headers.get(AGENT_CONTEXT_HEADER))
|
||||||
|
|
||||||
conn = self._db_conn_factory()
|
with closing(self._db_conn_factory()) as conn:
|
||||||
try:
|
|
||||||
cur = conn.cursor()
|
cur = conn.cursor()
|
||||||
cur.execute(
|
cur.execute(
|
||||||
"""
|
"""
|
||||||
@@ -120,8 +120,6 @@ class DeviceAuthManager:
|
|||||||
row = self._recover_device_record(
|
row = self._recover_device_record(
|
||||||
conn, guid, fingerprint, token_version, context_label
|
conn, guid, fingerprint, token_version, context_label
|
||||||
)
|
)
|
||||||
finally:
|
|
||||||
conn.close()
|
|
||||||
|
|
||||||
if not row:
|
if not row:
|
||||||
raise DeviceAuthError("device_not_found", status_code=403)
|
raise DeviceAuthError("device_not_found", status_code=403)
|
||||||
|
|||||||
Reference in New Issue
Block a user