summaryrefslogtreecommitdiff
path: root/src/home/config/_validators.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/home/config/_validators.py')
-rw-r--r--src/home/config/_validators.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/home/config/_validators.py b/src/home/config/_validators.py
new file mode 100644
index 0000000..963a25f
--- /dev/null
+++ b/src/home/config/_validators.py
@@ -0,0 +1,46 @@
+import logging
+import inspect
+
+from cerberus import Validator, DocumentError
+
+
+__all__ = [
+ 'linux_boards_validator'
+]
+
+_logger = logging.getLogger(__name__)
+
+
+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)
+
+
+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)