mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
61 lines
1.7 KiB
Python
61 lines
1.7 KiB
Python
|
|
# -*- coding: utf-8 -*-
|
||
|
|
|
||
|
|
from typing import Optional, Union
|
||
|
|
|
||
|
|
from ... import log
|
||
|
|
from ... import Config
|
||
|
|
from .. import Access
|
||
|
|
from .. import Auth as AuthBase
|
||
|
|
from .. import Group as GroupBase
|
||
|
|
from .. import User as UserBase
|
||
|
|
|
||
|
|
class Group(GroupBase): # export
|
||
|
|
|
||
|
|
def __init__(self, auth: AuthBase, name: str):
|
||
|
|
self.__name = name
|
||
|
|
self.__auth = auth
|
||
|
|
|
||
|
|
def _name(self) -> str:
|
||
|
|
return self.__name
|
||
|
|
|
||
|
|
class User(UserBase):
|
||
|
|
|
||
|
|
def __init__(self, auth: AuthBase, name: str):
|
||
|
|
self.__name = name
|
||
|
|
self.__auth = auth
|
||
|
|
self.__groups = None
|
||
|
|
|
||
|
|
def _name(self) -> str:
|
||
|
|
return self.__name
|
||
|
|
|
||
|
|
def _groups(self) -> list[Group]:
|
||
|
|
if self.__groups is None:
|
||
|
|
for name in conf['user.' + name + '.groups']:
|
||
|
|
ret[name] = Group(self, name)
|
||
|
|
self.__groups = ret
|
||
|
|
self.__groups = ret
|
||
|
|
|
||
|
|
class Auth(AuthBase): # export
|
||
|
|
|
||
|
|
def __init__(self, conf: Config):
|
||
|
|
self.__conf = conf
|
||
|
|
self.__users = None
|
||
|
|
self.__groups = None
|
||
|
|
self.__current_user = None
|
||
|
|
|
||
|
|
def _user(self, name_) -> User:
|
||
|
|
if self.__users is None:
|
||
|
|
ret: dict[str, User] = {}
|
||
|
|
for name in self.conf.entries('user'):
|
||
|
|
ret[name] = User(self, name)
|
||
|
|
self.__users = ret
|
||
|
|
return self.__users[name_]
|
||
|
|
|
||
|
|
def _access(self, what: str, access_type: Optional[Access]=None, who: Optional[Union[User|Group]]=None) -> bool:
|
||
|
|
slog(log.WARNING, f'Returning False for {access_type} access to resource {what} by {who}')
|
||
|
|
return False
|
||
|
|
|
||
|
|
def _current_user(self) -> User:
|
||
|
|
if self.__current_user is None:
|
||
|
|
self.__current_user = self._user(self.conf['current_user'])
|
||
|
|
return self.__current_user
|