Makefile: Include py-topdir.mk
Include py-topdir.mk, which entails loads of fallout from make check. Fix it. Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
7212850b22
commit
e9845b5a1f
3 changed files with 1796 additions and 1191 deletions
|
|
@ -1,27 +1,28 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from typing import Optional, Union, Self
|
||||
from __future__ import annotations
|
||||
|
||||
import abc
|
||||
|
||||
from enum import Flag, Enum, auto
|
||||
from enum import Enum, Flag, auto
|
||||
from typing import TYPE_CHECKING, Optional, Self, Union
|
||||
|
||||
from ..log import *
|
||||
from ..Config import Config
|
||||
from ..log import ERR
|
||||
from ..misc import load_object
|
||||
|
||||
class Access(Enum): # export
|
||||
Read = auto()
|
||||
if TYPE_CHECKING:
|
||||
from ..Config import Config
|
||||
|
||||
class Access(Enum): # export
|
||||
Read = auto()
|
||||
Modify = auto()
|
||||
Create = auto()
|
||||
Delete = auto()
|
||||
|
||||
class ProjectFlags(Flag): # export
|
||||
NoFlags = auto()
|
||||
class ProjectFlags(Flag): # export
|
||||
NoFlags = auto()
|
||||
Contributing = auto()
|
||||
Active = auto()
|
||||
Active = auto()
|
||||
|
||||
class Group: # export
|
||||
class Group: # export
|
||||
|
||||
def __repr__(self):
|
||||
return f'Group({self.name})'
|
||||
|
|
@ -34,7 +35,7 @@ class Group: # export
|
|||
def name(self) -> str:
|
||||
return self._name()
|
||||
|
||||
class User: # export
|
||||
class User: # export
|
||||
|
||||
def __repr__(self):
|
||||
return f'User({self.name})'
|
||||
|
|
@ -70,14 +71,14 @@ class User: # export
|
|||
def email(self) -> str:
|
||||
return self._email()
|
||||
|
||||
class Auth(abc.ABC): # export
|
||||
class Auth(abc.ABC): # export
|
||||
|
||||
@classmethod
|
||||
def load(cls, conf: Config, tp: str='') -> Self:
|
||||
def load(cls, conf: Config, tp: str = '') -> Self:
|
||||
if tp == '':
|
||||
val = conf.get('type')
|
||||
if val is None:
|
||||
msg = f'No type specified in auth configuration'
|
||||
msg = 'No type specified in auth configuration'
|
||||
conf.dump(ERR, msg)
|
||||
raise Exception(msg)
|
||||
tp = val
|
||||
|
|
@ -92,10 +93,17 @@ class Auth(abc.ABC): # export
|
|||
return self.__conf
|
||||
|
||||
@abc.abstractmethod
|
||||
def _access(self, what: str, access_type: Optional[Access], who: User|Group|None) -> bool:
|
||||
def _access(
|
||||
self, what: str, access_type: Optional[Access], who: User | Group | None
|
||||
) -> bool:
|
||||
raise NotImplementedError
|
||||
|
||||
def access(self, what: str, access_type: Optional[Access]=None, who: Optional[Union[User|Group]]=None) -> bool:
|
||||
def access(
|
||||
self,
|
||||
what: str,
|
||||
access_type: Optional[Access] = None,
|
||||
who: Optional[Union[User, Group]] = None
|
||||
) -> bool:
|
||||
return self._access(what, access_type, who)
|
||||
|
||||
@abc.abstractmethod
|
||||
|
|
|
|||
|
|
@ -1,16 +1,18 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional, Union
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from ...log import *
|
||||
from ... import Config
|
||||
from .. import Access
|
||||
from .. import Auth as AuthBase
|
||||
from .. import Group as GroupBase
|
||||
from .. import User as UserBase
|
||||
from .. import ProjectFlags
|
||||
from ...log import WARNING, slog
|
||||
from ..Auth import Access
|
||||
from ..Auth import Auth as AuthBase
|
||||
from ..Auth import Group as GroupBase
|
||||
from ..Auth import ProjectFlags
|
||||
from ..Auth import User as UserBase
|
||||
|
||||
class Group(GroupBase): # export
|
||||
if TYPE_CHECKING:
|
||||
from ...Config import Config
|
||||
|
||||
class Group(GroupBase): # export
|
||||
|
||||
def __init__(self, auth: AuthBase, name: str):
|
||||
self.__name = name
|
||||
|
|
@ -19,7 +21,7 @@ class Group(GroupBase): # export
|
|||
def _name(self) -> str:
|
||||
return self.__name
|
||||
|
||||
class User(UserBase): # export
|
||||
class User(UserBase): # export
|
||||
|
||||
def __init__(self, auth: AuthBase, name: str, conf: Config):
|
||||
self.__name = name
|
||||
|
|
@ -47,13 +49,13 @@ class User(UserBase): # export
|
|||
def _email(self) -> str:
|
||||
return self.__email
|
||||
|
||||
class Auth(AuthBase): # export
|
||||
class Auth(AuthBase): # export
|
||||
|
||||
def __init__(self, conf: Config):
|
||||
super().__init__(conf)
|
||||
self.___users: Optional[dict[str, UserBase]] = None
|
||||
self.__groups = None
|
||||
self.__current_user: UserBase|None = None
|
||||
self.__current_user: UserBase | None = None
|
||||
self.__user_by_email: Optional[dict[str, UserBase]] = None
|
||||
|
||||
@property
|
||||
|
|
@ -62,12 +64,18 @@ class Auth(AuthBase): # export
|
|||
ret: dict[str, UserBase] = {}
|
||||
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)
|
||||
self.___users = ret
|
||||
return self.___users
|
||||
|
||||
def _access(self, what: str, access_type: Optional[Access], who: User|GroupBase|None) -> bool: # type: ignore
|
||||
slog(WARNING, f'Returning False for {access_type} access to resource {what} by {who}')
|
||||
def _access(
|
||||
self, what: str, access_type: Access | None, who: UserBase | GroupBase | None
|
||||
) -> bool: # type: ignore
|
||||
slog(
|
||||
WARNING,
|
||||
f'Returning False for {access_type} access to resource {what} by {who}'
|
||||
)
|
||||
return False
|
||||
|
||||
def _user(self, name) -> UserBase:
|
||||
|
|
|
|||
|
|
@ -1,19 +1,21 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from __future__ import annotations
|
||||
|
||||
from typing import Optional, Union
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
import ldap
|
||||
import ldap # type: ignore[import-untyped]
|
||||
|
||||
from ...log import *
|
||||
from ...ldap import bind
|
||||
from ...Config import Config
|
||||
from .. import Access
|
||||
from .. import Auth as AuthBase
|
||||
from .. import Group as GroupBase
|
||||
from .. import User as UserBase
|
||||
from .. import ProjectFlags
|
||||
from ...log import DEBUG, ERR, WARNING, slog
|
||||
from ..Auth import Access
|
||||
from ..Auth import Auth as AuthBase
|
||||
from ..Auth import Group as GroupBase
|
||||
from ..Auth import ProjectFlags
|
||||
from ..Auth import User as UserBase
|
||||
|
||||
class Group(GroupBase): # export
|
||||
if TYPE_CHECKING:
|
||||
from ...Config import Config
|
||||
|
||||
class Group(GroupBase): # export
|
||||
|
||||
def __init__(self, auth: AuthBase, name: str):
|
||||
self.__name = name
|
||||
|
|
@ -24,13 +26,7 @@ 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):
|
||||
|
||||
self.__auth = auth
|
||||
self.__name = name
|
||||
|
|
@ -50,14 +46,14 @@ class User(UserBase):
|
|||
def _display_name(self) -> str:
|
||||
return self.__cn
|
||||
|
||||
class Auth(AuthBase): # export
|
||||
class Auth(AuthBase): # export
|
||||
|
||||
def __init__(self, conf: Config):
|
||||
super().__init__(conf)
|
||||
self.___users: Optional[dict[str, UserBase]] = None
|
||||
self.___user_by_email: Optional[dict[str, User]] = None
|
||||
self.__groups = None
|
||||
self.__current_user: User|None = None
|
||||
self.__current_user: User | None = None
|
||||
self.__user_base_dn = conf['user_base_dn']
|
||||
self.__conn = self.__bind()
|
||||
self.__dummy = self.load(conf, 'dummy')
|
||||
|
|
@ -72,18 +68,16 @@ class Auth(AuthBase): # export
|
|||
ret_by_email: dict[str, User] = {}
|
||||
for res in self.__conn.find(
|
||||
self.__user_base_dn,
|
||||
ldap.SCOPE_SUBTREE,
|
||||
ldap.SCOPE_SUBTREE, # pyright: ignore[reportAttributeAccessIssue]
|
||||
"objectClass=inetOrgPerson",
|
||||
('uid', 'cn', 'uidNumber', 'mail', 'maildrop')
|
||||
):
|
||||
('uid', 'cn', 'uidNumber', 'mail', 'maildrop')):
|
||||
try:
|
||||
display_name = None
|
||||
if 'displayName' in res[1]:
|
||||
cn = res[1]['displayName'][0].decode('utf-8')
|
||||
else:
|
||||
cn = res[1]['cn'][0].decode('utf-8')
|
||||
uid = res[1]['uid'][0].decode('utf-8')
|
||||
uidNumber = res[1]['uidNumber'][0].decode('utf-8')
|
||||
res[1]['uidNumber'][0].decode('utf-8')
|
||||
emails = []
|
||||
#for attr in ['mail', 'maildrop']:
|
||||
for attr in ['mail']:
|
||||
|
|
@ -93,7 +87,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(self, name = uid, cn = cn, email = emails[0])
|
||||
ret[uid] = user
|
||||
for email in emails:
|
||||
ret_by_email[email] = user
|
||||
|
|
@ -111,10 +105,18 @@ class Auth(AuthBase): # export
|
|||
def __user_by_email(self) -> dict[str, UserBase]:
|
||||
if self.___user_by_email is None:
|
||||
self.__users
|
||||
return self.___user_by_email # type: ignore # We are sure that ___user_by_email is not None at this point
|
||||
return self.___user_by_email # type: ignore # We are sure that ___user_by_email is not None at this point
|
||||
|
||||
def _access(self, what: str, access_type: Optional[Access], who: User|GroupBase|None) -> bool: # type: ignore
|
||||
slog(WARNING, f'Returning False for {access_type} access to resource {what} by {who}')
|
||||
def _access(
|
||||
self,
|
||||
what: str,
|
||||
access_type: Optional[Access],
|
||||
who: UserBase | GroupBase | None
|
||||
) -> bool: # type: ignore
|
||||
slog(
|
||||
WARNING,
|
||||
f'Returning False for {access_type} access to resource {what} by {who}'
|
||||
)
|
||||
return False
|
||||
|
||||
def _user(self, name) -> UserBase:
|
||||
|
|
@ -136,5 +138,9 @@ class Auth(AuthBase): # export
|
|||
def _projects(self, name, flags: ProjectFlags) -> list[str]:
|
||||
if flags & ProjectFlags.Contributing:
|
||||
# TODO: Ask LDAP
|
||||
slog(WARNING, f'Querying LDAP for projects a user contributes to is not implemented, ignoring')
|
||||
slog(
|
||||
WARNING,
|
||||
'Querying LDAP for projects a user contributes to is not '
|
||||
'implemented, ignoring'
|
||||
)
|
||||
return []
|
||||
|
|
|
|||
Loading…
Reference in a new issue