mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2025-12-13 01:30:31 +08:00
changed config hierarchy
This commit is contained in:
parent
e17889ba42
commit
2535892723
@ -15,8 +15,6 @@ kvmd:
|
|||||||
auth: !include auth.yaml
|
auth: !include auth.yaml
|
||||||
|
|
||||||
hid:
|
hid:
|
||||||
type: tty
|
|
||||||
params:
|
|
||||||
reset_pin: 4
|
reset_pin: 4
|
||||||
device: /dev/kvmd-hid
|
device: /dev/kvmd-hid
|
||||||
|
|
||||||
|
|||||||
@ -15,8 +15,6 @@ kvmd:
|
|||||||
auth: !include auth.yaml
|
auth: !include auth.yaml
|
||||||
|
|
||||||
hid:
|
hid:
|
||||||
type: tty
|
|
||||||
params:
|
|
||||||
reset_pin: 4
|
reset_pin: 4
|
||||||
device: /dev/kvmd-hid
|
device: /dev/kvmd-hid
|
||||||
|
|
||||||
|
|||||||
@ -15,8 +15,6 @@ kvmd:
|
|||||||
auth: !include auth.yaml
|
auth: !include auth.yaml
|
||||||
|
|
||||||
hid:
|
hid:
|
||||||
type: tty
|
|
||||||
params:
|
|
||||||
reset_pin: 4
|
reset_pin: 4
|
||||||
device: /dev/kvmd-hid
|
device: /dev/kvmd-hid
|
||||||
|
|
||||||
|
|||||||
@ -15,8 +15,6 @@ kvmd:
|
|||||||
auth: !include auth.yaml
|
auth: !include auth.yaml
|
||||||
|
|
||||||
hid:
|
hid:
|
||||||
type: tty
|
|
||||||
params:
|
|
||||||
reset_pin: 4
|
reset_pin: 4
|
||||||
device: /dev/kvmd-hid
|
device: /dev/kvmd-hid
|
||||||
|
|
||||||
|
|||||||
@ -112,11 +112,11 @@ def _init_config(config_path: str, sections: List[str], override_options: List[s
|
|||||||
config = make_config(raw_config, scheme)
|
config = make_config(raw_config, scheme)
|
||||||
|
|
||||||
if "kvmd" in sections:
|
if "kvmd" in sections:
|
||||||
scheme["kvmd"]["auth"]["internal"] = get_auth_service_class(config.kvmd.auth.internal_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:
|
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"]["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)
|
config = make_config(raw_config, scheme)
|
||||||
|
|
||||||
@ -164,11 +164,13 @@ def _get_config_scheme(sections: List[str]) -> Dict:
|
|||||||
},
|
},
|
||||||
|
|
||||||
"auth": {
|
"auth": {
|
||||||
"internal_type": Option("htpasswd"),
|
"internal": {
|
||||||
# "internal": {},
|
"type": Option("htpasswd"),
|
||||||
"external_type": Option(""),
|
"force_users": Option([], type=valid_users_list),
|
||||||
# "external": {},
|
},
|
||||||
"internal_users": Option([], type=valid_users_list),
|
"external": {
|
||||||
|
"type": Option(""),
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
"info": {
|
"info": {
|
||||||
@ -178,7 +180,6 @@ def _get_config_scheme(sections: List[str]) -> Dict:
|
|||||||
|
|
||||||
"hid": {
|
"hid": {
|
||||||
"type": Option("tty"),
|
"type": Option("tty"),
|
||||||
# "params": {},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
"atx": {
|
"atx": {
|
||||||
|
|||||||
@ -49,7 +49,7 @@ def main(argv: Optional[List[str]]=None) -> None:
|
|||||||
with gpio.bcm():
|
with gpio.bcm():
|
||||||
for (name, pin, enabled) in [
|
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 []),
|
] if config.hid.type == "tty" else []),
|
||||||
("atx_power_switch_pin", config.atx.power_switch_pin, config.atx.enabled),
|
("atx_power_switch_pin", config.atx.power_switch_pin, config.atx.enabled),
|
||||||
("atx_reset_switch_pin", config.atx.reset_switch_pin, config.atx.enabled),
|
("atx_reset_switch_pin", config.atx.reset_switch_pin, config.atx.enabled),
|
||||||
|
|||||||
@ -44,9 +44,9 @@ from .. import init
|
|||||||
|
|
||||||
# =====
|
# =====
|
||||||
def _get_htpasswd_path(config: Section) -> str:
|
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'"
|
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
|
return config.kvmd.auth.internal.file
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -53,16 +53,16 @@ def main(argv: Optional[List[str]]=None) -> None:
|
|||||||
# pylint: disable=protected-access
|
# pylint: disable=protected-access
|
||||||
Server(
|
Server(
|
||||||
auth_manager=AuthManager(
|
auth_manager=AuthManager(
|
||||||
internal_type=config.auth.internal_type,
|
internal_type=config.auth.internal.type,
|
||||||
internal_kwargs=config.auth.internal._unpack(),
|
internal_kwargs=config.auth.internal._unpack(ignore=["type", "force_users"]),
|
||||||
external_type=config.auth.external_type,
|
external_type=config.auth.external.type,
|
||||||
external_kwargs=(config.auth.external._unpack() if config.auth.external_type else {}),
|
external_kwargs=(config.auth.external._unpack(ignore=["type"]) if config.auth.external.type else {}),
|
||||||
internal_users=config.auth.internal_users,
|
force_internal_users=config.auth.internal.force_users,
|
||||||
),
|
),
|
||||||
info_manager=InfoManager(**config.info._unpack()),
|
info_manager=InfoManager(**config.info._unpack()),
|
||||||
log_reader=LogReader(),
|
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()),
|
atx=Atx(**config.atx._unpack()),
|
||||||
msd=MassStorageDevice(**config.msd._unpack()),
|
msd=MassStorageDevice(**config.msd._unpack()),
|
||||||
streamer=Streamer(**config.streamer._unpack()),
|
streamer=Streamer(**config.streamer._unpack()),
|
||||||
|
|||||||
@ -45,7 +45,7 @@ class AuthManager:
|
|||||||
external_type: str,
|
external_type: str,
|
||||||
external_kwargs: Dict,
|
external_kwargs: Dict,
|
||||||
|
|
||||||
internal_users: List[str],
|
force_internal_users: List[str],
|
||||||
) -> None:
|
) -> None:
|
||||||
|
|
||||||
self.__internal_service = get_auth_service_class(internal_type)(**internal_kwargs)
|
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)
|
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())
|
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}
|
self.__tokens: Dict[str, str] = {} # {token: user}
|
||||||
|
|
||||||
async def authorize(self, user: str, passwd: str) -> bool:
|
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
|
service = self.__external_service
|
||||||
else:
|
else:
|
||||||
service = self.__internal_service
|
service = self.__internal_service
|
||||||
|
|||||||
@ -71,15 +71,16 @@ class Section(dict):
|
|||||||
dict.__init__(self)
|
dict.__init__(self)
|
||||||
self.__meta: Dict[str, Dict[str, Any]] = {}
|
self.__meta: Dict[str, Dict[str, Any]] = {}
|
||||||
|
|
||||||
def _unpack(self, _section: Optional["Section"]=None) -> Dict[str, Any]:
|
def _unpack(self, ignore: Optional[List[str]]=None) -> Dict[str, Any]:
|
||||||
if _section is None:
|
if ignore is None:
|
||||||
_section = self
|
ignore = []
|
||||||
unpacked: Dict[str, Any] = {}
|
unpacked: Dict[str, Any] = {}
|
||||||
for (key, value) in _section.items():
|
for (key, value) in self.items():
|
||||||
|
if key not in ignore:
|
||||||
if isinstance(value, Section):
|
if isinstance(value, Section):
|
||||||
unpacked[key] = value._unpack() # pylint: disable=protected-access
|
unpacked[key] = value._unpack() # pylint: disable=protected-access
|
||||||
else: # Option
|
else: # Option
|
||||||
unpacked[_section._get_unpack_as(key)] = value # pylint: disable=protected-access
|
unpacked[self._get_unpack_as(key)] = value # pylint: disable=protected-access
|
||||||
return unpacked
|
return unpacked
|
||||||
|
|
||||||
def _set_meta(self, key: str, default: Any, unpack_as: str, help: str) -> None: # pylint: disable=redefined-builtin
|
def _set_meta(self, key: str, default: Any, unpack_as: str, help: str) -> None: # pylint: disable=redefined-builtin
|
||||||
|
|||||||
@ -7,8 +7,6 @@ kvmd:
|
|||||||
auth: !include auth.yaml
|
auth: !include auth.yaml
|
||||||
|
|
||||||
hid:
|
hid:
|
||||||
type: tty
|
|
||||||
params:
|
|
||||||
reset_pin: 4
|
reset_pin: 4
|
||||||
device: /dev/ttyS10
|
device: /dev/ttyS10
|
||||||
noop: true
|
noop: true
|
||||||
|
|||||||
@ -57,7 +57,7 @@ def _htpasswd_fixture(request) -> Generator[passlib.apache.HtpasswdFile, None, N
|
|||||||
def _run_htpasswd(cmd: List[str], htpasswd_path: str, internal_type: str="htpasswd") -> None:
|
def _run_htpasswd(cmd: List[str], htpasswd_path: str, internal_type: str="htpasswd") -> None:
|
||||||
cmd = ["kvmd-htpasswd", *cmd, "--set-options"]
|
cmd = ["kvmd-htpasswd", *cmd, "--set-options"]
|
||||||
if internal_type != "htpasswd": # By default
|
if internal_type != "htpasswd": # By default
|
||||||
cmd.append("kvmd/auth/internal_type=" + internal_type)
|
cmd.append("kvmd/auth/internal/type=" + internal_type)
|
||||||
if htpasswd_path:
|
if htpasswd_path:
|
||||||
cmd.append("kvmd/auth/internal/file=" + htpasswd_path)
|
cmd.append("kvmd/auth/internal/file=" + htpasswd_path)
|
||||||
main(cmd)
|
main(cmd)
|
||||||
|
|||||||
@ -50,7 +50,7 @@ def _make_service_kwargs(path: str) -> Dict:
|
|||||||
async def _get_configured_manager(
|
async def _get_configured_manager(
|
||||||
internal_path: str,
|
internal_path: str,
|
||||||
external_path: str="",
|
external_path: str="",
|
||||||
internal_users: Optional[List[str]]=None,
|
force_internal_users: Optional[List[str]]=None,
|
||||||
) -> AsyncGenerator[AuthManager, None]:
|
) -> AsyncGenerator[AuthManager, None]:
|
||||||
|
|
||||||
manager = AuthManager(
|
manager = AuthManager(
|
||||||
@ -58,7 +58,7 @@ async def _get_configured_manager(
|
|||||||
internal_kwargs=_make_service_kwargs(internal_path),
|
internal_kwargs=_make_service_kwargs(internal_path),
|
||||||
external_type=("htpasswd" if external_path else ""),
|
external_type=("htpasswd" if external_path else ""),
|
||||||
external_kwargs=(_make_service_kwargs(external_path) if external_path else {}),
|
external_kwargs=(_make_service_kwargs(external_path) if external_path else {}),
|
||||||
internal_users=(internal_users or []),
|
force_internal_users=(force_internal_users or []),
|
||||||
)
|
)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user