diff options
author | Devaev Maxim <[email protected]> | 2019-09-11 19:11:19 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-09-11 19:11:19 +0300 |
commit | 2535892723e275a3e31aa318edc788869c643fd0 (patch) | |
tree | c51277d4ef558cc010622cfa8c4e4c06777a8ed1 /kvmd/apps | |
parent | e17889ba426a167804796a830043e59e1941972f (diff) |
changed config hierarchy
Diffstat (limited to 'kvmd/apps')
-rw-r--r-- | kvmd/apps/__init__.py | 21 | ||||
-rw-r--r-- | kvmd/apps/cleanup/__init__.py | 2 | ||||
-rw-r--r-- | kvmd/apps/htpasswd/__init__.py | 4 | ||||
-rw-r--r-- | kvmd/apps/kvmd/__init__.py | 12 | ||||
-rw-r--r-- | kvmd/apps/kvmd/auth.py | 6 |
5 files changed, 23 insertions, 22 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index 974a7d70..7b8f2ef2 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -112,11 +112,11 @@ 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_plugin_options() - if config.kvmd.auth.external_type: - scheme["kvmd"]["auth"]["external"] = get_auth_service_class(config.kvmd.auth.external_type).get_plugin_options() + scheme["kvmd"]["auth"]["internal"].update(get_auth_service_class(config.kvmd.auth.internal.type).get_plugin_options()) + if config.kvmd.auth.external.type: + scheme["kvmd"]["auth"]["external"].update(get_auth_service_class(config.kvmd.auth.external.type).get_plugin_options()) - scheme["kvmd"]["hid"]["params"] = get_hid_class(config.kvmd.hid.type).get_plugin_options() + scheme["kvmd"]["hid"].update(get_hid_class(config.kvmd.hid.type).get_plugin_options()) config = make_config(raw_config, scheme) @@ -164,11 +164,13 @@ def _get_config_scheme(sections: List[str]) -> Dict: }, "auth": { - "internal_type": Option("htpasswd"), - # "internal": {}, - "external_type": Option(""), - # "external": {}, - "internal_users": Option([], type=valid_users_list), + "internal": { + "type": Option("htpasswd"), + "force_users": Option([], type=valid_users_list), + }, + "external": { + "type": Option(""), + }, }, "info": { @@ -178,7 +180,6 @@ def _get_config_scheme(sections: List[str]) -> Dict: "hid": { "type": Option("tty"), - # "params": {}, }, "atx": { diff --git a/kvmd/apps/cleanup/__init__.py b/kvmd/apps/cleanup/__init__.py index 8aaf3452..f25e679a 100644 --- a/kvmd/apps/cleanup/__init__.py +++ b/kvmd/apps/cleanup/__init__.py @@ -49,7 +49,7 @@ def main(argv: Optional[List[str]]=None) -> None: with gpio.bcm(): for (name, pin, enabled) in [ *([ - ("hid_reset_pin", config.hid.params.reset_pin, True), + ("hid_reset_pin", config.hid.reset_pin, True), ] if config.hid.type == "tty" else []), ("atx_power_switch_pin", config.atx.power_switch_pin, config.atx.enabled), ("atx_reset_switch_pin", config.atx.reset_switch_pin, config.atx.enabled), diff --git a/kvmd/apps/htpasswd/__init__.py b/kvmd/apps/htpasswd/__init__.py index 1a666d0f..385de75c 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.internal_type != "htpasswd": + if config.kvmd.auth.internal.type != "htpasswd": raise SystemExit(f"Error: KVMD internal auth not using 'htpasswd'" - f" (now configured {config.kvmd.auth.internal_type!r})") + f" (now configured {config.kvmd.auth.internal.type!r})") return config.kvmd.auth.internal.file diff --git a/kvmd/apps/kvmd/__init__.py b/kvmd/apps/kvmd/__init__.py index 203b741e..f9e46b84 100644 --- a/kvmd/apps/kvmd/__init__.py +++ b/kvmd/apps/kvmd/__init__.py @@ -53,16 +53,16 @@ def main(argv: Optional[List[str]]=None) -> None: # pylint: disable=protected-access Server( auth_manager=AuthManager( - internal_type=config.auth.internal_type, - internal_kwargs=config.auth.internal._unpack(), - external_type=config.auth.external_type, - external_kwargs=(config.auth.external._unpack() if config.auth.external_type else {}), - internal_users=config.auth.internal_users, + internal_type=config.auth.internal.type, + internal_kwargs=config.auth.internal._unpack(ignore=["type", "force_users"]), + external_type=config.auth.external.type, + external_kwargs=(config.auth.external._unpack(ignore=["type"]) if config.auth.external.type else {}), + force_internal_users=config.auth.internal.force_users, ), info_manager=InfoManager(**config.info._unpack()), log_reader=LogReader(), - hid=get_hid_class(config.hid.type)(**config.hid.params._unpack()), + hid=get_hid_class(config.hid.type)(**config.hid._unpack(ignore=["type"])), atx=Atx(**config.atx._unpack()), msd=MassStorageDevice(**config.msd._unpack()), streamer=Streamer(**config.streamer._unpack()), diff --git a/kvmd/apps/kvmd/auth.py b/kvmd/apps/kvmd/auth.py index e4268e74..6a26bbc6 100644 --- a/kvmd/apps/kvmd/auth.py +++ b/kvmd/apps/kvmd/auth.py @@ -45,7 +45,7 @@ class AuthManager: external_type: str, external_kwargs: Dict, - internal_users: List[str], + force_internal_users: List[str], ) -> None: self.__internal_service = get_auth_service_class(internal_type)(**internal_kwargs) @@ -56,12 +56,12 @@ class AuthManager: self.__external_service = get_auth_service_class(external_type)(**external_kwargs) get_logger().info("Using external auth service %r", self.__external_service.get_plugin_name()) - self.__internal_users = internal_users + self.__force_internal_users = force_internal_users self.__tokens: Dict[str, str] = {} # {token: user} async def authorize(self, user: str, passwd: str) -> bool: - if user not in self.__internal_users and self.__external_service: + if user not in self.__force_internal_users and self.__external_service: service = self.__external_service else: service = self.__internal_service |