Simplify pending setup secrets

This commit is contained in:
StasonJatham committed 2026-05-21 18:30:15 +02:00
1 parent 5fee087b60
commit 8f07bbde84
6 files changed
+29 -23

No files matched your search

+5 -6
View File
@@ -1,17 +1,16 @@
from __future__ import annotations
import secrets
from datetime import UTC, datetime
from ..security import hash_lookup_token, hash_secret, verify_secret
from ..security import hash_lookup_token, hash_secret, new_bearer_secret, verify_secret
from .types import AccountRow
class AccountsMixin:
def create_account(self, hostname: str, username: str | None = None, *, accepted: bool = True) -> AccountRow:
now = datetime.now(UTC).isoformat()
update_slug = secrets.token_urlsafe(32)
management_slug = secrets.token_urlsafe(32)
update_slug = new_bearer_secret()
management_slug = new_bearer_secret()
management_hash = hash_lookup_token(management_slug)
accepted_at = now if accepted else None
with self.connect() as conn:
@@ -103,13 +102,13 @@ class AccountsMixin:
conn.execute("DELETE FROM records WHERE hostname = ?", (hostname,))
def rotate_update_slug(self, hostname: str) -> AccountRow | None:
update_slug = secrets.token_urlsafe(32)
update_slug = new_bearer_secret()
with self.connect() as conn:
conn.execute("UPDATE accounts SET update_slug = ? WHERE hostname = ?", (update_slug, hostname))
return self.get_account_by_hostname(hostname)
def rotate_management_slug(self, hostname: str) -> AccountRow | None:
management_slug = secrets.token_urlsafe(32)
management_slug = new_bearer_secret()
management_hash = hash_lookup_token(management_slug)
with self.connect() as conn:
conn.execute("UPDATE accounts SET management_hash = ? WHERE hostname = ?", (management_hash, hostname))