summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--clusterman/config.py20
-rw-r--r--pyproject.toml2
2 files changed, 20 insertions, 2 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()
diff --git a/pyproject.toml b/pyproject.toml
index d18be07..a565d86 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -1,7 +1,7 @@
[project]
name = "clusterman"
dynamic = ["version"]
-dependencies = ["psutil"]
+dependencies = ["psutil", "jsonschema"]
description = "Simple cluster management utility"
readme = "README.md"