From 73c1115e6fba24b86eca1e5cad5f5086d6bd2ba6 Mon Sep 17 00:00:00 2001 From: Panu Oksiala Date: Mon, 22 Jan 2024 00:24:37 +0200 Subject: Initial commit --- desmo_api/models.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 desmo_api/models.py (limited to 'desmo_api/models.py') 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 -- cgit v1.3