(20241213) Started accepting "auth" for software/theCaOfficeAi... I don't know how these details count as "auth", though.

This commit is contained in:
2024-12-13 17:01:32 +05:30
parent e8ddffbdfe
commit 4c258b110a
11 changed files with 604 additions and 18 deletions
View File
+159
View File
@@ -0,0 +1,159 @@
"""
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
from typing import Optional, Literal, Union
# 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 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(
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"] = Field(alias = "client")
auth: Union[TheCAOfficeAIAuth]
# ┏┓ ┏•
# ┃ ┏┓┏┓╋┓┏┓
# ┗┛┗┛┛┗┛┗┗┫
# ┛
class Config:
extra = "forbid"
# *****************************************************************************************************************
# ***** ****
# *** MAIN PROGRAM ***
# ***** ****
# *****************************************************************************************************************
if __name__ == "__main__":
pass
+12 -6
View File
@@ -89,7 +89,7 @@ class CoreAuthTokenModel(BaseModel):
alias = "_id"
)
serviceType: Literal["email", "sms", "chat"] = Field(
serviceType: Literal["software", "email", "sms", "chat"] = Field(
description = "the kind of service this message was sent/received from",
frozen = True
)
@@ -98,7 +98,8 @@ class CoreAuthTokenModel(BaseModel):
"gmail", "outlook", # ...................... Mail Clients
"telegram", "whatsapp", # .................. Chat Clients
"nimbusSmsIndia", "savvyBulkSmsKenya", # ... SMS Clients
"razorpay", "safaricomMPesaExpress" # ...... Payment Gateways
"razorpay", "safaricomMPesaExpress", # ..... Payment Gateways
"theCaOfficeAi" # .......................... God knows, don't ask.
] = Field(
description = "the third-part client that was used",
frozen = True
@@ -133,16 +134,16 @@ class CoreAuthTokenModel(BaseModel):
default = None
)
auth: dict | None = Field(
auth: dict = Field(
description = "any direct auth details like api keys or passwords; will differ for each client",
frozen = False,
default = None
default = {}
)
token: dict | None = Field(
token: dict = Field(
description = "the actual auth tokens of that client; will differ for each client",
frozen = False,
default = None
default = {}
)
user: CoreUserInfoModel = Field(
@@ -191,6 +192,11 @@ class CoreAuthTokenModel(BaseModel):
def parse_date_time(cls, value):
return date_time.parse_date_time(input_value = value, timezone = date_time.TIMEZONE_UTC)
@field_validator("auth", "token", mode = "before")
def handle_null_creds(cls, value):
if value is None: value = {}
return value
# *****************************************************************************************************************
# ***** ****