(20250210) Started working on MikroTik config automation.

This commit is contained in:
2025-02-10 19:35:28 +05:30
parent 95d90e807b
commit 94e5c81087
13 changed files with 789 additions and 836 deletions
+24 -37
View File
@@ -36,9 +36,13 @@ sys.path.append(".")
sys.path.append("..")
# For making data behaviour_models:
from pydantic import BaseModel, Field, field_validator, PastDatetime
from pydantic import BaseModel, Field, field_validator, PastDatetime, model_validator
from typing import Optional, Literal, Union
# Other data models:
from models.software.tcaoff_ai.auth import TheCAOfficeAIAuth
from models.software.mikrotik.auth import MikroTikPPPoE1000Auth, MikroTikHotspot1000Auth
# My utils:
from utils_v2.string import regex
from utils_v2.date_time import date_time
@@ -75,40 +79,6 @@ REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]
# *****************************************************************************************************************
class TheCAOfficeAIAuth(BaseModel):
authorizeSoftware: bool = Field(
description = "god knows; don't ask",
frozen = True
)
authorizeMailMessaging: bool = Field(
description = "god knows; don't ask",
frozen = True
)
authorizeCompliancePortal: bool = Field(
description = "god knows; don't ask",
frozen = True
)
authorizeFinancialInstitution: bool = Field(
description = "god knows; don't ask",
frozen = True
)
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "forbid"
# ---------------------------------------------------------------------------------------------------------------------
class SoftwareAuthRequestHeaders(BaseModel):
sessionToken: str = Field(
@@ -135,8 +105,8 @@ class SoftwareAuthRequestHeaders(BaseModel):
class SoftwareAuthRequestData(BaseModel):
softwareClient: Literal["theCaOfficeAi"] = Field(alias = "client")
auth: Union[TheCAOfficeAIAuth]
softwareClient: Literal["theCaOfficeAi", "mikrotikPPPoE1000", "mikrotikHotspot1000"] = Field(alias = "client")
auth: Union[TheCAOfficeAIAuth, MikroTikPPPoE1000Auth, MikroTikHotspot1000Auth]
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
@@ -146,6 +116,23 @@ class SoftwareAuthRequestData(BaseModel):
class Config:
extra = "forbid"
# ┓┏ ┓• ┓ •
# ┃┃┏┓┃┓┏┫┏┓╋┓┏┓┏┓
# ┗┛┗┻┗┗┗┻┗┻┗┗┗┛┛┗
@model_validator(mode = "after")
def ensure_harmony(cls, values):
client = values.softwareClient
auth = values.auth
harmony_map = {
"theCaOfficeAi": TheCAOfficeAIAuth,
"mikrotikPPPoE1000": MikroTikPPPoE1000Auth,
"mikrotikHotspot1000": MikroTikHotspot1000Auth
}
if not isinstance(auth, harmony_map[client]):
raise ValueError(f"incorrect 'auth' for selected client '{client}'")
return values
# *****************************************************************************************************************
# ***** ****