|
@@ -1,6 +1,7 @@
|
|
|
from __future__ import annotations
|
|
from __future__ import annotations
|
|
|
|
|
|
|
|
import json
|
|
import json
|
|
|
|
|
+import secrets
|
|
|
from datetime import datetime, timezone
|
|
from datetime import datetime, timezone
|
|
|
from sqlite3 import IntegrityError
|
|
from sqlite3 import IntegrityError
|
|
|
from uuid import uuid4
|
|
from uuid import uuid4
|
|
@@ -80,8 +81,18 @@ def get_account_secrets(account_id: str) -> dict:
|
|
|
return {"api_key": row["api_key"], "api_secret": row["api_secret"]}
|
|
return {"api_key": row["api_key"], "api_secret": row["api_secret"]}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _generate_account_id(length: int = 12) -> str:
|
|
|
|
|
+ alphabet = "abcdefghijklmnopqrstuvwxyz0123456789"
|
|
|
|
|
+ while True:
|
|
|
|
|
+ candidate = "".join(secrets.choice(alphabet) for _ in range(length))
|
|
|
|
|
+ with get_connection() as conn:
|
|
|
|
|
+ exists = conn.execute("SELECT 1 FROM accounts WHERE id = ?", (candidate,)).fetchone()
|
|
|
|
|
+ if exists is None:
|
|
|
|
|
+ return candidate
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
def create_account(*, display_name: str, venue: str, venue_account_ref: str, api_key: str, api_secret: str, description: str | None = None, enabled: bool = True) -> dict:
|
|
def create_account(*, display_name: str, venue: str, venue_account_ref: str, api_key: str, api_secret: str, description: str | None = None, enabled: bool = True) -> dict:
|
|
|
- account_id = str(uuid4())
|
|
|
|
|
|
|
+ account_id = _generate_account_id()
|
|
|
now = utc_now_iso()
|
|
now = utc_now_iso()
|
|
|
with get_connection() as conn:
|
|
with get_connection() as conn:
|
|
|
try:
|
|
try:
|