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:
parent
dd6caf4f99
commit
a94603b6cc
1 changed files with 10 additions and 2 deletions
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue