feat(db): add get_active_lease_by_token helper to accounts_repo
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -733,6 +733,36 @@ def cleanup_expired_leases() -> int:
|
|||||||
conn.close()
|
conn.close()
|
||||||
|
|
||||||
|
|
||||||
|
def get_active_lease_by_token(conn, lease_token: str) -> Optional[dict[str, Any]]:
|
||||||
|
"""Look up a lease by token: active and not expired.
|
||||||
|
|
||||||
|
Returns dict with id, account_id, lease_token, holder, purpose, expires_at (Unix sec),
|
||||||
|
status; or None if not found / inactive / expired.
|
||||||
|
"""
|
||||||
|
cur = conn.cursor()
|
||||||
|
now = _now_unix()
|
||||||
|
cur.execute(
|
||||||
|
"""
|
||||||
|
SELECT id, account_id, lease_token, holder, purpose, expires_at, status
|
||||||
|
FROM account_leases
|
||||||
|
WHERE lease_token = ? AND status = 'active' AND expires_at > ?
|
||||||
|
""",
|
||||||
|
(lease_token, now),
|
||||||
|
)
|
||||||
|
row = cur.fetchone()
|
||||||
|
if not row:
|
||||||
|
return None
|
||||||
|
return {
|
||||||
|
"id": row[0],
|
||||||
|
"account_id": row[1],
|
||||||
|
"lease_token": row[2],
|
||||||
|
"holder": row[3],
|
||||||
|
"purpose": row[4],
|
||||||
|
"expires_at": int(row[5]),
|
||||||
|
"status": row[6],
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
# Internal helpers
|
# Internal helpers
|
||||||
# ============================================================================
|
# ============================================================================
|
||||||
|
|||||||
Reference in New Issue
Block a user