diff options
author | Devaev Maxim <[email protected]> | 2019-04-09 07:13:13 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2019-04-09 07:13:13 +0300 |
commit | a6028c46a46fc06c8865679b8c922bfcd2852ab0 (patch) | |
tree | 106fde0b0f96f2ec3d27f6172c514791c619d306 /kvmd/apps/__init__.py | |
parent | 0460c2e83be9837fab01b116402d54c6b32ee4e4 (diff) |
auth plugins
Diffstat (limited to 'kvmd/apps/__init__.py')
-rw-r--r-- | kvmd/apps/__init__.py | 67 |
1 files changed, 40 insertions, 27 deletions
diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index 9a9a7593..77a9644b 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -35,6 +35,9 @@ import pygments import pygments.lexers.data import pygments.formatters +from ..plugins import UnknownPluginError +from ..plugins.auth import get_auth_service_class + from ..yamlconf import ConfigError from ..yamlconf import make_config from ..yamlconf import Section @@ -55,8 +58,6 @@ from ..validators.fs import valid_unix_mode from ..validators.net import valid_ip_or_host from ..validators.net import valid_port -from ..validators.auth import valid_auth_type - from ..validators.kvm import valid_stream_quality from ..validators.kvm import valid_stream_fps @@ -84,29 +85,11 @@ def init( args_parser.add_argument("-m", "--dump-config", dest="dump_config", action="store_true", help="View current configuration (include all overrides)") (options, remaining) = args_parser.parse_known_args(argv) - raw_config: Dict = {} - - if options.config_path: - options.config_path = os.path.expanduser(options.config_path) - raw_config = load_yaml_file(options.config_path) - - scheme = _get_config_scheme() - try: - _merge_dicts(raw_config, build_raw_from_options(options.set_options)) - config = make_config(raw_config, scheme) - except ConfigError as err: - raise SystemExit("Config error: " + str(err)) + config = _init_config(options.config_path, options.set_options) if options.dump_config: - dump = make_config_dump(config) - if sys.stdout.isatty(): - dump = pygments.highlight( - dump, - pygments.lexers.data.YamlLexer(), - pygments.formatters.TerminalFormatter(bg="dark"), # pylint: disable=no-member - ) - print(dump) - sys.exit(0) + _dump_config(config) + raise SystemExit() logging.captureWarnings(True) logging.config.dictConfig(config.logging) @@ -114,6 +97,35 @@ def init( # ===== +def _init_config(config_path: str, options: List[str]) -> Section: + config_path = os.path.expanduser(config_path) + raw_config: Dict = load_yaml_file(config_path) + + scheme = _get_config_scheme() + try: + _merge_dicts(raw_config, build_raw_from_options(options)) + config = make_config(raw_config, scheme) + + scheme["kvmd"]["auth"]["internal"] = get_auth_service_class(config.kvmd.auth.internal_type).get_options() + if config.kvmd.auth.external_type: + scheme["kvmd"]["auth"]["external"] = get_auth_service_class(config.kvmd.auth.external_type).get_options() + + return make_config(raw_config, scheme) + except (ConfigError, UnknownPluginError) as err: + raise SystemExit("Config error: %s" % (str(err))) + + +def _dump_config(config: Section) -> None: + dump = make_config_dump(config) + if sys.stdout.isatty(): + dump = pygments.highlight( + dump, + pygments.lexers.data.YamlLexer(), + pygments.formatters.TerminalFormatter(bg="dark"), # pylint: disable=no-member + ) + print(dump) + + def _merge_dicts(dest: Dict, src: Dict) -> None: for key in src: if key in dest: @@ -138,10 +150,11 @@ def _get_config_scheme() -> Dict: }, "auth": { - "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"), - }, + "internal_users": Option([]), + "internal_type": Option("htpasswd"), + "external_type": Option(""), + # "internal": {}, + # "external": {}, }, "info": { |