api: root relative paths for stage arguments

Resolve relative paths for items the `api.arguments` call: Since paths
are different on the host and in the container, they can be transmitted
relative. Resolve the items for all groups that have paths registered.
This commit is contained in:
Christian Kellner 2021-06-01 19:13:25 +02:00 committed by Tom Gundersen
parent 3377f6c288
commit 463e67d61c

View file

@ -249,6 +249,21 @@ def arguments(path="/run/osbuild/api/osbuild"):
fd = msg["fd"]
with os.fdopen(fds.steal(fd), encoding="utf-8") as f:
data = json.load(f)
# Root relative paths: since paths are different on the
# host and in the container they are transmitted not as
# absolute but relative paths. For all items that have
# registered roots, re-root their path entries here
for name, root in data.get("paths", {}).items():
group = data.get(name)
if not group or not isinstance(group, dict):
continue
for item in group.values():
path = item.get("path")
if not path:
continue
item["path"] = os.path.join(root, path)
return data