summaryrefslogtreecommitdiff
path: root/clusterman/config.py
diff options
context:
space:
mode:
Diffstat (limited to 'clusterman/config.py')
-rw-r--r--clusterman/config.py20
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()