(20250614) Cred and Data ids can now be listed.
This commit is contained in:
@@ -349,7 +349,7 @@ async def update_cred(
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@cred_and_data_bp.route("/<json_type>/delete", methods = ["POST", "GET"])
|
||||
@cred_and_data_bp.route("/<json_type>/delete", methods = ["DELETE"])
|
||||
@set_api_version(api_version = "2.1.0")
|
||||
@read_input(sanitize_headers = True, sanitize_data = True)
|
||||
@log_request_to_mongo(
|
||||
@@ -401,6 +401,77 @@ async def delete_data(
|
||||
else: return ResponseModel(status_code = StatusCodes.FAILED)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
@cred_and_data_bp.route("/<json_type>/ids", methods = ["GET"])
|
||||
@set_api_version(api_version = "2.1.0")
|
||||
@read_input(sanitize_headers = True, sanitize_data = True)
|
||||
@log_request_to_mongo(
|
||||
attr_name = "mongo",
|
||||
project = "internal",
|
||||
log_type = "credData",
|
||||
operation = "listIds",
|
||||
log_input = True,
|
||||
log_output = True
|
||||
)
|
||||
@should_not_be_under_maintenance(attr_name = "is_under_maintenance")
|
||||
@only_whitelisted_ips(attr_name = "whitelisted_ips")
|
||||
@validate_input(header_validator = None)
|
||||
@handle_cancelled_request()
|
||||
async def list_all_ids(
|
||||
json_type: str = None,
|
||||
inbound_headers: dict = None,
|
||||
inbound_data: dict = None,
|
||||
inbound_files: dict = None,
|
||||
**kwargs
|
||||
):
|
||||
|
||||
"""
|
||||
To list all the ids for cred or data.
|
||||
:param json_type: The choice from one of the fields of 'JSON_TYPE_INFO'.
|
||||
:param inbound_headers: auto-extracted by the decorators.
|
||||
:param inbound_data: auto-extracted by the decorators.
|
||||
:param inbound_files: auto-extracted by the decorators.
|
||||
:param kwargs: Any number of extra inputs supplied by the decorators.
|
||||
:return: A standard response structure.
|
||||
"""
|
||||
|
||||
# If an invalid choice was made:
|
||||
if json_type not in JSON_TYPE_INFO.keys():
|
||||
return ResponseModel(
|
||||
status_code = StatusCodes.FAILED,
|
||||
message = f"invalid path '{json_type}'",
|
||||
http_code = HttpCodes.BAD_REQUEST
|
||||
)
|
||||
|
||||
# Try to enlist all the ids:
|
||||
data_json = await current_app.mongo.find_many(
|
||||
collection = JSON_TYPE_INFO[json_type]["collection"],
|
||||
filter = {},
|
||||
limit = 1_000,
|
||||
projection = {"_id": False, "scriptId": True, "desc": True},
|
||||
sort = {"_id": 1},
|
||||
raise_exception = True
|
||||
)
|
||||
|
||||
# In case no result was found:
|
||||
if not data_json:
|
||||
return ResponseModel(
|
||||
status_code = StatusCodes.FAILED,
|
||||
http_code = HttpCodes.INTERNAL_SERVER_ERROR,
|
||||
message = "invalid script id"
|
||||
)
|
||||
|
||||
# Successfully retrieved:
|
||||
return ResponseModel(
|
||||
status_code = StatusCodes.OK,
|
||||
http_code = HttpCodes.SUCCESS,
|
||||
message = f"found {len(data_json)} script id(s)",
|
||||
data = data_json
|
||||
)
|
||||
|
||||
|
||||
# *****************************************************************************************************************
|
||||
# ***** ****
|
||||
# *** MAIN PROGRAM ***
|
||||
|
||||
Reference in New Issue
Block a user