From 2b5178c19816e8bf4a2068450d75376a7cc29b45 Mon Sep 17 00:00:00 2001 From: Cayo Puigdefabregas Date: Fri, 8 Apr 2022 12:39:01 +0200 Subject: [PATCH] add parser schemas --- ereuse_devicehub/parser/schemas.py | 35 ++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 ereuse_devicehub/parser/schemas.py diff --git a/ereuse_devicehub/parser/schemas.py b/ereuse_devicehub/parser/schemas.py new file mode 100644 index 00000000..ad2ccdb1 --- /dev/null +++ b/ereuse_devicehub/parser/schemas.py @@ -0,0 +1,35 @@ +from flask import current_app as app +from marshmallow import Schema as MarshmallowSchema +from marshmallow import ValidationError, validates_schema +from marshmallow.fields import Dict, List, Nested, String + +from ereuse_devicehub.resources.schemas import Thing + + +class Snapshot_lite_data(MarshmallowSchema): + dmidecode = String(required=False) + hwinfo = String(required=False) + smart = List(Dict(), required=False) + lshw = Dict(required=False) + + +class Snapshot_lite(Thing): + uuid = String(required=True) + version = String(required=True) + schema_version = String(required=True) + software = String(required=True) + wbid = String(required=True) + type = String(required=True) + timestamp = String(required=True) + data = Nested(Snapshot_lite_data) + + @validates_schema + def validate_workbench_version(self, data: dict): + if data['schema_version'] not in app.config['WORKBENCH_LITE']: + raise ValidationError( + 'Min. supported Workbench version is ' + '{} but yours is {}.'.format( + app.config['WORKBENCH_LITE'][0], data['version'] + ), + field_names=['version'], + )