From be23951e000d72691204991f3764ee651a7dd1c8 Mon Sep 17 00:00:00 2001 From: Malkin0xb Date: Thu, 12 Dec 2024 10:25:32 +0000 Subject: [PATCH 1/5] init --- odins_spear/scripts/aa_cc_hg_audit.py | 85 ++++++++------------------- 1 file changed, 23 insertions(+), 62 deletions(-) diff --git a/odins_spear/scripts/aa_cc_hg_audit.py b/odins_spear/scripts/aa_cc_hg_audit.py index 3dafca7..84223cc 100644 --- a/odins_spear/scripts/aa_cc_hg_audit.py +++ b/odins_spear/scripts/aa_cc_hg_audit.py @@ -1,74 +1,35 @@ from tqdm import tqdm -def remove_excess_details(aa_cc_hg: dict): - del aa_cc_hg["name"] - del aa_cc_hg["phoneNumber"] - del aa_cc_hg["extension"] - del aa_cc_hg["department"] - del aa_cc_hg["isActive"] - - if aa_cc_hg["typeTag"] == "AA": - del aa_cc_hg["video"] - elif aa_cc_hg["typeTag"] == "CC": - del aa_cc_hg["video"] - del aa_cc_hg["policy"] - elif aa_cc_hg["typeTag"] == "HG": - del aa_cc_hg["serviceProviderId"] - del aa_cc_hg["groupId"] - del aa_cc_hg["policy"] - + def main(api, service_provider_id: str, group_id: str): """ - This script returns the services assigned to Auto Attendants, - Call Centres, and Hunt Groups. Only services are applied to these - entities and there are scenarios one would need to focus services + This script returns the services assigned to Auto Attendants, + Call Centres, and Hunt Groups. Only services are applied to these + entities and there are scenarios one would need to focus services assigned to these entities. - :param service_provider_id: Service Provider ID or Enterprise ID containing the Group ID. :param group_id: Group ID to generate the report for. - :return JSON: A JSON formatted report of service packs assigned to AA, CC, and HG. - """ - + :return JSON: A JSON formatted report of service packs assigned to AA, CC, and HG. + """ print("aa_cc_hg_audit start.") - return_data = { - "autoAttendants": [], - "callCenters": [], - "huntGroups": [] - } - auto_attendants = api.get.auto_attendants(service_provider_id, group_id) - call_centers = api.get.group_call_centers(service_provider_id, group_id) - hunt_groups = api.get.group_hunt_groups(service_provider_id, group_id) - - for aa in tqdm(auto_attendants, desc="Analysing Auto Attendants"): - aa["typeTag"] = "AA" - remove_excess_details(aa) + return_data = {"autoAttendants": [], "callCenters": [], "huntGroups": []} + + for entity_type, api_method in [ + ("autoAttendants", api.get_auto_attendants), + ("callCenters", api.get_group_call_centers), + ("huntGroups", api.get_group_hunt_groups), + ]: + entities = api_method(service_provider_id, group_id) + for entity in tqdm(entities, desc=f"Analysing {entity_type.capitalize()}"): + services = api.get_user_services_assigned(entity["serviceUserId"]) + return_data[entity_type].append( + { + "serviceUserId": entity["serviceUserId"], + "type": entity["type"], + "services": services.get("userServices", []), + } + ) - for cc in tqdm(call_centers, desc="Analysing Call Centers"): - cc["typeTag"] = "CC" - remove_excess_details(cc) - - for hg in tqdm(hunt_groups, desc="Analysing Hunt Groups"): - hg["typeTag"] = "HG" - remove_excess_details(hg) - - aa_cc_hgs = auto_attendants + call_centers + hunt_groups - - for aa_cc_hg in tqdm(aa_cc_hgs, desc="Fetching User Services"): - response = api.get.user_services_assigned(aa_cc_hg["serviceUserId"]) - aa_cc_hg["services"] = response["userServices"] - - if aa_cc_hg["typeTag"] == "AA": - del aa_cc_hg["typeTag"] - return_data["autoAttendants"].append(aa_cc_hg) - elif aa_cc_hg["typeTag"] == "CC": - del aa_cc_hg["typeTag"] - return_data["callCenters"].append(aa_cc_hg) - elif aa_cc_hg["typeTag"] == "HG": - del aa_cc_hg["typeTag"] - return_data["huntGroups"].append(aa_cc_hg) - return return_data - - \ No newline at end of file From 00ae497a0f96b13fe54cf2256e5bcf8921f8f547 Mon Sep 17 00:00:00 2001 From: Malkin0xb Date: Thu, 12 Dec 2024 13:11:52 +0000 Subject: [PATCH 2/5] api function fix --- odins_spear/scripts/aa_cc_hg_audit.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/odins_spear/scripts/aa_cc_hg_audit.py b/odins_spear/scripts/aa_cc_hg_audit.py index 84223cc..fb47274 100644 --- a/odins_spear/scripts/aa_cc_hg_audit.py +++ b/odins_spear/scripts/aa_cc_hg_audit.py @@ -17,13 +17,13 @@ def main(api, service_provider_id: str, group_id: str): return_data = {"autoAttendants": [], "callCenters": [], "huntGroups": []} for entity_type, api_method in [ - ("autoAttendants", api.get_auto_attendants), - ("callCenters", api.get_group_call_centers), - ("huntGroups", api.get_group_hunt_groups), + ("autoAttendants", api.auto_attendant.get_auto_attendants), + ("callCenters", api.call_centers.get_group_call_centers), + ("huntGroups", api.hunt_groups.get_group_hunt_groups), ]: entities = api_method(service_provider_id, group_id) for entity in tqdm(entities, desc=f"Analysing {entity_type.capitalize()}"): - services = api.get_user_services_assigned(entity["serviceUserId"]) + services = api.services.get_user_services(entity["serviceUserId"]) return_data[entity_type].append( { "serviceUserId": entity["serviceUserId"], From 4de4f227270837c7cf7e621188f3b3e1e8c5c9bd Mon Sep 17 00:00:00 2001 From: Malkin0xb Date: Thu, 12 Dec 2024 16:55:35 +0000 Subject: [PATCH 3/5] Added default value & assigned services --- odins_spear/scripts/aa_cc_hg_audit.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/odins_spear/scripts/aa_cc_hg_audit.py b/odins_spear/scripts/aa_cc_hg_audit.py index fb47274..7eeaf53 100644 --- a/odins_spear/scripts/aa_cc_hg_audit.py +++ b/odins_spear/scripts/aa_cc_hg_audit.py @@ -23,11 +23,11 @@ def main(api, service_provider_id: str, group_id: str): ]: entities = api_method(service_provider_id, group_id) for entity in tqdm(entities, desc=f"Analysing {entity_type.capitalize()}"): - services = api.services.get_user_services(entity["serviceUserId"]) + services = api.services.get_user_services_assigned(entity["serviceUserId"]) return_data[entity_type].append( { "serviceUserId": entity["serviceUserId"], - "type": entity["type"], + "type": entity.get("type", "None"), "services": services.get("userServices", []), } ) From e00ac8d4084c73609eaa1ced18edfc7796175356 Mon Sep 17 00:00:00 2001 From: Jordan Date: Wed, 18 Dec 2024 09:43:02 +0000 Subject: [PATCH 4/5] slight adjustments --- odins_spear/api.py | 4 ++-- odins_spear/endpoints/services.py | 14 +++++++------- odins_spear/scripts/aa_cc_hg_audit.py | 26 ++++++++------------------ 3 files changed, 17 insertions(+), 27 deletions(-) diff --git a/odins_spear/api.py b/odins_spear/api.py index 7e19c2d..42904b7 100644 --- a/odins_spear/api.py +++ b/odins_spear/api.py @@ -47,7 +47,7 @@ def __init__( self.administrators = Administrators() self.alternate_numbers = AlternateNumbers() - self.auto_attendant = AutoAttendants() + self.auto_attendants = AutoAttendants() self.call_centers = CallCenters() self.call_forwarding_always = CallForwardingAlways() self.call_processing_policies = CallProcessingPolicies() @@ -172,6 +172,6 @@ def _update_requester(self, session_response: requests.models.Response): def __str__(self) -> str: return ( - f"API - url: {self.base_url}, username: {self.username}" + f"API - url: {self.base_url}, username: {self.username} " f"Authenticated: {self.authorised}" ) diff --git a/odins_spear/endpoints/services.py b/odins_spear/endpoints/services.py index ab6e92e..25f7c86 100644 --- a/odins_spear/endpoints/services.py +++ b/odins_spear/endpoints/services.py @@ -17,7 +17,7 @@ def get_user_services_assigned(self, user_id: str): params = {"userId": user_id} - return self.requester.get(endpoint, params=params) + return self._requester.get(endpoint, params=params) def get_user_services(self, user_id: str): """Fetch all services assigned to a broadwrok entity, this can be @@ -34,7 +34,7 @@ def get_user_services(self, user_id: str): params = {"userId": user_id} - return self.requester.get(endpoint, params=params) + return self._requester.get(endpoint, params=params) def get_user_service_settings(self, user_id: str): """Retrieves all service settings for a specific user. @@ -50,7 +50,7 @@ def get_user_service_settings(self, user_id: str): params = {"userId": user_id} - return self.requester.get(endpoint, params=params) + return self._requester.get(endpoint, params=params) def get_group_services(self, group_id: str, service_provider_id: str): """ @@ -68,7 +68,7 @@ def get_group_services(self, group_id: str, service_provider_id: str): params = {"groupId": group_id, "serviceProviderId": service_provider_id} - return self.requester.get(endpoint, params=params) + return self._requester.get(endpoint, params=params) def get_group_services_user_assigned( self, @@ -99,7 +99,7 @@ def get_group_services_user_assigned( "serviceName": service_name, } - return self.requester.get(endpoint, params=params) + return self._requester.get(endpoint, params=params) # POST @@ -137,7 +137,7 @@ def put_user_services( {"serviceName": service_pack, "assigned": assigned} for service_pack in service_packs ] - return self.requester.put(endpoint, data=data) + return self._requester.put(endpoint, data=data) def put_user_service_settings(self, user_id: str, settings: dict): """Updates specific service settings for a given user. @@ -155,7 +155,7 @@ def put_user_service_settings(self, user_id: str, settings: dict): data = {"userId": user_id, **settings} - return self.requester.put(endpoint, data=data) + return self._requester.put(endpoint, data=data) # DELETE diff --git a/odins_spear/scripts/aa_cc_hg_audit.py b/odins_spear/scripts/aa_cc_hg_audit.py index 7eeaf53..9f6d9c5 100644 --- a/odins_spear/scripts/aa_cc_hg_audit.py +++ b/odins_spear/scripts/aa_cc_hg_audit.py @@ -1,28 +1,18 @@ from tqdm import tqdm -def main(api, service_provider_id: str, group_id: str): - """ - This script returns the services assigned to Auto Attendants, - Call Centres, and Hunt Groups. Only services are applied to these - entities and there are scenarios one would need to focus services - assigned to these entities. - - :param service_provider_id: Service Provider ID or Enterprise ID containing the Group ID. - :param group_id: Group ID to generate the report for. - - :return JSON: A JSON formatted report of service packs assigned to AA, CC, and HG. - """ - print("aa_cc_hg_audit start.") - return_data = {"autoAttendants": [], "callCenters": [], "huntGroups": []} +def main(api, service_provider_id: str, group_id: str) -> dict: + return_data = {"auto_attendants": [], "call_centers": [], "hunt_groups": []} for entity_type, api_method in [ - ("autoAttendants", api.auto_attendant.get_auto_attendants), - ("callCenters", api.call_centers.get_group_call_centers), - ("huntGroups", api.hunt_groups.get_group_hunt_groups), + ("auto_attendants", api.auto_attendants.get_auto_attendants), + ("call_centers", api.call_centers.get_group_call_centers), + ("hunt_groups", api.hunt_groups.get_group_hunt_groups), ]: entities = api_method(service_provider_id, group_id) - for entity in tqdm(entities, desc=f"Analysing {entity_type.capitalize()}"): + for entity in tqdm( + entities, desc=f"Analysing {entity_type.replace("_", " ").title()}" + ): services = api.services.get_user_services_assigned(entity["serviceUserId"]) return_data[entity_type].append( { From 6b897c3f9c315cd59d7a303b6d13399d2b1f85a3 Mon Sep 17 00:00:00 2001 From: Jordan-Prescott Date: Tue, 14 Jan 2025 11:54:10 +0000 Subject: [PATCH 5/5] removed api importing scripter and reporter --- odins_spear/api.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/odins_spear/api.py b/odins_spear/api.py index c092dfc..c819d36 100644 --- a/odins_spear/api.py +++ b/odins_spear/api.py @@ -1,7 +1,6 @@ from .requester import Requester from .logger import Logger -from .scripter import Scripter -from .reporter import Reporter + from .exceptions import ( OSApiAuthenticationFail, @@ -42,8 +41,6 @@ def __init__( self.logger = Logger.get_instance(self.username) self._requester = Requester(self.base_url, self.rate_limit, self.logger) - self.scripter = Scripter(api=self) - self.reporter = Reporter(api=self) self.administrators = Administrators() self.alternate_numbers = AlternateNumbers() self.authentication = Authentication()