182 lines
5.0 KiB
Python
182 lines
5.0 KiB
Python
# Copyright (c) 2020. BioPro. Scientific.
|
|
|
|
import abc
|
|
from pathlib import Path
|
|
from typing import List, Optional, Union
|
|
|
|
from biopro.recording import RecordingMetaFile
|
|
from biopro.util.address import ADDRESS
|
|
from biopro.util.cli_base import CliOptions, cli_flags, cli_options
|
|
from .alias import UserDeviceAlias
|
|
from .setting import UserSetting
|
|
from .setup import UserSetup
|
|
|
|
|
|
class UserSettingAPI(metaclass=abc.ABCMeta):
|
|
@property
|
|
@abc.abstractmethod
|
|
def user_repository(self) -> Path:
|
|
"""user repository path"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def user_list(self) -> List[str]:
|
|
"""list user"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def user_info(self, user: str) -> UserSetting:
|
|
"""user information"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def user_add(self, user: str, password: str) -> bool:
|
|
"""create a new user"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def user_check_password_strength(self, password: str) -> Optional[str]:
|
|
"""check the password is strength enough.
|
|
|
|
:param password:
|
|
:return: suggestion message, None when pass
|
|
"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def user_change_password(self, user: str, password: str, new_password: str):
|
|
"""change a user password"""
|
|
pass
|
|
|
|
# TODO user_forget_password
|
|
|
|
@abc.abstractmethod
|
|
def user_del(self, user: str, password: str) -> bool:
|
|
"""delete a user"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def user_validate(self, user: str, password: str) -> bool:
|
|
"""validate a user"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def user_sync(self, user: str) -> None:
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def configuration_list(self, user: str) -> List[str]:
|
|
"""list user's configurations"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def configuration_filter(self,
|
|
user: str,
|
|
library: str = None,
|
|
device: str = None) -> List[str]:
|
|
"""filter user's configurations with some condition"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def configuration_get(self, user: str, name: str) -> RecordingMetaFile:
|
|
"""get user configuration"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def configuration_add(self, user: str, name: str, meta: str) -> None:
|
|
"""add new user configuration from meta file"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def configuration_del(self, user: str, name: str) -> bool:
|
|
"""delete user configuration"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def configuration_clone(self, user: str, name: str, new_name: str, from_user: str = None) -> bool:
|
|
"""clone configuration *name* from *from_user* to *user* and given a *new_name*
|
|
|
|
:param user: target user
|
|
:param name: source configuration name
|
|
:param new_name: target configuration name
|
|
:param from_user: from user, None equal *user*
|
|
:return: success or not
|
|
"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def setup_list(self, user: str) -> List[str]:
|
|
""""""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def setup_info(self, user: str, name: str) -> UserSetup:
|
|
""""""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def setup_new(self, user: str, name: str) -> UserSetup:
|
|
""""""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def setup_del(self, user: str, name: str) -> bool:
|
|
""""""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def alias_list(self, user: str) -> List[UserDeviceAlias]:
|
|
"""list device alias for user *user*"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def alias_info(self, user: str, name: Union[str, ADDRESS]) -> Optional[UserDeviceAlias]:
|
|
"""get device alias according *name* for user *user*
|
|
|
|
:param user: user name
|
|
:param name: device name, alias or mac address
|
|
:return:
|
|
"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def alias_new(self, user: str, address: Union[str, ADDRESS]) -> UserDeviceAlias:
|
|
"""create new device alias according the *address* for user *user*
|
|
|
|
:param user: user name
|
|
:param address: mac address, could be str form
|
|
:return:
|
|
"""
|
|
pass
|
|
|
|
@abc.abstractmethod
|
|
def alias_del(self, user: str, address: Union[str, ADDRESS]) -> bool:
|
|
"""delete device alias according the *address* for user *user*
|
|
|
|
:param user: user name
|
|
:param address: mac address, could be str form
|
|
:return: true if success
|
|
"""
|
|
pass
|
|
|
|
|
|
# noinspection PyUnusedLocal
|
|
class UserSettingOptions(CliOptions):
|
|
"""using setting options."""
|
|
|
|
def __init__(self):
|
|
self.user_repository: Optional[str] = None
|
|
'''user repository root'''
|
|
|
|
self.debug_account_system = False
|
|
|
|
@cli_options('-U', '--user-repository', value='PATH')
|
|
def _user_repository(self, opt: str, value: str):
|
|
"""change the user repository root"""
|
|
self.user_repository = value
|
|
|
|
@cli_flags('--debug-account-system')
|
|
def _debug_account_system(self, flag: str):
|
|
"""debug user account system"""
|
|
self.debug_account_system = True
|