This repository has been archived on 2024-05-31. You can view files and clone it, but cannot push or open issues or pull requests.
devicehub-teal/ereuse_devicehub/parser/schemas.py

56 lines
1.8 KiB
Python
Raw Normal View History

2022-04-08 10:39:01 +00:00
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
2023-07-03 16:49:15 +00:00
# from marshmallow_enum import EnumField
2022-04-08 10:39:01 +00:00
class Snapshot_lite_data(MarshmallowSchema):
2023-07-03 16:49:15 +00:00
hwmd_version = String(required=True)
lshw = Dict(required=True)
2023-07-03 16:49:15 +00:00
dmidecode = String(required=True)
lspci = String(required=True)
2023-07-03 16:49:15 +00:00
hwinfo = String(required=True)
smart = List(Dict(), required=False)
class Test(MarshmallowSchema):
type = String(required=True)
class Sanitize(MarshmallowSchema):
type = String(required=True)
2022-04-08 10:39:01 +00:00
class Snapshot_lite(Thing):
uuid = String(required=True)
version = String(required=True)
2022-04-08 14:46:57 +00:00
schema_api = String(required=True)
2022-04-08 10:39:01 +00:00
software = String(required=True)
2023-07-03 16:49:15 +00:00
# software = EnumField(
# SnapshotSoftware,
# required=True,
# description='The software that generated this Snapshot.',
# )
2022-04-25 09:45:25 +00:00
sid = String(required=True)
2022-04-08 10:39:01 +00:00
type = String(required=True)
timestamp = String(required=True)
2022-12-15 09:18:22 +00:00
settings_version = String(required=False)
2023-07-03 16:49:15 +00:00
hwmd = Nested(Snapshot_lite_data, required=True)
tests = Nested(Test, many=True, collection_class=list, required=False)
sanitize = Nested(Sanitize, many=True, collection_class=list, required=False)
2022-04-08 10:39:01 +00:00
@validates_schema
def validate_workbench_version(self, data: dict):
if data['schema_api'] not in app.config['SCHEMA_WORKBENCH']:
2022-04-08 10:39:01 +00:00
raise ValidationError(
'Min. supported Workbench version is '
'{} but yours is {}.'.format(
app.config['SCHEMA_WORKBENCH'][0], data['version']
2022-04-08 10:39:01 +00:00
),
field_names=['version'],
)