summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-04-08 06:19:02 +0300
committerDevaev Maxim <[email protected]>2019-04-08 06:19:02 +0300
commitd8a5e3837152c7db21b96a585523481337247e6f (patch)
tree8e738ecda2c6d5c94df88d0f6c57ebb926dfc96f /kvmd
parent9243d2a00c86aa9b5df2b1df20d2ba57be0bed47 (diff)
basic -> htpasswd
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/__init__.py6
-rw-r--r--kvmd/apps/htpasswd/__init__.py8
-rw-r--r--kvmd/apps/kvmd/auth.py14
-rw-r--r--kvmd/validators/auth.py2
4 files changed, 15 insertions, 15 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"])