debian-forge/inputs/org.osbuild.files
Christian Kellner 659c139ed1 inputs/files: extract source options schema
This is mostly to prepare the support for pipeline options will be
different for pipeline origins than source origins.
2021-06-09 18:37:47 +01:00

110 lines
2.4 KiB
Python
Executable file

#!/usr/bin/python3
"""
Inputs for individual files
Provides all the files, named via their content hash, specified
via `references` in a new directory.
The returned data in `files` is a dictionary where the keys are
paths to the provided files and the values dictionaries with
metadata for it. The input itself currently does not set any
metadata itself, but will forward any metadata set via the
`metadata` property. Keys in that must start with a prefix,
like `rpm.` to avoid namespace clashes. This is enforced via
schema validation.
"""
import os
import sys
from osbuild import inputs
SCHEMA = r"""
"additionalProperties": false,
"definitions": {
"metadata": {
"description": "Additional metadata to forward to the stage",
"type": "object",
"additionalProperties": false,
"patternProperties": {
"^\\w+[.]{1}\\w+$": {
"additionalProperties": false
}
}
},
"plain-ref": {
"type": "array",
"items": {
"type": "string"
}
},
"source-options": {
"type": "object",
"additionalProperties": false,
"properties": {
"metadata": {
"$ref": "#/definitions/metadata"
}
}
},
"source-object-ref": {
"type": "object",
"additionalProperties": false,
"minProperties": 1,
"patternProperties": {
".*": {
"$ref": "#/definitions/source-options"
}
}
},
"source-origin": {
"type": "string",
"description": "When the origin of the input is a source",
"enum": ["org.osbuild.source"]
}
},
"required": ["type", "origin", "references"],
"properties": {
"type": {
"enum": ["org.osbuild.files"]
},
"origin": {
"description": "The origin of the input (must be 'org.osbuild.source')",
"$ref": "#/definitions/source-origin"
},
"references": {
"description": "Checksums of files to use as files input",
"oneOf": [
{"$ref": "#/definitions/plain-ref"},
{"$ref": "#/definitions/source-object-ref"}
]
}
}
"""
class FilesInput(inputs.InputService):
def map(self, store, _origin, refs, target, _options):
source = store.source("org.osbuild.files")
for checksum in refs:
os.link(f"{source}/{checksum}", f"{target}/{checksum}")
reply = {
"path": target,
"data": {
"files": refs
}
}
return reply
def main():
service = FilesInput.from_args(sys.argv[1:])
service.main()
if __name__ == '__main__':
main()