(20241127) Testing GMail auth.

This commit is contained in:
2024-11-27 20:14:04 +05:30
parent 269e36ec27
commit 2e7f1cb626
9 changed files with 336 additions and 238 deletions
+40 -2
View File
@@ -54,6 +54,7 @@ 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_v2 import AsyncRedisCache
from utils_v2.serialization.json_serializer import JSONSerializer
from utils_v2.api.async_quart import (
set_api_version,
read_input,
@@ -65,6 +66,9 @@ from utils_v2.api.async_quart import (
handle_cancelled_request
)
# GMail-related utils:
from utils_v2.goog.gmail.gmail_client import AsyncGMailClient, SCOPES_GMAIL_MAIL_MANAGEMENT
# To make REST API calls:
import httpx
@@ -72,9 +76,13 @@ import httpx
from icecream import IceCreamDebugger
# All the blueprints:
from api.blueprints.mail.oauth import mail_oauth_bp
from api.blueprints.mail.callback import mail_callback_bp
from api.blueprints.test.callback import test_callback_bp
# All the helpers:
from api.helpers.user import session
# *****************************************************************************************************************
# ***** ****
@@ -98,6 +106,7 @@ APP_VERSION = constants.APP_VERSION
# The Quart app:
app = Quart(__name__)
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(test_callback_bp, url_prefix = f"/{MODULE_BASE}/test")
@@ -163,9 +172,15 @@ async def app_startup(**kwargs):
# Make an instance of an HTTP client to use to make API calls:
current_app.http_client = httpx.AsyncClient(
limits = httpx.Limits(
max_connections = 100, # ............ Maximum number of connections allowed in the pool.
max_keepalive_connections = 50, # ... Maximum number of connections that can be kept alive.
),
timeout = httpx.Timeout(
10.0,
read = 5.0
connect = 2.5, # ... Shorter connection timeout.
read = 2.5, # ...... Like what EasyEcom gives.
write = 10.0, # .... Time to wait for sending data.
pool = 120.0 # ..... Time to wait for a free connection from the pool.
)
)
@@ -194,6 +209,7 @@ async def app_startup(**kwargs):
)
current_app.module_cache = AsyncRedisCache(
connection_string = script_cred["redisCache"]["funcReturn"]["connectionString"],
serializer = JSONSerializer(),
debug = enable_debugging,
debug_prefix = "User Cache | "
)
@@ -206,10 +222,32 @@ async def app_startup(**kwargs):
debug = enable_debugging
)
await current_app.logs_mongo.connect()
current_app.data_mongo = AsyncMongo(
connection_string = script_cred["mongoDb"]["data"]["connectionString"],
database_name = script_cred["mongoDb"]["data"]["dbName"],
max_connections = script_cred["mongoDb"]["data"]["poolSize"],
debug = enable_debugging
)
await current_app.data_mongo.connect()
# Create an instance to handle GMail-related activities:
current_app.gmail_client = AsyncGMailClient(
service_name = "gmail",
oauth_json = script_cred["google"]["oauth"]["tcaoff"],
http_client = current_app.http_client,
redirect_url = r"https://api.thecaoffice.com/converse/mail/callback/gmail",
scopes = SCOPES_GMAIL_MAIL_MANAGEMENT,
debug = True,
debug_prefix = "GMail (M) | ",
debug_only_errors = False
)
# Pick the important stuff:
current_app.whitelisted_ips = current_app.script_data["whitelistedIps"]
# Register helpers:
current_app.get_session = session.get_session
# Remove unwanted/sensitive variables from RAM:
del script_cred
gc.collect()