From 3ed71b48ef92cbba589e594bf0a229b7a07d5448 Mon Sep 17 00:00:00 2001 From: Enno Tensing Date: Wed, 30 Jul 2025 10:57:52 +0200 Subject: [PATCH] generate: container: Switch some maybe() calls to maybe_or() Some places can use maybe_or() intead of maybe(), so use it there. Signed-off-by: Enno Tensing --- generate/container.py | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) diff --git a/generate/container.py b/generate/container.py index 86cb3a3..e7970c5 100644 --- a/generate/container.py +++ b/generate/container.py @@ -284,9 +284,9 @@ class Secret: logger.log_warning(f"Secret {key} is malformed!") continue name = key - secret_type = maybe(val[key], "type") - target = maybe(val[key], "target") - options = maybe(val[key], "options") + secret_type = maybe_or(val[key], "type", "") + target = maybe_or(val[key], "target", "") + options = maybe_or(val[key], "options", "") if options is None: options = "" secrets.append( @@ -456,9 +456,9 @@ class Image: if val is None or not isinstance(val, dict): logger.log_error("Image key either not present or malformed!") return None - registry = maybe(val, "registry") - image = maybe(val, "image") - tag = maybe(val, "tag") + registry = maybe_or(val, "registry", "") + image = maybe_or(val, "image", "") + tag = maybe_or(val, "tag", "") return cls(str(registry), str(image), str(tag)) def command(self) -> str: @@ -503,7 +503,7 @@ class Dns: if val is None or not isinstance(val, dict): logger.log_error("DNS Key is either missing or malformed!") return cls([], "") - search = maybe(val, "search") + search = maybe_or(val, "search", "") servers = maybe(val, "servers") if not isinstance(servers, list): logger.log_error("Servers key is not an array!") @@ -559,12 +559,8 @@ class Container: privileged = maybe(json, "privileged") read_only = maybe(json, "read_only") replace = maybe(json, "replace") - pull_policy = maybe(json, "pull_policy") - if pull_policy is None: - pull_policy = "always" - restart = maybe(json, "restart") - if restart is None: - restart = "no" + pull_policy = maybe_or(json, "pull_policy", "always") + restart = maybe_or(json, "restart", "no") network = maybe(json, "network") dns = maybe(json, "dns") ports = maybe(json, "ports")