(20241225) Work started on upgrades and server-registration module.

This commit is contained in:
2024-12-25 14:52:07 +05:30
parent 053e2c49e3
commit 1fd287900d
8 changed files with 647 additions and 164 deletions
+31 -15
View File
@@ -7,7 +7,7 @@
DATE:
Created: Wednesday, 18th Sept., 2024
Updated: Tuesday, 8th Oct., 2024
Updated: Wednesday, 25th Dec., 2024
OBJECTIVE:
@@ -61,6 +61,15 @@ from utils_v2.api.async_quart import (
make_ordered_json
)
# Models:
from models.cred_and_data.api import (
CredAndDataSetRequestHeaders,
CredAndDataGetRequestHeaders,
CredAndDataUpdateRequestHeaders,
CredAndDataUpdateRequestData,
CredAndDataDeleteRequestHeaders
)
# For asynchronous activities:
import asyncio
@@ -113,8 +122,9 @@ def init(blueprint_setup_state):
# ---------------------------------------------------------------------------------------------------------------------
@cred_and_data_bp.route("/<json_type>/set", methods = ["POST", "GET"])
@set_api_version(api_version = "2.1.0")
@cred_and_data_bp.route("/<json_type>", methods = ["POST"])
@cred_and_data_bp.route("/<json_type>/set", methods = ["POST"])
@set_api_version(api_version = "2.2.0")
@read_input(sanitize_headers = True, sanitize_data = True)
@log_request_to_mongo(
attr_name = "mongo",
@@ -126,7 +136,7 @@ def init(blueprint_setup_state):
)
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
@only_whitelisted_ips(attr_name = "whitelisted_ips")
@validate_input(mandatory_header_keys = ["X-Script-Id", "X-Script-Desc"])
@validate_input(header_validator = lambda x: CredAndDataSetRequestHeaders(**x).model_dump())
@handle_cancelled_request()
async def set_data(
json_type: str = None,
@@ -181,8 +191,9 @@ async def set_data(
# ---------------------------------------------------------------------------------------------------------------------
@cred_and_data_bp.route("/<json_type>/get", methods = ["POST", "GET"])
@set_api_version(api_version = "2.1.0")
@cred_and_data_bp.route("/<json_type>", methods = ["GET"])
@cred_and_data_bp.route("/<json_type>/get", methods = ["GET"])
@set_api_version(api_version = "2.2.0")
@read_input(sanitize_headers = True, sanitize_data = True)
@log_request_to_mongo(
attr_name = "mongo",
@@ -194,7 +205,7 @@ async def set_data(
)
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
@only_whitelisted_ips(attr_name = "whitelisted_ips")
@validate_input(mandatory_header_keys = ["X-Script-Id"])
@validate_input(header_validator = lambda x: CredAndDataGetRequestHeaders(**x).model_dump())
@handle_cancelled_request()
async def get_data(
json_type: str = None,
@@ -251,7 +262,8 @@ async def get_data(
# ---------------------------------------------------------------------------------------------------------------------
@cred_and_data_bp.route("/<json_type>/update", methods = ["POST", "GET"])
@cred_and_data_bp.route("/<json_type>", methods = ["PATCH"])
@cred_and_data_bp.route("/<json_type>/update", methods = ["PATCH"])
@set_api_version(api_version = "2.1.0")
@read_input(sanitize_headers = True, sanitize_data = True)
@log_request_to_mongo(
@@ -264,12 +276,15 @@ async def get_data(
)
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
@only_whitelisted_ips(attr_name = "whitelisted_ips")
@validate_input(mandatory_header_keys = ["X-Script-Id"])
@validate_input(
header_validator = lambda x: CredAndDataUpdateRequestHeaders(**x).model_dump(),
data_validator = lambda x: CredAndDataUpdateRequestData(**x)
)
@handle_cancelled_request()
async def update_cred(
json_type: str = None,
inbound_headers: dict = None,
inbound_data: dict = None,
inbound_data: dict | CredAndDataUpdateRequestData = None,
inbound_files: dict = None,
**kwargs
):
@@ -299,10 +314,10 @@ async def update_cred(
# Prepare the update JSON. Pre-process the fields to set and unset.
# Our actual data/cred are held inside a field called "content", so we must wrap the request in that:
update_json = {}
if inbound_data.get("unset"):
update_json["$unset"] = current_app.mongo.dict_to_dot_notation({"content": inbound_data["unset"]})
if inbound_data.get("set"):
update_json["$set"] = current_app.mongo.dict_to_dot_notation({"content": inbound_data["set"]})
if inbound_data.unsetJson:
update_json["$unset"] = current_app.mongo.dict_to_dot_notation({"content": inbound_data.unsetJson})
if inbound_data.setJson:
update_json["$set"] = current_app.mongo.dict_to_dot_notation({"content": inbound_data.setJson})
# Make an attempt to set the credentials:
success = await current_app.mongo.update_one(
@@ -334,7 +349,8 @@ async def update_cred(
)
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
@only_whitelisted_ips(attr_name = "whitelisted_ips")
@validate_input(mandatory_header_keys = ["X-Script-Id"])
@validate_input(header_validator = lambda x: CredAndDataDeleteRequestHeaders(**x).model_dump())
@handle_cancelled_request()
async def delete_data(
json_type: str = None,
inbound_headers: dict = None,