diff --git a/stages/org.osbuild.systemd.unit.create b/stages/org.osbuild.systemd.unit.create index 0f88a98c..2c367f3f 100755 --- a/stages/org.osbuild.systemd.unit.create +++ b/stages/org.osbuild.systemd.unit.create @@ -5,14 +5,11 @@ import sys import osbuild.api -def main(tree, options): - filename = options["filename"] +def validate(filename, cfg): # ensure the service name does not exceed maximum filename length if len(filename) > 255: raise ValueError(f"Error: the {filename} service exceeds the maximum filename length.") - cfg = options["config"] - # Filename extension must match the config: # .service requires a Service section # .mount requires a Mount section @@ -21,6 +18,12 @@ def main(tree, options): if filename.endswith(".mount") and "Mount" not in cfg: raise ValueError(f"Error: {filename} unit requires Mount section") + +def main(tree, options): + filename = options["filename"] + cfg = options["config"] + validate(filename, cfg) + # We trick configparser into letting us write multiple instances of the same option by writing them as keys with no # value, so we enable allow_no_value config = configparser.ConfigParser(allow_no_value=True)