diff options
author | Devaev Maxim <[email protected]> | 2019-04-16 00:28:13 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-04-16 00:28:13 +0300 |
commit | da46733840764fd646d5fed7bcae8111ef86c273 (patch) | |
tree | 1f0eba7c7e7a072334137efad92c14d016d22ae4 | |
parent | b1e2d5967a938c62fe47b784565b5bdc5ed55cb2 (diff) |
refactoring
-rw-r--r-- | kvmd/apps/kvmd/__init__.py | 4 | ||||
-rw-r--r-- | kvmd/apps/kvmd/auth.py | 8 | ||||
-rw-r--r-- | testenv/tests/auth/test_manager.py | 21 |
3 files changed, 16 insertions, 17 deletions
diff --git a/kvmd/apps/kvmd/__init__.py b/kvmd/apps/kvmd/__init__.py index 36ac871d..caa8aa4b 100644 --- a/kvmd/apps/kvmd/__init__.py +++ b/kvmd/apps/kvmd/__init__.py @@ -47,9 +47,9 @@ def main(argv: Optional[List[str]]=None) -> None: Server( auth_manager=AuthManager( internal_type=config.auth.internal_type, - internal=config.auth.internal._unpack(), + internal_kwargs=config.auth.internal._unpack(), external_type=config.auth.external_type, - external=(config.auth.external._unpack() if config.auth.external_type else {}), + external_kwargs=(config.auth.external._unpack() if config.auth.external_type else {}), internal_users=config.auth.internal_users, ), info_manager=InfoManager(**config.info._unpack()), diff --git a/kvmd/apps/kvmd/auth.py b/kvmd/apps/kvmd/auth.py index 22724421..d90202c3 100644 --- a/kvmd/apps/kvmd/auth.py +++ b/kvmd/apps/kvmd/auth.py @@ -38,20 +38,20 @@ class AuthManager: self, internal_type: str, - internal: Dict, + internal_kwargs: Dict, external_type: str, - external: Dict, + external_kwargs: Dict, internal_users: List[str], ) -> None: - self.__internal_service = get_auth_service_class(internal_type)(**internal) + self.__internal_service = get_auth_service_class(internal_type)(**internal_kwargs) get_logger().info("Using internal login service %r", self.__internal_service.PLUGIN_NAME) self.__external_service: Optional[BaseAuthService] = None if external_type: - self.__external_service = get_auth_service_class(external_type)(**external) + self.__external_service = get_auth_service_class(external_type)(**external_kwargs) get_logger().info("Using external login service %r", self.__external_service.PLUGIN_NAME) self.__internal_users = internal_users diff --git a/testenv/tests/auth/test_manager.py b/testenv/tests/auth/test_manager.py index 26306731..45978828 100644 --- a/testenv/tests/auth/test_manager.py +++ b/testenv/tests/auth/test_manager.py @@ -24,6 +24,7 @@ import os import contextlib from typing import List +from typing import Dict from typing import AsyncGenerator from typing import Optional @@ -39,6 +40,12 @@ from kvmd.plugins.auth import get_auth_service_class # ===== +def _make_service_kwargs(path: str) -> Dict: + cls = get_auth_service_class("htpasswd") + scheme = cls.get_options() + return make_config({"file": path}, scheme)._unpack() # pylint: disable=protected-access + + @contextlib.asynccontextmanager async def _get_configured_manager( internal_path: str, @@ -46,22 +53,14 @@ async def _get_configured_manager( internal_users: Optional[List[str]]=None, ) -> AsyncGenerator[AuthManager, None]: - internal_class = get_auth_service_class("htpasswd") - internal = make_config({"file": internal_path}, internal_class.get_options())._unpack() # pylint: disable=protected-access - internal.update(internal) - - if external_path: - external_class = get_auth_service_class("htpasswd") - external = make_config({"file": external_path}, external_class.get_options())._unpack() # pylint: disable=protected-access - external.update(external) - manager = AuthManager( internal_type="htpasswd", - internal=internal, + internal_kwargs=_make_service_kwargs(internal_path), external_type=("htpasswd" if external_path else ""), - external=(external if external_path else {}), + external_kwargs=(_make_service_kwargs(external_path) if external_path else {}), internal_users=(internal_users or []), ) + try: yield manager finally: |