Skip to content

Commit

Permalink
Update credential script to add ability to set maximum reservation time
Browse files Browse the repository at this point in the history
  • Loading branch information
val500 committed Dec 20, 2024
1 parent a923829 commit 61e2a39
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions server/src/tools/client_credentials_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,28 @@ 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)
Expand Down Expand Up @@ -136,11 +158,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
Expand All @@ -161,11 +185,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:
Expand All @@ -175,6 +201,7 @@ def edit_client_credential(db):
"$set": {
"max_priority": max_priority,
"allowed_queues": allowed_queues,
"max_reservation_time": max_reservation,
}
},
return_document=ReturnDocument.AFTER,
Expand Down

0 comments on commit 61e2a39

Please sign in to comment.