7f7a16d4d2
added multiple files for and correction and changes as well.
150 lines
5.8 KiB
Python
150 lines
5.8 KiB
Python
"""
|
|
|
|
AUTHOR:
|
|
|
|
Khushal P Soonderji
|
|
|
|
DATE:
|
|
|
|
Friday, 13th Dec., 2024.
|
|
|
|
OBJECTIVE:
|
|
|
|
To provide a structure to receive auth details of various software.
|
|
|
|
REFERENCES:
|
|
|
|
N/A
|
|
|
|
DOWNLOADS:
|
|
|
|
N/A
|
|
|
|
"""
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** IMPORT ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# To make sibling directories accessible for imports:
|
|
import sys
|
|
sys.path.append(".")
|
|
sys.path.append("..")
|
|
|
|
# For making data behaviour_models:
|
|
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
|
|
from models.software.ecommerce.auth import ShopifyAuth
|
|
from models.software.places.oauth import GooglePlacesAuth
|
|
# My utils:
|
|
from utils_v2.string import regex
|
|
from utils_v2.date_time import date_time
|
|
|
|
# To work with date and time:
|
|
import datetime
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** MACROS / ONE-TIME INIT ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# RegEx Patterns:
|
|
REGEX_SESSION_TOKEN = r"^[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[a-f0-9]{12}$"
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** VARIABLES ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
# --- Nothing Yet
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** FUNCTIONS ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
class SoftwareAuthRequestHeaders(BaseModel):
|
|
|
|
sessionToken: str = Field(
|
|
description = "the session token of the user who is requesting the service",
|
|
pattern = REGEX_SESSION_TOKEN,
|
|
frozen = True,
|
|
alias = "X-Session-Token"
|
|
)
|
|
|
|
# ┏┓ ┏•
|
|
# ┃ ┏┓┏┓╋┓┏┓
|
|
# ┗┛┗┛┛┗┛┗┗┫
|
|
# ┛
|
|
|
|
class Config:
|
|
extra = "allow"
|
|
|
|
def model_dump(self, *args, **kwargs):
|
|
return super().model_dump(*args, by_alias = True, **kwargs)
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
class SoftwareAuthRequestData(BaseModel):
|
|
|
|
softwareClient: Literal["theCaOfficeAi", "mikrotikPPPoE1000", "mikrotikHotspot1000", "shopify", "googlePlaces"] = Field(alias = "client")
|
|
auth: Union[TheCAOfficeAIAuth, MikroTikPPPoE1000Auth, MikroTikHotspot1000Auth, ShopifyAuth, GooglePlacesAuth]
|
|
|
|
# ┏┓ ┏•
|
|
# ┃ ┏┓┏┓╋┓┏┓
|
|
# ┗┛┗┛┛┗┛┗┗┫
|
|
# ┛
|
|
|
|
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,
|
|
"shopify": ShopifyAuth,
|
|
"googlePlaces": GooglePlacesAuth
|
|
}
|
|
if not isinstance(auth, harmony_map[client]):
|
|
raise ValueError(f"incorrect 'auth' for selected client '{client}'")
|
|
return values
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** MAIN PROGRAM ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
pass
|