diff options
| author | Panu Oksiala <panu@oksiala.fi> | 2024-01-22 00:24:37 +0200 |
|---|---|---|
| committer | Panu Oksiala <panu@oksiala.fi> | 2024-01-22 00:24:37 +0200 |
| commit | 73c1115e6fba24b86eca1e5cad5f5086d6bd2ba6 (patch) | |
| tree | daedbc44f41c91a13cb7fc26edd325ab14996217 /desmo_api/models.py | |
Initial commit
Diffstat (limited to 'desmo_api/models.py')
| -rw-r--r-- | desmo_api/models.py | 32 |
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 |
