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!")
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")