1
0
Fork 0

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 <tenno@suij.in>
This commit is contained in:
Enno Tensing 2025-07-30 10:57:52 +02:00
parent 487be8c49a
commit 3ed71b48ef
Signed by: tenno
GPG key ID: 95265603BD36E66C

View file

@ -284,9 +284,9 @@ class Secret:
logger.log_warning(f"Secret {key} is malformed!") logger.log_warning(f"Secret {key} is malformed!")
continue continue
name = key name = key
secret_type = maybe(val[key], "type") secret_type = maybe_or(val[key], "type", "")
target = maybe(val[key], "target") target = maybe_or(val[key], "target", "")
options = maybe(val[key], "options") options = maybe_or(val[key], "options", "")
if options is None: if options is None:
options = "" options = ""
secrets.append( secrets.append(
@ -456,9 +456,9 @@ class Image:
if val is None or not isinstance(val, dict): if val is None or not isinstance(val, dict):
logger.log_error("Image key either not present or malformed!") logger.log_error("Image key either not present or malformed!")
return None return None
registry = maybe(val, "registry") registry = maybe_or(val, "registry", "")
image = maybe(val, "image") image = maybe_or(val, "image", "")
tag = maybe(val, "tag") tag = maybe_or(val, "tag", "")
return cls(str(registry), str(image), str(tag)) return cls(str(registry), str(image), str(tag))
def command(self) -> str: def command(self) -> str:
@ -503,7 +503,7 @@ class Dns:
if val is None or not isinstance(val, dict): if val is None or not isinstance(val, dict):
logger.log_error("DNS Key is either missing or malformed!") logger.log_error("DNS Key is either missing or malformed!")
return cls([], "") return cls([], "")
search = maybe(val, "search") search = maybe_or(val, "search", "")
servers = maybe(val, "servers") servers = maybe(val, "servers")
if not isinstance(servers, list): if not isinstance(servers, list):
logger.log_error("Servers key is not an array!") logger.log_error("Servers key is not an array!")
@ -559,12 +559,8 @@ class Container:
privileged = maybe(json, "privileged") privileged = maybe(json, "privileged")
read_only = maybe(json, "read_only") read_only = maybe(json, "read_only")
replace = maybe(json, "replace") replace = maybe(json, "replace")
pull_policy = maybe(json, "pull_policy") pull_policy = maybe_or(json, "pull_policy", "always")
if pull_policy is None: restart = maybe_or(json, "restart", "no")
pull_policy = "always"
restart = maybe(json, "restart")
if restart is None:
restart = "no"
network = maybe(json, "network") network = maybe(json, "network")
dns = maybe(json, "dns") dns = maybe(json, "dns")
ports = maybe(json, "ports") ports = maybe(json, "ports")