diff options
author | Devaev Maxim <[email protected]> | 2020-05-29 17:03:41 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-05-29 17:03:41 +0300 |
commit | 3389dbe0481515b6625359c17105a27cb8dfa93a (patch) | |
tree | b5b4d7abaac60747777244b005f63a8274955e7c /kvmd | |
parent | ef8b6cfda56aa2474fde00c8e94ea0a3dafa3e0d (diff) |
refactoring
Diffstat (limited to 'kvmd')
-rw-r--r-- | kvmd/apps/kvmd/api/hid.py | 4 | ||||
-rw-r--r-- | kvmd/apps/otgmsd/__init__.py | 4 | ||||
-rw-r--r-- | kvmd/plugins/auth/pam.py | 4 | ||||
-rw-r--r-- | kvmd/validators/basic.py | 4 |
4 files changed, 10 insertions, 6 deletions
diff --git a/kvmd/apps/kvmd/api/hid.py b/kvmd/apps/kvmd/api/hid.py index 59824e11..3580c373 100644 --- a/kvmd/apps/kvmd/api/hid.py +++ b/kvmd/apps/kvmd/api/hid.py @@ -37,7 +37,7 @@ from ....plugins.hid import BaseHid from ....validators import raise_error from ....validators.basic import valid_bool -from ....validators.basic import valid_number +from ....validators.basic import valid_int_f0 from ....validators.os import valid_printable_filename @@ -98,7 +98,7 @@ class HidApi: @exposed_http("POST", "/hid/print") async def __print_handler(self, request: Request) -> Response: text = await request.text() - limit = int(valid_number(request.query.get("limit", "1024"), min=0, type=int)) + limit = int(valid_int_f0(request.query.get("limit", "1024"))) if limit > 0: text = text[:limit] symmap = self.__ensure_symmap(request.query.get("keymap", self.__default_keymap_name)) diff --git a/kvmd/apps/otgmsd/__init__.py b/kvmd/apps/otgmsd/__init__.py index 2e7122ac..a9891f0e 100644 --- a/kvmd/apps/otgmsd/__init__.py +++ b/kvmd/apps/otgmsd/__init__.py @@ -31,7 +31,7 @@ from typing import Optional import psutil from ...validators.basic import valid_bool -from ...validators.basic import valid_number +from ...validators.basic import valid_int_f0 from ...validators.os import valid_abs_file @@ -90,7 +90,7 @@ def main(argv: Optional[List[str]]=None) -> None: description="KVMD OTG-MSD low-level hand tool", parents=[parent_parser], ) - parser.add_argument("-i", "--instance", default=0, type=(lambda arg: valid_number(arg, min=0)), + parser.add_argument("-i", "--instance", default=0, type=valid_int_f0, metavar="<N>", help="Drive instance (0 for KVMD drive)") parser.add_argument("--unlock", action="store_true", help="Send SIGUSR1 to MSD kernel thread") diff --git a/kvmd/plugins/auth/pam.py b/kvmd/plugins/auth/pam.py index bcdde5e4..643a6657 100644 --- a/kvmd/plugins/auth/pam.py +++ b/kvmd/plugins/auth/pam.py @@ -30,7 +30,7 @@ import pam from ...yamlconf import Option -from ...validators.basic import valid_number +from ...validators.basic import valid_int_f0 from ...validators.auth import valid_users_list from ...logging import get_logger @@ -63,7 +63,7 @@ class Plugin(BaseAuthService): "service": Option("login"), "allow_users": Option([], type=valid_users_list), "deny_users": Option([], type=valid_users_list), - "allow_uids_at": Option(0, type=(lambda arg: valid_number(arg, min=0))), + "allow_uids_at": Option(0, type=valid_int_f0), } async def authorize(self, user: str, passwd: str) -> bool: diff --git a/kvmd/validators/basic.py b/kvmd/validators/basic.py index 24387be4..ee71be0f 100644 --- a/kvmd/validators/basic.py +++ b/kvmd/validators/basic.py @@ -84,6 +84,10 @@ def valid_number( return arg +def valid_int_f0(arg: Any) -> int: + return int(valid_number(arg, min=0)) + + def valid_int_f1(arg: Any) -> int: return int(valid_number(arg, min=1)) |