(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:
|
||||
|
||||
@@ -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}
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user