(20241225) Work started on upgrades and server-registration module.
This commit is contained in:
@@ -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,
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
DATE:
|
||||
|
||||
Created: Wednesday, 18th Sept., 2024
|
||||
Updated: Tuesday, 8th Oct., 2024
|
||||
Updated: Wednesday, 25th Dec., 2024
|
||||
|
||||
OBJECTIVE:
|
||||
|
||||
@@ -58,8 +58,9 @@ from utils_v2.api.async_quart import (
|
||||
handle_cancelled_request
|
||||
)
|
||||
|
||||
# Data models:
|
||||
# Models:
|
||||
from utils_v2.api.log import APILogModel
|
||||
from models.logs.api import LogChainRequestData, LogsByFilterRequestData
|
||||
|
||||
# For asynchronous activities:
|
||||
import asyncio
|
||||
@@ -128,12 +129,12 @@ async def get_log(
|
||||
if not fetched_log: return ResponseModel(
|
||||
status_code = StatusCodes.FAILED,
|
||||
http_code = HttpCodes.NOT_FOUND,
|
||||
message = "no such log"
|
||||
message = "No such log."
|
||||
)
|
||||
|
||||
else: return ResponseModel(
|
||||
status_code = StatusCodes.OK,
|
||||
message = f"log found",
|
||||
message = f"Log found.",
|
||||
data = {"total": 1, "fetched": 1, "logs": fetched_log}
|
||||
)
|
||||
|
||||
@@ -171,12 +172,12 @@ async def get_exception_from_log(
|
||||
if not fetched_log: return ResponseModel(
|
||||
status_code = StatusCodes.FAILED,
|
||||
http_code = HttpCodes.NOT_FOUND,
|
||||
message = "no such log"
|
||||
message = "No such log."
|
||||
)
|
||||
|
||||
else: return ResponseModel(
|
||||
status_code = StatusCodes.OK,
|
||||
message = f"log found",
|
||||
message = f"Log found.",
|
||||
data = {"total": 1, "fetched": 1, "logs": fetched_log}
|
||||
)
|
||||
|
||||
@@ -189,10 +190,12 @@ async def get_exception_from_log(
|
||||
@read_input(sanitize_headers = False, sanitize_data = False)
|
||||
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
|
||||
@only_whitelisted_ips(attr_name = "whitelisted_ips")
|
||||
@validate_input(data_validator = lambda x: LogChainRequestData(**x))
|
||||
@handle_cancelled_request()
|
||||
async def get_log_chain(
|
||||
log_chain,
|
||||
inbound_headers: dict = None,
|
||||
inbound_data: dict = None,
|
||||
inbound_data: dict | LogChainRequestData = None,
|
||||
inbound_files: dict = None,
|
||||
**kwargs
|
||||
):
|
||||
@@ -214,10 +217,10 @@ async def get_log_chain(
|
||||
fetched_logs = await current_app.mongo.find_many(
|
||||
collection = "logs",
|
||||
filter = {"logChain": log_chain},
|
||||
projection = {"_id": False},
|
||||
sort = inbound_data.get("sort", {"_id": -1}),
|
||||
limit = inbound_data.get("limit", 25),
|
||||
skip = inbound_data.get("skip", 0)
|
||||
projection = inbound_data.projection,
|
||||
sort = inbound_data.sort,
|
||||
limit = inbound_data.limit,
|
||||
skip = inbound_data.skip
|
||||
)
|
||||
|
||||
fetched_count = len(fetched_logs)
|
||||
@@ -225,12 +228,12 @@ async def get_log_chain(
|
||||
if not fetched_logs: return ResponseModel(
|
||||
status_code = StatusCodes.FAILED,
|
||||
http_code = HttpCodes.NOT_FOUND,
|
||||
message = "no such log chain"
|
||||
message = "No such log chain."
|
||||
)
|
||||
|
||||
else: return ResponseModel(
|
||||
status_code = StatusCodes.OK,
|
||||
message = f"{fetched_count} logs fetched",
|
||||
message = f"{fetched_count} log(s) fetched",
|
||||
data = {"total": total_count, "fetched": fetched_count, "logs": fetched_logs}
|
||||
)
|
||||
|
||||
@@ -243,10 +246,12 @@ async def get_log_chain(
|
||||
@read_input(sanitize_headers = False, sanitize_data = False)
|
||||
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
|
||||
@only_whitelisted_ips(attr_name = "whitelisted_ips")
|
||||
@validate_input(data_validator = lambda x: LogChainRequestData(**x))
|
||||
@handle_cancelled_request()
|
||||
async def get_exceptions_from_log_chain(
|
||||
log_chain,
|
||||
inbound_headers: dict = None,
|
||||
inbound_data: dict = None,
|
||||
inbound_data: dict | LogChainRequestData = None,
|
||||
inbound_files: dict = None,
|
||||
**kwargs
|
||||
):
|
||||
@@ -275,9 +280,9 @@ async def get_exceptions_from_log_chain(
|
||||
"ts": True,
|
||||
"exception": True
|
||||
},
|
||||
sort = inbound_data.get("sort", {"_id": -1}),
|
||||
limit = inbound_data.get("limit", 25),
|
||||
skip = inbound_data.get("skip", 0)
|
||||
sort = inbound_data.sort,
|
||||
limit = inbound_data.limit,
|
||||
skip = inbound_data.skip
|
||||
)
|
||||
|
||||
fetched_count = len(fetched_logs)
|
||||
@@ -285,12 +290,12 @@ async def get_exceptions_from_log_chain(
|
||||
if not fetched_logs: return ResponseModel(
|
||||
status_code = StatusCodes.FAILED,
|
||||
http_code = HttpCodes.NOT_FOUND,
|
||||
message = "no such log chain"
|
||||
message = "No such log chain."
|
||||
)
|
||||
|
||||
else: return ResponseModel(
|
||||
status_code = StatusCodes.OK,
|
||||
message = f"{fetched_count} logs fetched",
|
||||
message = f"{fetched_count} log(s) fetched.",
|
||||
data = {"total": total_count, "fetched": fetched_count, "logs": fetched_logs}
|
||||
)
|
||||
|
||||
@@ -303,9 +308,11 @@ async def get_exceptions_from_log_chain(
|
||||
@read_input(sanitize_headers = False, sanitize_data = False)
|
||||
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
|
||||
@only_whitelisted_ips(attr_name = "whitelisted_ips")
|
||||
@validate_input(data_validator = lambda x: LogsByFilterRequestData(**x))
|
||||
@handle_cancelled_request()
|
||||
async def get_logs_by_filter(
|
||||
inbound_headers: dict = None,
|
||||
inbound_data: dict = None,
|
||||
inbound_data: dict | LogsByFilterRequestData = None,
|
||||
inbound_files: dict = None,
|
||||
**kwargs
|
||||
):
|
||||
@@ -320,16 +327,16 @@ async def get_logs_by_filter(
|
||||
|
||||
total_count = await current_app.mongo.count(
|
||||
collection = "logs",
|
||||
filter = inbound_data["filter"]
|
||||
filter = inbound_data.filter
|
||||
)
|
||||
|
||||
fetched_logs = await current_app.mongo.find_many(
|
||||
collection = "logs",
|
||||
filter = inbound_data["filter"],
|
||||
projection = inbound_data.get("projection", {"_id": False}),
|
||||
sort = inbound_data.get("sort", {"_id": -1}),
|
||||
limit = inbound_data.get("limit", 25),
|
||||
skip = inbound_data.get("skip", 0)
|
||||
filter = inbound_data.filter,
|
||||
projection = inbound_data.projection,
|
||||
sort = inbound_data.sort,
|
||||
limit = inbound_data.limit,
|
||||
skip = inbound_data.skip
|
||||
)
|
||||
|
||||
fetched_count = len(fetched_logs)
|
||||
@@ -337,12 +344,12 @@ async def get_logs_by_filter(
|
||||
if not fetched_logs: return ResponseModel(
|
||||
status_code = StatusCodes.FAILED,
|
||||
http_code = HttpCodes.NOT_FOUND,
|
||||
message = "no matching logs"
|
||||
message = "No matching logs."
|
||||
)
|
||||
|
||||
else: return ResponseModel(
|
||||
status_code = StatusCodes.OK,
|
||||
message = f"{len(fetched_logs)} / {total_count} logs fetched",
|
||||
message = f"{len(fetched_logs)} / {total_count} log(s) fetched.",
|
||||
data = {"total": total_count, "fetched": fetched_count, "logs": fetched_logs}
|
||||
)
|
||||
|
||||
|
||||
+3
-3
@@ -68,8 +68,8 @@ from utils_v2.api.async_quart import (
|
||||
from icecream import IceCreamDebugger
|
||||
|
||||
# All the blueprints:
|
||||
from api.cred_data.blueprint import cred_and_data_bp
|
||||
from api.logs.blueprint import logs_bp
|
||||
from api_v2.blueprints.cred_and_data.blueprint import cred_and_data_bp
|
||||
from api_v2.blueprints.logs.blueprint import logs_bp
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
@@ -81,7 +81,7 @@ from api.logs.blueprint import logs_bp
|
||||
|
||||
# Quart related:
|
||||
MODULE_BASE = "internal"
|
||||
APP_VERSION = "2.0.0"
|
||||
APP_VERSION = "2.2.0"
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
|
||||
Reference in New Issue
Block a user