summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/apps/__init__.py4
-rw-r--r--kvmd/apps/kvmd/auth.py8
-rw-r--r--kvmd/plugins/__init__.py32
-rw-r--r--kvmd/plugins/auth/htpasswd.py4
-rw-r--r--kvmd/plugins/auth/http.py4
5 files changed, 18 insertions, 34 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py
index e4b10127..89a1af0e 100644
--- a/kvmd/apps/__init__.py
+++ b/kvmd/apps/__init__.py
@@ -111,9 +111,9 @@ def _init_config(config_path: str, sections: List[str], override_options: List[s
config = make_config(raw_config, scheme)
if "kvmd" in sections:
- scheme["kvmd"]["auth"]["internal"] = get_auth_service_class(config.kvmd.auth.internal_type).get_options()
+ scheme["kvmd"]["auth"]["internal"] = get_auth_service_class(config.kvmd.auth.internal_type).get_plugin_options()
if config.kvmd.auth.external_type:
- scheme["kvmd"]["auth"]["external"] = get_auth_service_class(config.kvmd.auth.external_type).get_options()
+ scheme["kvmd"]["auth"]["external"] = get_auth_service_class(config.kvmd.auth.external_type).get_plugin_options()
config = make_config(raw_config, scheme)
return config
diff --git a/kvmd/apps/kvmd/auth.py b/kvmd/apps/kvmd/auth.py
index 0753f176..d1d21db4 100644
--- a/kvmd/apps/kvmd/auth.py
+++ b/kvmd/apps/kvmd/auth.py
@@ -47,12 +47,12 @@ class AuthManager:
) -> None:
self.__internal_service = get_auth_service_class(internal_type)(**internal_kwargs)
- get_logger().info("Using internal auth service %r", self.__internal_service.PLUGIN_NAME)
+ get_logger().info("Using internal auth service %r", self.__internal_service.get_plugin_name())
self.__external_service: Optional[BaseAuthService] = None
if external_type:
self.__external_service = get_auth_service_class(external_type)(**external_kwargs)
- get_logger().info("Using external auth service %r", self.__external_service.PLUGIN_NAME)
+ get_logger().info("Using external auth service %r", self.__external_service.get_plugin_name())
self.__internal_users = internal_users
@@ -66,9 +66,9 @@ class AuthManager:
ok = (await service.authorize(user, passwd))
if ok:
- get_logger().info("Authorized user %r via auth service %r", user, service.PLUGIN_NAME)
+ get_logger().info("Authorized user %r via auth service %r", user, service.get_plugin_name())
else:
- get_logger().error("Got access denied for user %r from auth service %r", user, service.PLUGIN_NAME)
+ get_logger().error("Got access denied for user %r from auth service %r", user, service.get_plugin_name())
return ok
async def login(self, user: str, passwd: str) -> Optional[str]:
diff --git a/kvmd/plugins/__init__.py b/kvmd/plugins/__init__.py
index 235e7e0e..d91cc2c8 100644
--- a/kvmd/plugins/__init__.py
+++ b/kvmd/plugins/__init__.py
@@ -22,7 +22,6 @@
import importlib
import functools
-import os
from typing import Dict
from typing import Type
@@ -38,34 +37,23 @@ class UnknownPluginError(Exception):
# =====
class BasePlugin:
- PLUGIN_NAME: str = ""
-
def __init__(self, **_: Any) -> None:
pass # pragma: nocover
@classmethod
- def get_options(cls) -> Dict[str, Option]:
+ def get_plugin_name(cls) -> str:
+ name = cls.__module__
+ return name[name.rindex(".") + 1:]
+
+ @classmethod
+ def get_plugin_options(cls) -> Dict[str, Option]:
return {} # pragma: nocover
-# =====
def get_plugin_class(sub: str, name: str) -> Type[BasePlugin]:
- classes = _get_plugin_classes(sub)
try:
- return classes[name]
- except KeyError:
+ module = importlib.import_module("kvmd.plugins.{}.{}".format(sub, name))
+ except ModuleNotFoundError:
raise UnknownPluginError("Unknown plugin '%s/%s'" % (sub, name))
-
-
-# =====
-def _get_plugin_classes(sub: str) -> Dict[str, Type[BasePlugin]]:
- classes: Dict[str, Type[BasePlugin]] = {} # noqa: E701
- sub_path = os.path.join(os.path.dirname(__file__), sub)
- for file_name in os.listdir(sub_path):
- if not file_name.startswith("__") and file_name.endswith(".py"):
- module_name = file_name[:-3]
- module = importlib.import_module("kvmd.plugins.{}.{}".format(sub, module_name))
- plugin_class = getattr(module, "Plugin")
- classes[plugin_class.PLUGIN_NAME] = plugin_class
- return classes
+ return getattr(module, "Plugin")
diff --git a/kvmd/plugins/auth/htpasswd.py b/kvmd/plugins/auth/htpasswd.py
index 3e7e52d9..46576727 100644
--- a/kvmd/plugins/auth/htpasswd.py
+++ b/kvmd/plugins/auth/htpasswd.py
@@ -33,13 +33,11 @@ from . import BaseAuthService
# =====
class Plugin(BaseAuthService):
- PLUGIN_NAME = "htpasswd"
-
def __init__(self, path: str) -> None: # pylint: disable=super-init-not-called
self.__path = path
@classmethod
- def get_options(cls) -> Dict[str, Option]:
+ def get_plugin_options(cls) -> Dict[str, Option]:
return {
"file": Option("/etc/kvmd/htpasswd", type=valid_abs_path_exists, unpack_as="path"),
}
diff --git a/kvmd/plugins/auth/http.py b/kvmd/plugins/auth/http.py
index edd7ab96..85156a1a 100644
--- a/kvmd/plugins/auth/http.py
+++ b/kvmd/plugins/auth/http.py
@@ -40,8 +40,6 @@ from . import BaseAuthService
# =====
class Plugin(BaseAuthService):
- PLUGIN_NAME = "http"
-
def __init__( # pylint: disable=super-init-not-called
self,
url: str,
@@ -60,7 +58,7 @@ class Plugin(BaseAuthService):
self.__http_session: Optional[aiohttp.ClientSession] = None
@classmethod
- def get_options(cls) -> Dict[str, Option]:
+ def get_plugin_options(cls) -> Dict[str, Option]:
return {
"url": Option("http://localhost/auth"),
"verify": Option(True, type=valid_bool),