From c937500c750357259272bdb759596d4fa5d66dae Mon Sep 17 00:00:00 2001 From: Varun Valada Date: Thu, 19 Dec 2024 18:07:27 -0600 Subject: [PATCH 1/4] Update credential script to add ability to set maximum reservation time --- server/src/tools/client_credentials_admin.py | 28 ++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/server/src/tools/client_credentials_admin.py b/server/src/tools/client_credentials_admin.py index 63d4feac..b906f803 100644 --- a/server/src/tools/client_credentials_admin.py +++ b/server/src/tools/client_credentials_admin.py @@ -87,6 +87,29 @@ def handle_allowed_queues_input() -> list: return allowed_queues +def handle_max_reservation_input() -> list: + """Gets a user inputted max_reservation_time dict""" + max_reservation = {} + while True: + max_reservation_input = input( + "Do you want to specify a queue to set" + + " max reservation time for? (y/n): " + ) + if max_reservation_input == "y": + queue_name = input( + "Enter the name of the queue(* to apply max reservation for" + + " all queues): " + ) + max_reservation[queue_name] = int( + input("Enter the maximum reservation time for this queue: ") + ) + elif max_reservation_input == "n": + break + else: + print("Invalid input. Please enter 'y' or 'n'.") + return max_reservation + + def confirm_dialogue(entry: dict) -> bool: """Prompts the user to confirm their changes""" print(entry) @@ -136,11 +159,13 @@ def create_client_credential(db): max_priority = handle_max_priority_input() allowed_queues = handle_allowed_queues_input() + max_reservation = handle_max_reservation_input() entry = { "client_id": client_id, "max_priority": max_priority, "allowed_queues": allowed_queues, + "max_reservation_time": max_reservation, } if confirm_dialogue(entry): entry["client_secret_hash"] = client_secret_hash @@ -161,11 +186,13 @@ def edit_client_credential(db): max_priority = handle_max_priority_input() allowed_queues = handle_allowed_queues_input() + max_reservation = handle_max_reservation_input() confirm_output = confirm_dialogue( { "client_id": client_id, "max_priority": max_priority, "allowed_queues": allowed_queues, + "max_reservation_time": max_reservation, } ) if confirm_output: @@ -175,6 +202,7 @@ def edit_client_credential(db): "$set": { "max_priority": max_priority, "allowed_queues": allowed_queues, + "max_reservation_time": max_reservation, } }, return_document=ReturnDocument.AFTER, From 28d261b2b038d60cc3ba4141f77c5bdb550a2805 Mon Sep 17 00:00:00 2001 From: Varun Valada Date: Mon, 27 Jan 2025 09:17:09 -0600 Subject: [PATCH 2/4] Change plus to comma --- server/src/tools/client_credentials_admin.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/server/src/tools/client_credentials_admin.py b/server/src/tools/client_credentials_admin.py index b906f803..7af13bc4 100644 --- a/server/src/tools/client_credentials_admin.py +++ b/server/src/tools/client_credentials_admin.py @@ -56,8 +56,8 @@ def handle_max_priority_input() -> dict: ) if max_priority_input == "y": queue_name = input( - "Enter the name of the queue(* to apply max priority for" - + " all queues): " + "Enter the name of the queue(* to apply max priority for", + " all queues): ", ) max_priority[queue_name] = int( input("Enter the max priority for this queue: ") @@ -74,8 +74,8 @@ def handle_allowed_queues_input() -> list: allowed_queues = [] while True: allowed_queues_input = input( - "Do you want to specify a restricted queue that" - + " you are allowed to use? (y/n): " + "Do you want to specify a restricted queue that", + " you are allowed to use? (y/n): ", ) if allowed_queues_input == "y": queue_name = input("Enter the name of the queue: ") @@ -92,13 +92,13 @@ def handle_max_reservation_input() -> list: max_reservation = {} while True: max_reservation_input = input( - "Do you want to specify a queue to set" - + " max reservation time for? (y/n): " + "Do you want to specify a queue to set", + " max reservation time for? (y/n): ", ) if max_reservation_input == "y": queue_name = input( - "Enter the name of the queue(* to apply max reservation for" - + " all queues): " + "Enter the name of the queue(* to apply max reservation", + " for all queues): ", ) max_reservation[queue_name] = int( input("Enter the maximum reservation time for this queue: ") @@ -289,8 +289,8 @@ def main(): sys.exit() else: print( - "Invalid selection. Please enter " - + "'c', 'e', 'r', 'aq', 'rq', or 'q'\n" + "Invalid selection. Please enter ", + "'c', 'e', 'r', 'aq', 'rq', or 'q'\n", ) From 9ef88325ae0147c2618824698c6fe0631ede7a99 Mon Sep 17 00:00:00 2001 From: Varun Valada Date: Mon, 27 Jan 2025 10:46:08 -0600 Subject: [PATCH 3/4] Remove commas --- server/src/tools/client_credentials_admin.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/server/src/tools/client_credentials_admin.py b/server/src/tools/client_credentials_admin.py index 7af13bc4..aa5b6c2a 100644 --- a/server/src/tools/client_credentials_admin.py +++ b/server/src/tools/client_credentials_admin.py @@ -56,8 +56,8 @@ def handle_max_priority_input() -> dict: ) if max_priority_input == "y": queue_name = input( - "Enter the name of the queue(* to apply max priority for", - " all queues): ", + "Enter the name of the queue(* to apply max priority for " + "all queues): ", ) max_priority[queue_name] = int( input("Enter the max priority for this queue: ") @@ -74,8 +74,8 @@ def handle_allowed_queues_input() -> list: allowed_queues = [] while True: allowed_queues_input = input( - "Do you want to specify a restricted queue that", - " you are allowed to use? (y/n): ", + "Do you want to specify a restricted queue that " + "you are allowed to use? (y/n): " ) if allowed_queues_input == "y": queue_name = input("Enter the name of the queue: ") @@ -92,13 +92,13 @@ def handle_max_reservation_input() -> list: max_reservation = {} while True: max_reservation_input = input( - "Do you want to specify a queue to set", - " max reservation time for? (y/n): ", + "Do you want to specify a queue to set " + "max reservation time for? (y/n): " ) if max_reservation_input == "y": queue_name = input( - "Enter the name of the queue(* to apply max reservation", - " for all queues): ", + "Enter the name of the queue(* to apply max reservation " + "for all queues): " ) max_reservation[queue_name] = int( input("Enter the maximum reservation time for this queue: ") @@ -289,8 +289,8 @@ def main(): sys.exit() else: print( - "Invalid selection. Please enter ", - "'c', 'e', 'r', 'aq', 'rq', or 'q'\n", + "Invalid selection. Please enter " + "'c', 'e', 'r', 'aq', 'rq', or 'q'\n" ) From 239d99f27772aa736fadfceafe850f623d450158 Mon Sep 17 00:00:00 2001 From: Varun Valada Date: Mon, 27 Jan 2025 18:05:36 -0600 Subject: [PATCH 4/4] Minor changes --- server/src/tools/client_credentials_admin.py | 22 +++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/server/src/tools/client_credentials_admin.py b/server/src/tools/client_credentials_admin.py index aa5b6c2a..bae30f67 100644 --- a/server/src/tools/client_credentials_admin.py +++ b/server/src/tools/client_credentials_admin.py @@ -95,15 +95,23 @@ def handle_max_reservation_input() -> list: "Do you want to specify a queue to set " "max reservation time for? (y/n): " ) - if max_reservation_input == "y": + if max_reservation_input.lower() == "y": queue_name = input( - "Enter the name of the queue(* to apply max reservation " - "for all queues): " + "Enter the name of the queue " + "(* to apply max reservation for all queues): " ) - max_reservation[queue_name] = int( - input("Enter the maximum reservation time for this queue: ") - ) - elif max_reservation_input == "n": + while True: + try: + max_reservation[queue_name] = int( + input( + "Enter the maximum reservation time " + "for this queue: " + ) + ) + break + except ValueError: + print("Please enter a valid integer value") + elif max_reservation_input.lower() == "n": break else: print("Invalid input. Please enter 'y' or 'n'.")