diff options
author | Devaev Maxim <[email protected]> | 2019-04-08 06:19:02 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-04-08 06:19:02 +0300 |
commit | d8a5e3837152c7db21b96a585523481337247e6f (patch) | |
tree | 8e738ecda2c6d5c94df88d0f6c57ebb926dfc96f | |
parent | 9243d2a00c86aa9b5df2b1df20d2ba57be0bed47 (diff) |
basic -> htpasswd
-rw-r--r-- | kvmd/apps/__init__.py | 6 | ||||
-rw-r--r-- | kvmd/apps/htpasswd/__init__.py | 8 | ||||
-rw-r--r-- | kvmd/apps/kvmd/auth.py | 14 | ||||
-rw-r--r-- | kvmd/validators/auth.py | 2 | ||||
-rw-r--r-- | tests/test_app_htpasswd.py | 2 | ||||
-rw-r--r-- | tests/test_validators_auth.py | 2 |
6 files changed, 17 insertions, 17 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index d92d29ed..9a9a7593 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -138,9 +138,9 @@ def _get_config_scheme() -> Dict: }, "auth": { - "type": Option("basic", type=valid_auth_type, unpack_as="auth_type"), - "basic": { - "htpasswd": Option("/etc/kvmd/htpasswd", type=valid_abs_path_exists, unpack_as="htpasswd_path"), + "type": Option("htpasswd", type=valid_auth_type, unpack_as="auth_type"), + "htpasswd": { + "file": Option("/etc/kvmd/htpasswd", type=valid_abs_path_exists, unpack_as="path"), }, }, diff --git a/kvmd/apps/htpasswd/__init__.py b/kvmd/apps/htpasswd/__init__.py index 10f90c79..486f00e4 100644 --- a/kvmd/apps/htpasswd/__init__.py +++ b/kvmd/apps/htpasswd/__init__.py @@ -44,9 +44,9 @@ from .. import init # ===== def _get_htpasswd_path(config: Section) -> str: - if config.kvmd.auth.type != "basic": - print("Warning: KVMD does not use basic auth", file=sys.stderr) - return config.kvmd.auth.basic.htpasswd + if config.kvmd.auth.type != "htpasswd": + print("Warning: KVMD does not use htpasswd auth", file=sys.stderr) + return config.kvmd.auth.htpasswd.file @contextlib.contextmanager @@ -101,7 +101,7 @@ def main(argv: Optional[List[str]]=None) -> None: (parent_parser, argv, config) = init(add_help=False, argv=argv) parser = argparse.ArgumentParser( prog="kvmd-htpasswd", - description="Manage KVMD users (basic auth only)", + description="Manage KVMD users (htpasswd auth only)", parents=[parent_parser], ) parser.set_defaults(cmd=(lambda *_: parser.print_help())) diff --git a/kvmd/apps/kvmd/auth.py b/kvmd/apps/kvmd/auth.py index 8c1b188e..57b3bd54 100644 --- a/kvmd/apps/kvmd/auth.py +++ b/kvmd/apps/kvmd/auth.py @@ -32,9 +32,9 @@ from ...logging import get_logger # ===== class AuthManager: - def __init__(self, auth_type: str, basic: Dict) -> None: + def __init__(self, auth_type: str, htpasswd: Dict) -> None: self.__login = { - "basic": lambda: _BasicLogin(**basic), + "htpasswd": lambda: _HtpasswdLogin(**htpasswd), }[auth_type]().login self.__tokens: Dict[str, str] = {} # {token: user} @@ -60,11 +60,11 @@ class AuthManager: return self.__tokens.get(token) -class _BasicLogin: - def __init__(self, htpasswd_path: str) -> None: - get_logger().info("Using basic auth %r", htpasswd_path) - self.__htpasswd_path = htpasswd_path +class _HtpasswdLogin: + def __init__(self, path: str) -> None: + get_logger().info("Using htpasswd auth file %r", path) + self.__path = path def login(self, user: str, passwd: str) -> bool: - htpasswd = passlib.apache.HtpasswdFile(self.__htpasswd_path) + htpasswd = passlib.apache.HtpasswdFile(self.__path) return htpasswd.check_password(user, passwd) diff --git a/kvmd/validators/auth.py b/kvmd/validators/auth.py index 5f6188e1..b4b53928 100644 --- a/kvmd/validators/auth.py +++ b/kvmd/validators/auth.py @@ -40,4 +40,4 @@ def valid_auth_token(arg: Any) -> str: def valid_auth_type(arg: Any) -> str: - return check_string_in_list(arg, "auth type", ["basic"]) + return check_string_in_list(arg, "auth type", ["htpasswd"]) diff --git a/tests/test_app_htpasswd.py b/tests/test_app_htpasswd.py index 71d34fff..a7fe7395 100644 --- a/tests/test_app_htpasswd.py +++ b/tests/test_app_htpasswd.py @@ -59,7 +59,7 @@ def _run_main(htpasswd: passlib.apache.HtpasswdFile, cmd: List[str]) -> None: "kvmd-htpasswd", *cmd, "--set-options", - "kvmd/auth/basic/htpasswd=" + htpasswd.path, + "kvmd/auth/htpasswd/file=" + htpasswd.path, ]) diff --git a/tests/test_validators_auth.py b/tests/test_validators_auth.py index fd13a450..0fae541c 100644 --- a/tests/test_validators_auth.py +++ b/tests/test_validators_auth.py @@ -108,7 +108,7 @@ def test_fail__valid_auth_token(arg: Any) -> None: print(valid_auth_token(arg)) [email protected]("arg", ["BASIC ", "basic"]) [email protected]("arg", ["HTPASSWD ", "htpasswd"]) def test_ok__valid_auth_type(arg: Any) -> None: assert valid_auth_type(arg) == arg.strip().lower() |