diff options
| author | Loic Guegan <manzerbredes@mailbox.org> | 2023-10-26 17:50:34 +0200 |
|---|---|---|
| committer | Loic Guegan <manzerbredes@mailbox.org> | 2023-10-26 17:50:34 +0200 |
| commit | 2d46fcf95548ec3ef69ace0cc70aa98b387e28a5 (patch) | |
| tree | ac214eb2fc07beab57d5c36a8cc3dfe43bf56956 /clusterman/config.py | |
| parent | 2250082bb3a5db28d6d0be4c4cd5027cafd9a355 (diff) | |
Minor changes
Diffstat (limited to 'clusterman/config.py')
| -rw-r--r-- | clusterman/config.py | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/clusterman/config.py b/clusterman/config.py index 645f4d1..94294be 100644 --- a/clusterman/config.py +++ b/clusterman/config.py @@ -1,5 +1,6 @@ from pathlib import Path -import os, json +import os, json, sys +from jsonschema import validate class Config: @@ -16,6 +17,18 @@ class Config: "plugins": { "ls": "ls -al" }, "timeout": 0.5 } + SCHEMA_CONFIG = { + "type": "object", + "properties": { + "timeout": {"type": "number"}, + "plugins": {"type": "object"}, + "cluster": {"type": "object", "properties":{ + "ip4_from": {"type": "string"}, + "ip4_to": {"type": "string"}, + "ip4_ignore": {"type": "array", "items":{"type": "string"}} + }} + } + } def __init__(self): Path(self.CONF_DIR).mkdir(parents=True, exist_ok=True) @@ -27,6 +40,11 @@ class Config: if os.path.exists(self.CONF_FILE): with open(self.CONF_FILE) as f: self.config=json.load(f) + try: + validate(instance=self.config, schema=self.SCHEMA_CONFIG) + except: + print("Invalid configuration file") + sys.exit(1) else: self.save() |
