summaryrefslogtreecommitdiff
path: root/kvmd/validators/os.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-10-15 08:21:04 +0300
committerDevaev Maxim <[email protected]>2019-10-15 08:31:00 +0300
commit7b4818ed1502271137b6860511f11b4f415d8230 (patch)
treea570fcaa8828666434b01ea3a0c1c82544ff0429 /kvmd/validators/os.py
parente58ad66da98917d66f58731d041d4ddbe18befed (diff)
msd: allow any printable characters in image name
Diffstat (limited to 'kvmd/validators/os.py')
-rw-r--r--kvmd/validators/os.py19
1 files changed, 19 insertions, 0 deletions
diff --git a/kvmd/validators/os.py b/kvmd/validators/os.py
index 505df8e2..d37ae5d4 100644
--- a/kvmd/validators/os.py
+++ b/kvmd/validators/os.py
@@ -51,6 +51,25 @@ def valid_abs_path_exists(arg: Any, name: str="") -> str:
return valid_abs_path(arg, exists=True, name=name)
+def valid_printable_filename(arg: Any, name: str="") -> str:
+ if not name:
+ name = "printable filename"
+
+ if len(str(arg).strip()) == 0:
+ arg = None
+ arg = check_not_none_string(arg, name)
+
+ if "/" in arg or "\0" in arg or arg in [".", ".."]:
+ raise_error(arg, name)
+
+ arg = "".join(
+ (ch if ch.isprintable() else "_")
+ for ch in arg[:255]
+ )
+ return arg
+
+
+# =====
def valid_unix_mode(arg: Any) -> int:
return int(valid_number(arg, min=0, name="UNIX mode"))