197 lines
6.4 KiB
Python
197 lines
6.4 KiB
Python
"""
|
|
|
|
AUTHOR:
|
|
|
|
Khushal P Soonderji
|
|
|
|
DATE:
|
|
|
|
Thursday, 5th Dec., 2024.
|
|
|
|
OBJECTIVE:
|
|
|
|
To provide a structure to receive auth details of various SMS providers.
|
|
|
|
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 NimbusSMSIndiaAuth(BaseModel):
|
|
|
|
entityId: str = Field(
|
|
description = "the entity id as registered with DLT",
|
|
min_length = 1,
|
|
frozen = True
|
|
)
|
|
|
|
senderId: str = Field(
|
|
description = "the 6-char code that you see in your SMS inbox",
|
|
min_length = 1,
|
|
frozen = True,
|
|
examples = ["HDFCBK", "NSESMS", "ZRODHA"]
|
|
)
|
|
|
|
userId: str = Field(
|
|
description = "the 6-digit id that Nimbus has assigned to you",
|
|
min_length = 1,
|
|
frozen = True
|
|
)
|
|
|
|
apiKey: str = Field(
|
|
description = "the key generated through Nimbus's portal",
|
|
min_length = 1,
|
|
frozen = True
|
|
)
|
|
|
|
# ┏┓ ┏•
|
|
# ┃ ┏┓┏┓╋┓┏┓
|
|
# ┗┛┗┛┛┗┛┗┗┫
|
|
# ┛
|
|
|
|
class Config:
|
|
extra = "forbid"
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
class SavvyBulkSMSKenyaAuth(BaseModel):
|
|
|
|
apiKey: str = Field(
|
|
description = "the key generated through Savvy's portal",
|
|
min_length = 1,
|
|
frozen = True
|
|
)
|
|
|
|
partnerId: str = Field(
|
|
description = "the key generated through Savvy's portal",
|
|
min_length = 1,
|
|
frozen = True
|
|
)
|
|
|
|
shortCode: str = Field(
|
|
description = "your short code with Savvy",
|
|
min_length = 1,
|
|
frozen = True
|
|
)
|
|
|
|
# ┏┓ ┏•
|
|
# ┃ ┏┓┏┓╋┓┏┓
|
|
# ┗┛┗┛┛┗┛┗┗┫
|
|
# ┛
|
|
|
|
class Config:
|
|
extra = "forbid"
|
|
|
|
|
|
# ---------------------------------------------------------------------------------------------------------------------
|
|
|
|
|
|
class SMSAuthRequestHeaders(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 SMSAuthRequestData(BaseModel):
|
|
|
|
smsClient: Literal["nimbusSmsIndia", "savvyBulkSmsKenya"] = Field(alias = "client")
|
|
auth: Union[NimbusSMSIndiaAuth, SavvyBulkSMSKenyaAuth]
|
|
|
|
# ┏┓ ┏•
|
|
# ┃ ┏┓┏┓╋┓┏┓
|
|
# ┗┛┗┛┛┗┛┗┗┫
|
|
# ┛
|
|
|
|
class Config:
|
|
extra = "forbid"
|
|
|
|
|
|
# *****************************************************************************************************************
|
|
# ***** ****
|
|
# *** MAIN PROGRAM ***
|
|
# ***** ****
|
|
# *****************************************************************************************************************
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
pass
|