aboutsummaryrefslogtreecommitdiffstats
path: root/desmo_api/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'desmo_api/models.py')
-rw-r--r--desmo_api/models.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/desmo_api/models.py b/desmo_api/models.py
new file mode 100644
index 0000000..a4df14c
--- /dev/null
+++ b/desmo_api/models.py
@@ -0,0 +1,32 @@
+from pydantic import BaseModel, ValidationError, validator
+from typing import Literal
+
+
+class JailInfo(BaseModel):
+ name: str
+ state: str
+ ip: str
+ host: str
+
+
+class FullJailInfo(JailInfo):
+ packages: list[str] = []
+ commands: list[str] = []
+
+
+class CreateJailRequest(BaseModel):
+ name: str
+ packages: list[str] = []
+ commands: list[str] = []
+
+ @validator("name")
+ def server_name_validator(cls, v: str):
+ if len(v) < 4 or len(v) > 32:
+ raise ValueError("server_name must be between 4 and 32 characters")
+ if not v.isascii():
+ raise ValueError("server_name must be ascii")
+ if not v.isalnum():
+ raise ValueError("server_name must be alphanumeric")
+ if v[0].isdigit():
+ raise ValueError("server_name must not start with a number")
+ return v