Create super user account if it does not exist (#1688)
* fix: temp create account for `super_user_id` if missing * chore: remove dumb import * refactor: move logic outside `crud` * feat: add uuid4 conversion * fix: require valid string in .env file * fix: update the `settings.super_user` value in case or normalisation for UUID4 * fix: allow long super_user * chore: code format * fix: add UI redirect with the normalized user * fix: normalize `super_user` up one level * fix: should normalize user in non-ui mode also
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import importlib
|
||||
import re
|
||||
from typing import Any
|
||||
from uuid import UUID
|
||||
|
||||
import httpx
|
||||
from loguru import logger
|
||||
@@ -63,3 +64,14 @@ async def stop_extension_background_work(ext_id: str, user: str):
|
||||
url = f"https://{settings.host}:{settings.port}/{ext_id}/api/v1?usr={user}"
|
||||
except Exception as ex:
|
||||
logger.warning(ex)
|
||||
|
||||
|
||||
def to_valid_user_id(user_id: str) -> UUID:
|
||||
if len(user_id) < 32:
|
||||
raise ValueError("User ID must have at least 128 bits")
|
||||
try:
|
||||
int(user_id, 16)
|
||||
except:
|
||||
raise ValueError("Invalid hex string for User ID.")
|
||||
|
||||
return UUID(hex=user_id[:32], version=4)
|
||||
|
||||
Reference in New Issue
Block a user