mirror of
ssh://git.janware.com/srv/git/janware/proj/jw-python
synced 2026-01-15 09:53:32 +01:00
jwutils: Add Auth
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
parent
74902349b6
commit
9b1650b58f
4 changed files with 141 additions and 0 deletions
72
tools/python/jwutils/auth/Auth.py
Normal file
72
tools/python/jwutils/auth/Auth.py
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
|
||||
from typing import Optional, Union
|
||||
|
||||
import abc
|
||||
|
||||
from enum import Enum, auto
|
||||
from jwutils import log, Config
|
||||
|
||||
class Access(Enum): # export
|
||||
Read = auto()
|
||||
Modify = auto()
|
||||
Create = auto()
|
||||
Delete = auto()
|
||||
|
||||
class Group: # export
|
||||
|
||||
def __repr__(self):
|
||||
return f'Group({self.name})'
|
||||
|
||||
@abc.abstractmethod
|
||||
def _name(self) -> str:
|
||||
pass
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name()
|
||||
|
||||
class User: # export
|
||||
|
||||
def __repr__(self):
|
||||
return f'User({self.name})'
|
||||
|
||||
@abc.abstractmethod
|
||||
def _name(self) -> str:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def _groups(self) -> list[Group]:
|
||||
pass
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
return self._name()
|
||||
|
||||
@property
|
||||
def groups(self) -> list[Group]:
|
||||
return self._groups()
|
||||
|
||||
class Auth: # export
|
||||
|
||||
def __init__(self, conf: Config):
|
||||
self.__conf = conf
|
||||
|
||||
@abc.abstractmethod
|
||||
def _access(self, what: str, access_type: Optional[Access]=None, who: Optional[Union[User|Group]]=None) -> bool:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def _current_user(self) -> User:
|
||||
pass
|
||||
|
||||
@property
|
||||
def conf(self):
|
||||
return self.__conf
|
||||
|
||||
@property
|
||||
def current_user(self) -> User:
|
||||
return self._current_user()
|
||||
|
||||
def access(self, what: str, access_type: Optional[Access]=None, who: Optional[Union[User|Group]]=None) -> bool:
|
||||
return self._access(what, access_type, who)
|
||||
Loading…
Add table
Add a link
Reference in a new issue