From 742753618af201f6bf6ded7fc0696a666983dc7d Mon Sep 17 00:00:00 2001 From: CHOPP3D <64507146+Chopped4Life@users.noreply.github.com> Date: Mon, 30 Sep 2024 14:36:37 +0100 Subject: [PATCH] 100 review scripter features return only json new (#119) --- odins_spear/scripts/aa_cc_hg_audit.py | 2 +- odins_spear/scripts/bulk_password_reset.py | 6 +++--- odins_spear/scripts/find_alias.py | 20 ++++++++++++++----- odins_spear/scripts/service_pack_audit.py | 4 +--- .../service_provider_trunking_capacity.py | 2 +- odins_spear/scripts/user_association.py | 2 +- 6 files changed, 22 insertions(+), 14 deletions(-) diff --git a/odins_spear/scripts/aa_cc_hg_audit.py b/odins_spear/scripts/aa_cc_hg_audit.py index f0713dc..93626d5 100644 --- a/odins_spear/scripts/aa_cc_hg_audit.py +++ b/odins_spear/scripts/aa_cc_hg_audit.py @@ -70,6 +70,6 @@ def main(api, service_provider_id: str, group_id: str): del aa_cc_hg["typeTag"] return_data["huntGroups"].append(aa_cc_hg) - return json.dumps(return_data) + return return_data \ No newline at end of file diff --git a/odins_spear/scripts/bulk_password_reset.py b/odins_spear/scripts/bulk_password_reset.py index 68da1ea..12bb508 100644 --- a/odins_spear/scripts/bulk_password_reset.py +++ b/odins_spear/scripts/bulk_password_reset.py @@ -17,7 +17,7 @@ def main(api, service_provider_id: str, group_id: str, users: list, password_typ print("Setting new SIP passwords complete.") formatted_user_and_new_passwords = [{"userId": user[0], "newPassword": user[1]} for user in users_and_new_passwords] - return json.dumps(formatted_user_and_new_passwords) + return formatted_user_and_new_passwords # intigration password elif password_type.lower() == "web": @@ -32,7 +32,7 @@ def main(api, service_provider_id: str, group_id: str, users: list, password_typ print("Setting new SIP passwords complete.") formatted_user_and_new_passwords = [{"userId": user[0], "newPassword": user[1]} for user in users_and_new_passwords] - return json.dumps(formatted_user_and_new_passwords) + return formatted_user_and_new_passwords # voicemail/ oortal elif password_type.lower() == "vm": # voicemail @@ -47,7 +47,7 @@ def main(api, service_provider_id: str, group_id: str, users: list, password_typ print("Setting new voicemail passcodes complete.") formatted_user_and_new_passcodes = [{"userId": user[0], "newPasscode": user[1]} for user in users_and_new_passcodes] - return json.dumps(formatted_user_and_new_passcodes) + return formatted_user_and_new_passcodes # raise error if user attempts to change another type of password. else: diff --git a/odins_spear/scripts/find_alias.py b/odins_spear/scripts/find_alias.py index 425f4ef..ac0690e 100644 --- a/odins_spear/scripts/find_alias.py +++ b/odins_spear/scripts/find_alias.py @@ -1,6 +1,9 @@ import re from tqdm import tqdm +from ..exceptions import OSAliasNotFound + + def locate_alias(alias, aliases: list): for a in aliases: if re.search(rf'\b{alias}\b', a): @@ -108,15 +111,22 @@ def main(api, service_provider_id: str, group_id: str, alias: str): for broadwork_entity in tqdm(OBJECT_WITH_ALIAS, desc=f"Searching AA, HG, and CC for alias {alias}"): if locate_alias(alias, broadwork_entity['aliases']): - return f""" - Alias ({alias}) found: {broadwork_entity['type']} - {broadwork_entity['name']}""" + return { + "alias":alias, + "service_user_id": broadwork_entity[1], + "type":broadwork_entity[0] + } users = api.get.users(service_provider_id, group_id, extended=True) print("Fetched users.") for user in tqdm(users, desc=f"Searching Users for alias: {alias}"): - + if locate_alias(alias, user['aliases']): - return f"\n\n\tAlias ({alias}) found: User - {user['userId']}\n" + return { + "alias": alias, + "user_id": user['userId'], + "type": "user" + } - return f"\n\n\tAlias ({alias}) not found." \ No newline at end of file + return OSAliasNotFound \ No newline at end of file diff --git a/odins_spear/scripts/service_pack_audit.py b/odins_spear/scripts/service_pack_audit.py index d1523f8..c1cdf76 100644 --- a/odins_spear/scripts/service_pack_audit.py +++ b/odins_spear/scripts/service_pack_audit.py @@ -29,6 +29,4 @@ def main(api, service_provider_id, group_id): assigned_service_pack_services.append(sps) - return json.dumps({ - "servicePackServices": assigned_service_pack_services -}) + return {"servicePackServices": assigned_service_pack_services} diff --git a/odins_spear/scripts/service_provider_trunking_capacity.py b/odins_spear/scripts/service_provider_trunking_capacity.py index 8a64c44..20c04bb 100644 --- a/odins_spear/scripts/service_provider_trunking_capacity.py +++ b/odins_spear/scripts/service_provider_trunking_capacity.py @@ -107,4 +107,4 @@ def main(api: object, service_provider_id: str): return_data["callCapacityDifference"] = return_data["maxActiveCalls"] - return_data["groupsCallCapacityTotal"] return_data["burstingCallCapacityDifference"] = return_data["burstingMaxActiveCalls"] - return_data["groupsBurstingCallCapacityTotal"] - return json.dumps(return_data) \ No newline at end of file + return return_data \ No newline at end of file diff --git a/odins_spear/scripts/user_association.py b/odins_spear/scripts/user_association.py index e4d368c..5bbe73d 100644 --- a/odins_spear/scripts/user_association.py +++ b/odins_spear/scripts/user_association.py @@ -56,4 +56,4 @@ def main(api, service_provider_id: str, group_id: str, user_id: str): except Exception: USER_DATA["callCenters"] = None - return json.dumps(USER_DATA) + return USER_DATA