auth: Force keyword-argument passing to __init__()
Expecting possible confusion regarding further base class gymnastics, e.g. multiple inheritance, make it impossible to pass constructor arguments to User and Group as blank positional arguments, force passing the argument names instead by adding "*" as first argument. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
d73d921885
commit
dd6caf4f99
3 changed files with 24 additions and 12 deletions
|
|
@ -24,6 +24,9 @@ class ProjectFlags(Flag): # export
|
|||
|
||||
class AuthEntity(abc.ABC): # export
|
||||
|
||||
def __init__(self, **kwargs) -> None:
|
||||
super().__init__(**kwargs)
|
||||
|
||||
@abc.abstractmethod
|
||||
def _name(self) -> str:
|
||||
...
|
||||
|
|
@ -48,11 +51,17 @@ class AuthEntity(abc.ABC): # export
|
|||
|
||||
class Group(AuthEntity): # export
|
||||
|
||||
def __init__(self, **kwargs) -> None:
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def __repr__(self):
|
||||
return f'Group({self.name})'
|
||||
|
||||
class User(AuthEntity): # export
|
||||
|
||||
def __init__(self, **kwargs) -> None:
|
||||
super().__init__(**kwargs)
|
||||
|
||||
def __repr__(self):
|
||||
return f'User({self.name})'
|
||||
|
||||
|
|
|
|||
|
|
@ -16,7 +16,8 @@ if TYPE_CHECKING:
|
|||
|
||||
class Group(GroupBase): # export
|
||||
|
||||
def __init__(self, auth: AuthBase, name: str):
|
||||
def __init__(self, *, auth: AuthBase, name: str, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.__name = name
|
||||
self.__auth = auth
|
||||
|
||||
|
|
@ -25,7 +26,8 @@ class Group(GroupBase): # export
|
|||
|
||||
class User(UserBase): # export
|
||||
|
||||
def __init__(self, auth: AuthBase, name: str, conf: Config):
|
||||
def __init__(self, *, auth: AuthBase, name: str, conf: Config, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.__name = name
|
||||
self.__conf = conf
|
||||
self.__auth = auth
|
||||
|
|
@ -44,7 +46,7 @@ class User(UserBase): # export
|
|||
name: str = ''
|
||||
ret: list[GroupBase] = []
|
||||
for name in self.conf['groups']:
|
||||
ret.append(Group(self.__auth, name))
|
||||
ret.append(Group(auth = self.__auth, name = name))
|
||||
self.__groups = ret
|
||||
return self.__groups
|
||||
|
||||
|
|
@ -53,8 +55,8 @@ class User(UserBase): # export
|
|||
|
||||
class Auth(AuthBase): # export
|
||||
|
||||
def __init__(self, conf: Config):
|
||||
super().__init__(conf)
|
||||
def __init__(self, *, conf: Config, **kwargs):
|
||||
super().__init__(conf, **kwargs)
|
||||
self.___users: dict[str, UserBase] | None = None
|
||||
self.__groups = None
|
||||
self.__current_user: UserBase | None = None
|
||||
|
|
@ -67,7 +69,7 @@ class Auth(AuthBase): # export
|
|||
for name in self.conf.entries('user'):
|
||||
conf = self.conf.branch('user.' + name)
|
||||
assert conf is not None, 'Config is None'
|
||||
ret[name] = User(self, name, conf)
|
||||
ret[name] = User(auth = self, name = name, conf = conf)
|
||||
self.___users = ret
|
||||
return self.___users
|
||||
|
||||
|
|
|
|||
|
|
@ -19,7 +19,8 @@ if TYPE_CHECKING:
|
|||
|
||||
class Group(GroupBase): # export
|
||||
|
||||
def __init__(self, auth: AuthBase, name: str):
|
||||
def __init__(self, *, auth: AuthBase, name: str, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.__name = name
|
||||
self.__auth = auth
|
||||
|
||||
|
|
@ -28,8 +29,8 @@ class Group(GroupBase): # export
|
|||
|
||||
class User(UserBase):
|
||||
|
||||
def __init__(self, auth: AuthBase, name: str, cn: str, email: str):
|
||||
|
||||
def __init__(self, *, auth: AuthBase, name: str, cn: str, email: str, **kwargs):
|
||||
super().__init__(**kwargs)
|
||||
self.__auth = auth
|
||||
self.__name = name
|
||||
self.__cn = cn
|
||||
|
|
@ -50,8 +51,8 @@ class User(UserBase):
|
|||
|
||||
class Auth(AuthBase): # export
|
||||
|
||||
def __init__(self, conf: Config):
|
||||
super().__init__(conf)
|
||||
def __init__(self, *, conf: Config, **kwargs):
|
||||
super().__init__(conf, **kwargs)
|
||||
self.___users: dict[str, UserBase] | None = None
|
||||
self.___user_by_email: dict[str, User] | None = None
|
||||
self.__groups = None
|
||||
|
|
@ -89,7 +90,7 @@ class Auth(AuthBase): # export
|
|||
if not emails:
|
||||
slog(DEBUG, f'No email for user "{uid}", skipping')
|
||||
continue
|
||||
user = User(self, name = uid, cn = cn, email = emails[0])
|
||||
user = User(auth = self, name = uid, cn = cn, email = emails[0])
|
||||
ret[uid] = user
|
||||
for email in emails:
|
||||
ret_by_email[email] = user
|
||||
|
|
|
|||
Loading…
Reference in a new issue