(20250619) Shifted the timed OTP generation code to this project.

This commit is contained in:
2025-06-19 16:41:51 +05:30
parent c754bb6a97
commit 265705a7da
7 changed files with 481 additions and 13 deletions
+44 -1
View File
@@ -53,6 +53,7 @@ from utils_v2.string import json
from utils_v2.api import async_quart
from utils_v2.date_time import date_time
from utils_v2.database.async_mongo_v2 import AsyncMongo
from utils_v2.cache.async_redis_cache_v3 import AsyncRedisCache
from utils_v2.api.async_quart import (
set_api_version,
read_input,
@@ -73,6 +74,7 @@ from controllers.servers.server import CoreServerController
# All the blueprints:
from api_v2.blueprints.cred_and_data.blueprint import cred_and_data_bp
from api_v2.blueprints.logs.blueprint import logs_bp
from api_v2.blueprints.otp.blueprint import otp_bp
from api_v2.blueprints.servers.blueprint import servers_bp
@@ -100,6 +102,7 @@ app = Quart(__name__)
app = cors(app)
app.register_blueprint(cred_and_data_bp, url_prefix = f"/{MODULE_BASE}")
app.register_blueprint(logs_bp, url_prefix = f"/{MODULE_BASE}/logs")
app.register_blueprint(otp_bp, url_prefix = f"/{MODULE_BASE}/otp")
app.register_blueprint(servers_bp, url_prefix = f"/{MODULE_BASE}/servers")
@@ -136,9 +139,21 @@ async def app_startup(**kwargs):
# Safe-halt mechanism for upgrades (for a single-worker run):
current_app.is_under_maintenance = False
# ┳┓ ┓ •
# ┃┃┏┓┣┓┓┏┏┓┏┓┓┏┓┏┓
# ┻┛┗ ┗┛┗┻┗┫┗┫┗┛┗┗┫
# ┛ ┛ ┛
# Debugging:
enable_debugging = True if os.environ["DEBUG"].strip().lower() == "true" else False
current_app.printer = IceCreamDebugger(prefix = f"{MODULE_BASE} (Q) | ", includeContext = True)
if os.environ["DEBUG"] == "True": current_app.printer.disable()
if not enable_debugging: current_app.printer.disable()
current_app.printer("initializing worker.")
# ┳┳┓ ┳┓┳┓
# ┃┃┃┏┓┏┓┏┓┏┓┃┃┣┫
# ┛ ┗┗┛┛┗┗┫┗┛┻┛┻┛
# ┛
# To connect to Mongo:
current_app.mongo = AsyncMongo(
@@ -150,19 +165,47 @@ async def app_startup(**kwargs):
)
await current_app.mongo.connect()
current_app.logs_mongo = current_app.mongo
current_app.printer("MongoDB ready.")
# ┏┓ ┓ ┓ ┳┓
# ┃ ┏┓┏┓┏┫ ┏┓┏┓┏┫ ┃┃┏┓╋┏┓
# ┗┛┛ ┗ ┗┻ ┗┻┛┗┗┻ ┻┛┗┻┗┗┻
# Get the script data:
script_id = os.environ["SCRIPT_ID"]
script_cred = (await current_app.mongo.find_one(
collection = "_scriptCred",
filter = {"scriptId": script_id}
))["content"]
current_app.script_data = (await current_app.mongo.find_one(
collection = "_scriptData",
filter = {"scriptId": script_id}
))["content"]
current_app.printer("Cred and Data ready.")
# ┳┓ ┓• ┏┓ ┓
# ┣┫┏┓┏┫┓┏ ┃ ┏┓┏┣┓┏┓
# ┛┗┗ ┗┻┗┛ ┗┛┗┻┗┛┗┗
current_app.otp_redis = AsyncRedisCache(
connection_string = script_cred["redisCache"]["general"]["sentinelJson"],
debug = enable_debugging,
debug_prefix = "OTP Cache | "
)
current_app.printer("Redis ready.")
# ┏┓ ┓┓
# ┃ ┏┓┏┓╋┏┓┏┓┃┃┏┓┏┓┏
# ┗┛┗┛┛┗┗┛ ┗┛┗┗┗ ┛ ┛
current_app.server_controller = CoreServerController()
current_app.printer("Controllers ready.")
# ┳┳┓•
# ┃┃┃┓┏┏
# ┛ ┗┗┛┗•