(20241129) Started talking to MariaDB for integration.
This commit is contained in:
+64
-1
@@ -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.database.async_mysql_v2 import AsyncMySQL
|
||||
from utils_v2.cache.async_redis_cache_v2 import AsyncRedisCache
|
||||
from utils_v2.serialization.json_serializer import JSONSerializer
|
||||
from utils_v2.api.async_quart import (
|
||||
@@ -67,7 +68,10 @@ from utils_v2.api.async_quart import (
|
||||
)
|
||||
|
||||
# GMail-related utils:
|
||||
from utils_v2.goog.gmail.gmail_client import AsyncGMailClient, SCOPES_GMAIL_MAIL_MANAGEMENT
|
||||
from utils_v2.goog.gmail.gmail_client import AsyncGMailClient
|
||||
|
||||
# Behaviour Models:
|
||||
from models.behaviour.mail.oauth import MailOAuthModel
|
||||
|
||||
# To make REST API calls:
|
||||
import httpx
|
||||
@@ -78,6 +82,7 @@ from icecream import IceCreamDebugger
|
||||
# All the blueprints:
|
||||
from api.blueprints.mail.oauth_request import mail_oauth_bp
|
||||
from api.blueprints.mail.oauth_callback import mail_callback_bp
|
||||
from api.blueprints.tech.chat_alerts import tech_chat_alert_bp
|
||||
from api.blueprints.test.callback import test_callback_bp
|
||||
|
||||
# All the helpers:
|
||||
@@ -108,6 +113,7 @@ app = Quart(__name__, template_folder = r"../views")
|
||||
app = cors(app)
|
||||
app.register_blueprint(mail_oauth_bp, url_prefix = f"/{MODULE_BASE}/mail")
|
||||
app.register_blueprint(mail_callback_bp, url_prefix = f"/{MODULE_BASE}/mail")
|
||||
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")
|
||||
|
||||
|
||||
@@ -184,6 +190,10 @@ async def app_startup(**kwargs):
|
||||
)
|
||||
)
|
||||
|
||||
# ┏┓ ┓ ┓ ┳┓
|
||||
# ┃ ┏┓┏┓┏┫ ┏┓┏┓┏┫ ┃┃┏┓╋┏┓
|
||||
# ┗┛┛ ┗ ┗┻ ┗┻┛┗┗┻ ┻┛┗┻┗┗┻
|
||||
|
||||
# Get the script credentials and data:
|
||||
script_id = os.environ["SCRIPT_ID"]
|
||||
response = await current_app.http_client.get(
|
||||
@@ -197,10 +207,19 @@ async def app_startup(**kwargs):
|
||||
)
|
||||
current_app.script_data = response.json().get("data")
|
||||
|
||||
# ┏┓┏┓┳┳ ┏┓┏┏• •
|
||||
# ┃ ┃┃┃┃ ┣┫╋╋┓┏┓┓╋┓┏
|
||||
# ┗┛┣┛┗┛ ┛┗┛┛┗┛┗┗┗┗┫
|
||||
# ┛
|
||||
|
||||
# We set the CPU affinity:
|
||||
try: set_cpu_affinity(script_cred["cpuAffinity"])
|
||||
except Exception as exception: current_app.printer(exception)
|
||||
|
||||
# ┳┓ ┓• ┏┓ ┓
|
||||
# ┣┫┏┓┏┫┓┏ ━━ ┃ ┏┓┏┣┓┏┓
|
||||
# ┛┗┗ ┗┻┗┛ ┗┛┗┻┗┛┗┗
|
||||
|
||||
# Caching connections:
|
||||
current_app.rate_limit_cache = AsyncRedisCache(
|
||||
connection_string = script_cred["redisCache"]["rateLimit"]["connectionString"],
|
||||
@@ -214,6 +233,33 @@ async def app_startup(**kwargs):
|
||||
debug_prefix = "User Cache | "
|
||||
)
|
||||
|
||||
# ┳┳┓ • ┳┓┳┓
|
||||
# ┃┃┃┏┓┏┓┓┏┓┃┃┣┫
|
||||
# ┛ ┗┗┻┛ ┗┗┻┻┛┻┛
|
||||
|
||||
# MariaDB connections:
|
||||
current_app.sql_writer = AsyncMySQL(
|
||||
pool_size = script_cred["mariaDb"]["write"]["poolSize"],
|
||||
host = script_cred["mariaDb"]["write"]["host"],
|
||||
user = script_cred["mariaDb"]["write"]["user"],
|
||||
password = script_cred["mariaDb"]["write"]["password"],
|
||||
database = script_cred["mariaDb"]["write"]["database"]
|
||||
)
|
||||
await current_app.sql_writer.connect()
|
||||
current_app.sql_reader = AsyncMySQL(
|
||||
pool_size = script_cred["mariaDb"]["read"]["poolSize"],
|
||||
host = script_cred["mariaDb"]["read"]["host"],
|
||||
user = script_cred["mariaDb"]["read"]["user"],
|
||||
password = script_cred["mariaDb"]["read"]["password"],
|
||||
database = script_cred["mariaDb"]["read"]["database"]
|
||||
)
|
||||
await current_app.sql_reader.connect()
|
||||
|
||||
# ┳┳┓
|
||||
# ┃┃┃┏┓┏┓┏┓┏┓
|
||||
# ┛ ┗┗┛┛┗┗┫┗┛
|
||||
# ┛
|
||||
|
||||
# MongoDB connections:
|
||||
current_app.logs_mongo = AsyncMongo(
|
||||
connection_string = script_cred["mongoDb"]["logs"]["connectionString"],
|
||||
@@ -230,6 +276,23 @@ async def app_startup(**kwargs):
|
||||
)
|
||||
await current_app.data_mongo.connect()
|
||||
|
||||
# ┳ ┓ ┳┳┓ ┓ ┓
|
||||
# ┃┏┓╋┏┓┏┓┏┓┏┓┃ ┃┃┃┏┓┏┫┏┓┃┏
|
||||
# ┻┛┗┗┗ ┛ ┛┗┗┻┗ ┛ ┗┗┛┗┻┗ ┗┛
|
||||
|
||||
current_app.mail_oauth_model = MailOAuthModel(
|
||||
cache = current_app.module_cache,
|
||||
alert_url = current_app.script_data["alerts"]["url"],
|
||||
http_client = current_app.http_client,
|
||||
debug = enable_debugging,
|
||||
debug_prefix = "Mail-OAuth | ",
|
||||
debug_only_errors = True
|
||||
)
|
||||
|
||||
# ┏┓
|
||||
# ┃ ┏┓┏┓┏┓┏┓┏╋┏┓┏┓┏
|
||||
# ┗┛┗┛┛┗┛┗┗ ┗┗┗┛┛ ┛
|
||||
|
||||
# Create an instance to handle GMail-related activities:
|
||||
current_app.gmail_client = AsyncGMailClient(
|
||||
service_name = "gmail",
|
||||
|
||||
Reference in New Issue
Block a user