diff options
author | Evgeny Zinoviev <me@ch1p.io> | 2023-06-08 13:32:49 +0300 |
---|---|---|
committer | Evgeny Zinoviev <me@ch1p.io> | 2023-06-08 13:32:49 +0300 |
commit | 27234de929542daaa8a9de9a6a5a3501845e598f (patch) | |
tree | 8b3501a272efe0c2448bd69a27af1fcfe396a457 /src/home/config/validators | |
parent | b8c04cb82e874a7f5ac0ad92f0bc0d110effee97 (diff) | |
parent | 994ae33a811fec7ca11ad049b56b85b4f8c2a553 (diff) |
Merge branch 'mqtt-refactoring' of ch1p.io:homekit into mqtt-refactoring
Diffstat (limited to 'src/home/config/validators')
-rw-r--r-- | src/home/config/validators/__init__.py | 2 | ||||
-rw-r--r-- | src/home/config/validators/_util.py | 11 | ||||
-rw-r--r-- | src/home/config/validators/_validators.py | 32 |
3 files changed, 45 insertions, 0 deletions
diff --git a/src/home/config/validators/__init__.py b/src/home/config/validators/__init__.py new file mode 100644 index 0000000..0e75132 --- /dev/null +++ b/src/home/config/validators/__init__.py @@ -0,0 +1,2 @@ +from ._validators import * +from ._util import validate diff --git a/src/home/config/validators/_util.py b/src/home/config/validators/_util.py new file mode 100644 index 0000000..5227c40 --- /dev/null +++ b/src/home/config/validators/_util.py @@ -0,0 +1,11 @@ +import inspect + +from cerberus import Validator, DocumentError + + +def validate(schema, data): + v = Validator(schema) + if not v.validate(data): + frame = inspect.currentframe().f_back + caller_name = frame.f_code.co_name + raise DocumentError(f'{caller_name}: failed to validate data: ' + v.errors) diff --git a/src/home/config/validators/_validators.py b/src/home/config/validators/_validators.py new file mode 100644 index 0000000..cddc1b0 --- /dev/null +++ b/src/home/config/validators/_validators.py @@ -0,0 +1,32 @@ +from ._util import validate + +__all__ = [ + 'linux_boards_validator' +] + + +def linux_boards_validator(data) -> None: + validate({ + 'type': 'dict', + 'valuesrules': { + 'type': 'dict', + 'schema': { + 'mdns': {'type': 'string', 'required': True}, + 'board': {'type': 'string', 'required': True}, + 'network': {'type': 'list', 'required': True, 'empty': False}, + 'ram': {'type': 'integer', 'required': True}, + 'ext_hdd': { + 'type': 'list', + 'schema': { + 'type': 'dict', + 'schema': { + 'mountpoint': {'type': 'string', 'required': True}, + 'size': {'type': 'integer', 'required': True} + } + }, + }, + 'services': {'type': 'list', 'empty': False}, + 'online': {'type': 'boolean', 'required': True} + } + } + }, data) |