auth.Auth.load(): Support dict and StringTree

Auth objects can currently be loaded dynamically with a Config type
argument. For greater flexibility, allow to pass dict and StringTree
mappings to load(), too.

Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-07-13 13:54:52 +02:00 • committed by janware DevOps
commit a94603b6cc
Signed by: DevOps
SSH key fingerprint: SHA256:cZiw7ExG5q3KAVm7Jse3rGITowu0VjgUgNMPbifmY8g

View file

@ -3,13 +3,17 @@ from __future__ import annotations
import abc
from enum import Enum, Flag, auto
from typing import TYPE_CHECKING, Self, Sequence
from typing import TYPE_CHECKING
from ..log import ERR
from ..misc import load_object
if TYPE_CHECKING:
from typing import Any, Self, Sequence
from ..Config import Config
from ..stree.StringTree import StringTree
class Access(Enum): # export
Read = auto()
@ -80,7 +84,11 @@ class User(AuthEntity): # export
class Auth(abc.ABC): # export
@classmethod
def load(cls, conf: Config, tp: str = '') -> Self:
def load(cls, conf: Config | dict[str, Any] | StringTree, tp: str = '') -> Self:
if isinstance(conf, dict):
conf = StringTree.from_dict(conf)
if isinstance(conf, StringTree):
conf = Config(tree = conf)
if tp == '':
val = conf.get('type')
if val is None: