diff options
author | Devaev Maxim <[email protected]> | 2019-09-14 06:07:36 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-09-14 06:07:36 +0300 |
commit | e8f0b361e3316fa61b8f052b6878d8fb16b9f0ca (patch) | |
tree | f9e223aae0338e93ff1b4de233a1826f391e5b75 /kvmd | |
parent | a2f91fb741f59e18db68278669faa075cdd9a98a (diff) |
crutch for plugins configuring
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/apps/__init__.py | 34 | ||||
-rw-r--r-- | kvmd/apps/cleanup/__init__.py | 5 | ||||
-rw-r--r-- | kvmd/apps/htpasswd/__init__.py | 3 | ||||
-rw-r--r-- | kvmd/apps/ipmi/__init__.py | 2 | ||||
-rw-r--r-- | kvmd/apps/kvmd/__init__.py | 6 |
5 files changed, 37 insertions, 13 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index a17a89c5..5121615b 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -74,8 +74,9 @@ def init( prog: Optional[str]=None, description: Optional[str]=None, add_help: bool=True, - sections: Optional[List[str]]=None, argv: Optional[List[str]]=None, + sections: Optional[List[str]]=None, + **plugins: bool, ) -> Tuple[argparse.ArgumentParser, List[str], Section]: argv = (argv or sys.argv) @@ -90,7 +91,7 @@ def init( help="View current configuration (include all overrides)") (options, remaining) = args_parser.parse_known_args(argv) - config = _init_config(options.config_path, (sections or []), options.set_options) + config = _init_config(options.config_path, options.set_options, (sections or []), **plugins) if options.dump_config: _dump_config(config) raise SystemExit() @@ -101,7 +102,16 @@ def init( # ===== -def _init_config(config_path: str, sections: List[str], override_options: List[str]) -> Section: +def _init_config( + config_path: str, + override_options: List[str], + sections: List[str], + with_auth: bool=False, + with_hid: bool=False, + with_atx: bool=False, + with_msd: bool=False, +) -> Section: + config_path = os.path.expanduser(config_path) raw_config: Dict = load_yaml_file(config_path) @@ -112,13 +122,19 @@ 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"].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()) + if with_auth: + 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()) + + if with_hid: + scheme["kvmd"]["hid"].update(get_hid_class(config.kvmd.hid.type).get_plugin_options()) + + if with_atx: + scheme["kvmd"]["atx"].update(get_atx_class(config.kvmd.atx.type).get_plugin_options()) - scheme["kvmd"]["hid"].update(get_hid_class(config.kvmd.hid.type).get_plugin_options()) - scheme["kvmd"]["atx"].update(get_atx_class(config.kvmd.atx.type).get_plugin_options()) - scheme["kvmd"]["msd"].update(get_msd_class(config.kvmd.msd.type).get_plugin_options()) + if with_msd: + scheme["kvmd"]["msd"].update(get_msd_class(config.kvmd.msd.type).get_plugin_options()) config = make_config(raw_config, scheme) diff --git a/kvmd/apps/cleanup/__init__.py b/kvmd/apps/cleanup/__init__.py index d7790b67..063c8eca 100644 --- a/kvmd/apps/cleanup/__init__.py +++ b/kvmd/apps/cleanup/__init__.py @@ -39,8 +39,11 @@ def main(argv: Optional[List[str]]=None) -> None: config = init( prog="kvmd-cleanup", description="Kill KVMD and clear resources", - sections=["logging", "kvmd"], argv=argv, + sections=["logging", "kvmd"], + with_hid=True, + with_atx=True, + with_msd=True, )[2].kvmd logger = get_logger(0) diff --git a/kvmd/apps/htpasswd/__init__.py b/kvmd/apps/htpasswd/__init__.py index 385de75c..aa42b429 100644 --- a/kvmd/apps/htpasswd/__init__.py +++ b/kvmd/apps/htpasswd/__init__.py @@ -101,8 +101,9 @@ def _cmd_delete(config: Section, options: argparse.Namespace) -> None: def main(argv: Optional[List[str]]=None) -> None: (parent_parser, argv, config) = init( add_help=False, - sections=["logging", "kvmd"], argv=argv, + sections=["logging", "kvmd"], + with_auth=True, ) parser = argparse.ArgumentParser( prog="kvmd-htpasswd", diff --git a/kvmd/apps/ipmi/__init__.py b/kvmd/apps/ipmi/__init__.py index e2b56b1a..17988977 100644 --- a/kvmd/apps/ipmi/__init__.py +++ b/kvmd/apps/ipmi/__init__.py @@ -34,8 +34,8 @@ def main(argv: Optional[List[str]]=None) -> None: config = init( prog="kvmd-ipmi", description="IPMI to KVMD proxy", - sections=["logging", "ipmi"], argv=argv, + sections=["logging", "ipmi"], )[2].ipmi # pylint: disable=protected-access diff --git a/kvmd/apps/kvmd/__init__.py b/kvmd/apps/kvmd/__init__.py index f44dc669..4f6806a2 100644 --- a/kvmd/apps/kvmd/__init__.py +++ b/kvmd/apps/kvmd/__init__.py @@ -45,8 +45,12 @@ def main(argv: Optional[List[str]]=None) -> None: config = init( prog="kvmd", description="The main Pi-KVM daemon", - sections=["logging", "kvmd"], argv=argv, + sections=["logging", "kvmd"], + with_auth=True, + with_hid=True, + with_atx=True, + with_msd=True, )[2].kvmd with gpio.bcm(): |