Resetting utils subtree.

This commit is contained in:
2024-12-05 14:47:16 +05:30
parent 6e6e6be87c
commit 75b4bf541b
151 changed files with 139 additions and 125374 deletions
+37 -1
View File
@@ -74,6 +74,7 @@ from utils_v2.goog.gmail.gmail_client import AsyncGMailClient
from models.behaviour.mail.oauth_v2 import MailOAuthModel
from models.behaviour.mail.sync_v2 import MailSyncModel
from models.behaviour.mail.retrieve import MailRetrieveModel
from models.behaviour.sms.auth import SMSAuthModel
# To make REST API calls:
import httpx
@@ -87,6 +88,7 @@ from api.blueprints.mail.oauth_callback import mail_callback_bp
from api.blueprints.mail.sync import mail_sync_bp
from api.blueprints.mail.list import mail_list_bp
from api.blueprints.mail.retrieve import mail_retrieve_bp
from api.blueprints.sms.auth import sms_auth_bp
from api.blueprints.tech.chat_alerts import tech_chat_alert_bp
from api.blueprints.test.callback import test_callback_bp
@@ -124,6 +126,7 @@ app.register_blueprint(mail_callback_bp, url_prefix = f"/{MODULE_BASE}/mail")
app.register_blueprint(mail_sync_bp, url_prefix = f"/{MODULE_BASE}/mail")
app.register_blueprint(mail_list_bp, url_prefix = f"/{MODULE_BASE}/mail")
app.register_blueprint(mail_retrieve_bp, url_prefix = f"/{MODULE_BASE}/mail")
app.register_blueprint(sms_auth_bp, url_prefix = f"/{MODULE_BASE}/sms")
app.register_blueprint(tech_chat_alert_bp, url_prefix = f"/{MODULE_BASE}/tech/alert")
app.register_blueprint(test_callback_bp, url_prefix = f"/{MODULE_BASE}/test")
@@ -205,19 +208,25 @@ async def app_startup(**kwargs):
# ┃ ┏┓┏┓┏┫ ┏┓┏┓┏┫ ┃┃┏┓╋┏┓
# ┗┛┛ ┗ ┗┻ ┗┻┛┗┗┻ ┻┛┗┻┗┗┻
# Get the script credentials and data:
# Get the script credentials:
script_id = os.environ["SCRIPT_ID"]
response = await current_app.http_client.get(
url = r"https://nexcom.ditscentre.in/internal/cred/get",
headers = {"X-Script-Id": script_id}
)
if response.status_code not in [200]: print("CRITICAL: SCRIPT CREDENTIALS LOADING FAILED!")
script_cred = response.json().get("data")
# Get the script data:
response = await current_app.http_client.get(
url = r"https://nexcom.ditscentre.in/internal/data/get",
headers = {"X-Script-Id": script_id}
)
if response.status_code not in [200]: print("CRITICAL: SCRIPT DATA LOADING FAILED!")
current_app.script_data = response.json().get("data")
current_app.printer("Cred and Data loaded.")
# ┏┓┏┓┳┳ ┏┓┏┏• •
# ┃ ┃┃┃┃ ┣┫╋╋┓┏┓┓╋┓┏
# ┗┛┣┛┗┛ ┛┗┛┛┗┛┗┗┗┗┫
@@ -227,6 +236,8 @@ async def app_startup(**kwargs):
try: set_cpu_affinity(script_cred["cpuAffinity"])
except Exception as exception: current_app.printer(exception)
current_app.printer("CPU affinity set.")
# ┳┓ ┓• ┏┓ ┓
# ┣┫┏┓┏┫┓┏ ━━ ┃ ┏┓┏┣┓┏┓
# ┛┗┗ ┗┻┗┛ ┗┛┗┻┗┛┗┗
@@ -244,6 +255,8 @@ async def app_startup(**kwargs):
debug_prefix = "User Cache | "
)
current_app.printer("Redis cache ready.")
# ┳┳┓ • ┳┓┳┓
# ┃┃┃┏┓┏┓┓┏┓┃┃┣┫
# ┛ ┗┗┻┛ ┗┗┻┻┛┻┛
@@ -266,6 +279,8 @@ async def app_startup(**kwargs):
)
await current_app.sql_reader.connect()
current_app.printer("MariaDB ready.")
# ┳┳┓
# ┃┃┃┏┓┏┓┏┓┏┓
# ┛ ┗┗┛┛┗┗┫┗┛
@@ -294,6 +309,8 @@ async def app_startup(**kwargs):
)
await current_app.data_mongo.connect()
current_app.printer("MongoDB ready.")
# ┳ ┓ ┳┳┓ ┓ ┓
# ┃┏┓╋┏┓┏┓┏┓┏┓┃ ┃┃┃┏┓┏┫┏┓┃┏
# ┻┛┗┗┗ ┛ ┛┗┗┻┗ ┛ ┗┗┛┗┻┗ ┗┛
@@ -323,6 +340,17 @@ async def app_startup(**kwargs):
debug_only_errors = True
)
current_app.sms_auth_model = SMSAuthModel(
cache = current_app.module_cache,
alert_url = current_app.script_data["alerts"]["url"],
http_client = current_app.http_client,
debug = enable_debugging,
debug_prefix = "SMS-Auth | ",
debug_only_errors = True
)
current_app.printer("Internal models ready.")
# ┏┓ ┓ ┏┓┓•
# ┃ ┏┓┏┓┏┓┏┓┏╋┏┓┏┓┏ ┏┓┏┓┏┫ ┃ ┃┓┏┓┏┓╋┏
# ┗┛┗┛┛┗┛┗┗ ┗┗┗┛┛ ┛ ┗┻┛┗┗┻ ┗┛┗┗┗ ┛┗┗┛
@@ -338,6 +366,8 @@ async def app_startup(**kwargs):
debug_only_errors = False
)
current_app.printer("Connectors and Clients ready.")
# ┏┓┳ ┳┳┓ •
# ┣┫┃ ┃┃┃┏┓┏┓┓┏
# ┛┗┻ ┛ ┗┗┻┗┫┗┗
@@ -349,6 +379,12 @@ async def app_startup(**kwargs):
openai_api_key = script_cred["openAi"]["openai_api_key"]
)
current_app.printer("AI ready.")
# ┳┳┓•
# ┃┃┃┓┏┏
# ┛ ┗┗┛┗
# Pick the important stuff:
current_app.whitelisted_ips = current_app.script_data["whitelistedIps"]