inputs: support array of objects references
This extends the possible ways of passing references to inputs. The
current ways possible are:
1) "plain references", an array of strings:
["ref1", "ref2", ...]
2) "object references", a mapping of keys to objects:
{"ref1": { <options> }, "ref2": { <options> }, ...}
This patch adds a new way:
3) "array of object references":
[{"id": "ref1", "options": { ... }}, {"id": ... }, ]
While osbuild promises to preserves the order for "object references"
not all JSON serialization libraries preserve the order since the
JSON specification does leave this up to the implementation.
The new "array of object references" thus allows for specifying the
references together with reference specific options and this in a
specific order.
Additionally this paves the way for specifying the same input twice,
e.g. in the case of the `org.osbuild.files` input where a pipeline
could then be specified twice with different files. This needs core
rework though, since internally we use dictionaries right now.
This commit is contained in:
parent
0fe7196c7a
commit
99abc1373d
8 changed files with 165 additions and 5 deletions
|
|
@ -46,6 +46,23 @@ SCHEMA = r"""
|
|||
}
|
||||
}
|
||||
},
|
||||
"source-array-ref": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["id"],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"options": {
|
||||
"$ref": "#/definitions/source-options"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"source-origin": {
|
||||
"type": "string",
|
||||
"description": "When the origin of the input is a source",
|
||||
|
|
@ -72,6 +89,23 @@ SCHEMA = r"""
|
|||
}
|
||||
}
|
||||
},
|
||||
"pipeline-array-ref": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["id"],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"options": {
|
||||
"$ref": "#/definitions/pipeline-options"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"pipeline-origin": {
|
||||
"type": "string",
|
||||
"description": "When the origin of the input is a pipeline",
|
||||
|
|
@ -93,7 +127,10 @@ SCHEMA = r"""
|
|||
},
|
||||
"references": {
|
||||
"description": "Container image id",
|
||||
"$ref": "#/definitions/source-object-ref"
|
||||
"oneOf": [
|
||||
{"$ref": "#/definitions/source-array-ref"},
|
||||
{"$ref": "#/definitions/source-object-ref"}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -110,7 +147,10 @@ SCHEMA = r"""
|
|||
},
|
||||
"references": {
|
||||
"description": "References to pipelines",
|
||||
"$ref": "#/definitions/pipeline-object-ref"
|
||||
"oneOf": [
|
||||
{"$ref": "#/definitions/pipeline-array-ref"},
|
||||
{"$ref": "#/definitions/pipeline-object-ref"}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -62,6 +62,23 @@ SCHEMA = r"""
|
|||
}
|
||||
}
|
||||
},
|
||||
"source-array-ref": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["id"],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"options": {
|
||||
"$ref": "#/definitions/source-options"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"source-origin": {
|
||||
"type": "string",
|
||||
"description": "When the origin of the input is a source",
|
||||
|
|
@ -89,6 +106,23 @@ SCHEMA = r"""
|
|||
}
|
||||
}
|
||||
},
|
||||
"pipeline-array-ref": {
|
||||
"type": "array",
|
||||
"minItems": 1,
|
||||
"items": {
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["id"],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"options": {
|
||||
"$ref": "#/definitions/pipeline-options"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"pipeline-origin": {
|
||||
"type": "string",
|
||||
"description": "When the origin of the input is a pipeline",
|
||||
|
|
@ -112,6 +146,7 @@ SCHEMA = r"""
|
|||
"description": "Checksums of files to use as files input",
|
||||
"oneOf": [
|
||||
{"$ref": "#/definitions/plain-ref"},
|
||||
{"$ref": "#/definitions/source-array-ref"},
|
||||
{"$ref": "#/definitions/source-object-ref"}
|
||||
]
|
||||
}
|
||||
|
|
@ -130,7 +165,10 @@ SCHEMA = r"""
|
|||
},
|
||||
"references": {
|
||||
"description": "References to pipelines",
|
||||
"$ref": "#/definitions/pipeline-object-ref"
|
||||
"oneOf": [
|
||||
{"$ref": "#/definitions/pipeline-array-ref"},
|
||||
{"$ref": "#/definitions/pipeline-object-ref"}
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -61,6 +61,24 @@ SCHEMA = """
|
|||
"$ref": "#/definitions/options"
|
||||
}
|
||||
}
|
||||
}, {
|
||||
"type": "array",
|
||||
"additionalItems": false,
|
||||
"minItems": 1,
|
||||
"maxItems": 1,
|
||||
"items": [{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["id"],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"options": {
|
||||
"$ref": "#/definitions/options"
|
||||
}
|
||||
}
|
||||
}]
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,6 +45,24 @@ SCHEMA = """
|
|||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}, {
|
||||
"type": "array",
|
||||
"additionalItems": false,
|
||||
"minItems": 1,
|
||||
"items": [{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["id"],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"options": {
|
||||
"type": "object",
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}]
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,6 +46,25 @@ SCHEMA = """
|
|||
},
|
||||
"minProperties": 1,
|
||||
"maxProperties": 1
|
||||
}, {
|
||||
"type": "array",
|
||||
"additionalItems": false,
|
||||
"minItems": 1,
|
||||
"maxItems": 1,
|
||||
"items": [{
|
||||
"type": "object",
|
||||
"additionalProperties": false,
|
||||
"required": ["id"],
|
||||
"properties": {
|
||||
"id": {
|
||||
"type": "string"
|
||||
},
|
||||
"options": {
|
||||
"type": "object",
|
||||
"additionalProperties": false
|
||||
}
|
||||
}
|
||||
}]
|
||||
}]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -248,7 +248,14 @@ def load_input(name: str, description: Dict, index: Index, stage: Stage, manifes
|
|||
refs = description.get("references", {})
|
||||
|
||||
if isinstance(refs, list):
|
||||
refs = {r: {} for r in refs}
|
||||
def make_ref(ref):
|
||||
if isinstance(ref, str):
|
||||
return ref, {}
|
||||
if isinstance(ref, dict):
|
||||
return ref.get("id"), ref.get("options", {})
|
||||
raise ValueError(f"Invalid reference: {ref}")
|
||||
|
||||
refs = dict(make_ref(ref) for ref in refs)
|
||||
|
||||
if origin == "org.osbuild.pipeline":
|
||||
resolved = {}
|
||||
|
|
|
|||
|
|
@ -114,9 +114,23 @@
|
|||
{
|
||||
"type": "array",
|
||||
"items": { "type": "string" }
|
||||
},{
|
||||
}, {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}, {
|
||||
"type": "array",
|
||||
"items": {
|
||||
"type": "object",
|
||||
"required": ["id"],
|
||||
"additionalProperties": false,
|
||||
"properties": {
|
||||
"id": { "type": "string" },
|
||||
"options": {
|
||||
"type": "object",
|
||||
"additionalProperties": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
|
|
|
|||
|
|
@ -439,3 +439,9 @@ class TestFormatV2(unittest.TestCase):
|
|||
}
|
||||
|
||||
self.check_input_references(desc)
|
||||
|
||||
# check references passed as array of objects
|
||||
inputs["references"] = [
|
||||
{"id": k, "options": {}} for k in refs
|
||||
]
|
||||
self.check_input_references(desc)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue