1
0
Fork 0

generate: container: Use ",".join() and fix Secret.command()

Use ",".join() instead of the custom join() method and fix
Secret.command() by checking if secret_type and not target is mount...

Signed-off-by: Enno Tensing <tenno@suij.in>
This commit is contained in:
Enno Tensing 2025-07-22 16:50:24 +02:00
parent 2216bf68da
commit 131ff71f34
Signed by: tenno
GPG key ID: 95265603BD36E66C

View file

@ -24,18 +24,6 @@ class ConfigError(Exception):
return f"Configuration error: {self.message}" return f"Configuration error: {self.message}"
def join(data: list, separator: str = ",") -> str:
"""Join a list together."""
ret: str = ""
x = data.copy()
if len(x) == 0:
return ret
while len(x) > 1:
ret += x.pop() + separator
ret += x.pop()
return ret
def maybe(json: dict, key: str) -> str | dict | list | bool | None: def maybe(json: dict, key: str) -> str | dict | list | bool | None:
"""Maybe get a value.""" """Maybe get a value."""
try: try:
@ -132,7 +120,8 @@ class Secret:
cmd = ( cmd = (
f"--secret {self.name},type={self.secret_type},target={self.target}" f"--secret {self.name},type={self.secret_type},target={self.target}"
) )
if self.target == "mount" and self.options != "": # Not a password, ruff...
if self.secret_type == "mount" and self.options != "": # noqa: S105
cmd = f"{cmd},{self.options}" cmd = f"{cmd},{self.options}"
return cmd return cmd
@ -265,7 +254,7 @@ class Network:
if self.mode == "": if self.mode == "":
return "" return ""
cmd = f"--network={self.mode}" cmd = f"--network={self.mode}"
opts = join(self.options) opts = ",".join(self.options)
if opts != "": if opts != "":
cmd += f":{opts}" cmd += f":{opts}"
return cmd return cmd
@ -346,10 +335,10 @@ class Dns:
if len(self.servers) == 0: if len(self.servers) == 0:
return f"--dns-search={self.search}" return f"--dns-search={self.search}"
if self.search == "": if self.search == "":
return f"--dns={join(self.servers)}" return f"--dns={','.join(self.servers)}"
cmd = f"--dns-search={self.search} \\\n\t--dns=" cmd = f"--dns-search={self.search} \\\n\t--dns="
cmd += join(self.servers) cmd += ",".join(self.servers)
return cmd return cmd