debian-forge/inputs/org.osbuild.tree
Christian Kellner 79b192e736 inputs: add new org.osbuild.tree input
This represents the tree-type input, which is the simplest form
of input a stage can consume. For the stage it is just a file
system tree at a specific location and the contents itself is
mostly opaque. An obvious thing to do with such a content is
carbon copy it to a different location.
Currently this input only supports the pipelines as origins,
which are identified via their id.
2021-01-18 17:44:46 +01:00

58 lines
1.1 KiB
Python
Executable file

#!/usr/bin/python3
"""
Tree inputs
Resolve the given pipeline `id` to a path and return that. If
`id` is `null` or the empty string it returns an empty tree.
"""
import json
import sys
from osbuild.objectstore import StoreClient
SCHEMA = """
"additionalProperties": false,
"required": ["pipeline"],
"properties": {
"pipeline": {
"description": "The Pipeline that built the desired tree",
"type": "object",
"required": ["id"],
"additionalProperties": false,
"properties": {
"id": {
"description": "Identifier for the pipeline",
"type": "string"
}
}
}
}
"""
def main():
args = json.load(sys.stdin)
options = args["options"]
store = StoreClient(connect_to=args["api"]["store"])
pid = options["pipeline"]["id"]
if not pid:
path = store.mkdtemp(prefix="empty")
else:
path = store.read_tree(pid)
if not path:
json.dump({"error": "Could find target"}, sys.stdout)
return 1
json.dump({"path": path}, sys.stdout)
return 0
if __name__ == '__main__':
r = main()
sys.exit(r)