From 19e858baedd94a531397209f1f97cac75a479a69 Mon Sep 17 00:00:00 2001 From: Christian Kellner Date: Wed, 10 Feb 2021 17:44:35 +0000 Subject: [PATCH] meta: Index now support different schema versions Add a `version` keyword argument to `Index.get_schema` which will in turn look for `osbuild.json` in case of the schema for the manifest is requested and otherwise forward the version argument to the `get_schema` method for the respective `ModuleInfo`. --- osbuild/meta.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/osbuild/meta.py b/osbuild/meta.py index a26d7fcb..7caa48e7 100644 --- a/osbuild/meta.py +++ b/osbuild/meta.py @@ -489,7 +489,7 @@ class Index: return self._module_info[(klass, name)] - def get_schema(self, klass, name=None) -> Schema: + def get_schema(self, klass, name=None, version="1") -> Schema: """Obtain a `Schema` for `klass` and `name` (optional) Returns a `Schema` for the entity identified via `klass` @@ -498,23 +498,23 @@ class Index: that case the actual schema data for `Schema` will be `None` and any validation will fail. """ - schema = self._schemata.get((klass, name)) + schema = self._schemata.get((klass, name, version)) if schema is not None: return schema if klass == "Manifest": - path = f"{self.path}/schemas/osbuild1.json" + path = f"{self.path}/schemas/osbuild{version}.json" with contextlib.suppress(FileNotFoundError): with open(path, "r") as f: schema = json.load(f) elif klass in ["Assembler", "Input", "Source", "Stage"]: info = self.get_module_info(klass, name) if info: - schema = info.get_schema() + schema = info.get_schema(version) else: raise ValueError(f"Unknown klass: {klass}") schema = Schema(schema, name or klass) - self._schemata[(klass, name)] = schema + self._schemata[(klass, name, version)] = schema return schema