From feaad16e3669b3b45cef9dc342a8b45c9348de1f Mon Sep 17 00:00:00 2001 From: Meganerd <114895043+MeganerdDev@users.noreply.github.com> Date: Wed, 10 May 2023 14:06:59 -0400 Subject: [PATCH 1/6] Update ms_teams.py Add try/except block for slicing access_token from response Add debug logger stdout on exception --- nautobot_chatops/dispatchers/ms_teams.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/nautobot_chatops/dispatchers/ms_teams.py b/nautobot_chatops/dispatchers/ms_teams.py index f78d41ac..7c21f268 100644 --- a/nautobot_chatops/dispatchers/ms_teams.py +++ b/nautobot_chatops/dispatchers/ms_teams.py @@ -63,7 +63,11 @@ def get_token(): }, timeout=15, ) - token = response.json()["access_token"] + try: + token = response.json()["access_token"] + except(KeyError) : + logger.error("ERROR: get_token() response is missing access_token key") + raise KeyError("get_token() response is missing access_token key") return token def _send(self, content, content_type="message"): From 4a3fff65850e0601266f07a7b78782fbed479d00 Mon Sep 17 00:00:00 2001 From: Meganerd <114895043+MeganerdDev@users.noreply.github.com> Date: Wed, 10 May 2023 14:24:15 -0400 Subject: [PATCH 2/6] Create 197.added --- changes/197.added | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/197.added diff --git a/changes/197.added b/changes/197.added new file mode 100644 index 00000000..2cab61aa --- /dev/null +++ b/changes/197.added @@ -0,0 +1 @@ +Add a try/except block and error logger message when access_token missing from get_token() response. From e7bb1ff6f275ca2ef2bb4343a102c3df41a96d44 Mon Sep 17 00:00:00 2001 From: Meganerd <114895043+MeganerdDev@users.noreply.github.com> Date: Wed, 10 May 2023 14:26:42 -0400 Subject: [PATCH 3/6] Update ms_teams.py Added debug log message --- nautobot_chatops/dispatchers/ms_teams.py | 1 + 1 file changed, 1 insertion(+) diff --git a/nautobot_chatops/dispatchers/ms_teams.py b/nautobot_chatops/dispatchers/ms_teams.py index 7c21f268..18706e42 100644 --- a/nautobot_chatops/dispatchers/ms_teams.py +++ b/nautobot_chatops/dispatchers/ms_teams.py @@ -63,6 +63,7 @@ def get_token(): }, timeout=15, ) + logger.debug(f"DEBUG: get_token() response {response.json()}") try: token = response.json()["access_token"] except(KeyError) : From 0984e23405751f0ff154e4d0c1b4f772b11e4ebf Mon Sep 17 00:00:00 2001 From: Meganerd <114895043+MeganerdDev@users.noreply.github.com> Date: Thu, 11 May 2023 23:26:19 -0400 Subject: [PATCH 4/6] Update ms_teams.py More verbosity for error --- nautobot_chatops/dispatchers/ms_teams.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/nautobot_chatops/dispatchers/ms_teams.py b/nautobot_chatops/dispatchers/ms_teams.py index 18706e42..e86868b0 100644 --- a/nautobot_chatops/dispatchers/ms_teams.py +++ b/nautobot_chatops/dispatchers/ms_teams.py @@ -67,8 +67,8 @@ def get_token(): try: token = response.json()["access_token"] except(KeyError) : - logger.error("ERROR: get_token() response is missing access_token key") - raise KeyError("get_token() response is missing access_token key") + logger.error("ERROR: get_token() response is missing access_token key, which indicates an error communicating with MS Teams. Check the app_id and app_secret.") + raise KeyError("get_token() response is missing access_token key, which indicates an error communicating with MS Teams. Check the app_id and app_secret.") return token def _send(self, content, content_type="message"): From 072824e708183eb58f1b9c3b9d350a8867dc68cd Mon Sep 17 00:00:00 2001 From: meganerd Date: Sat, 27 May 2023 14:36:35 -0400 Subject: [PATCH 5/6] + Run black code formatterw --- nautobot_chatops/dispatchers/ms_teams.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/nautobot_chatops/dispatchers/ms_teams.py b/nautobot_chatops/dispatchers/ms_teams.py index e86868b0..7e14eaa2 100644 --- a/nautobot_chatops/dispatchers/ms_teams.py +++ b/nautobot_chatops/dispatchers/ms_teams.py @@ -66,9 +66,13 @@ def get_token(): logger.debug(f"DEBUG: get_token() response {response.json()}") try: token = response.json()["access_token"] - except(KeyError) : - logger.error("ERROR: get_token() response is missing access_token key, which indicates an error communicating with MS Teams. Check the app_id and app_secret.") - raise KeyError("get_token() response is missing access_token key, which indicates an error communicating with MS Teams. Check the app_id and app_secret.") + except KeyError: + logger.error( + "ERROR: get_token() response is missing access_token key, which indicates an error communicating with MS Teams. Check the app_id and app_secret." + ) + raise KeyError( + "get_token() response is missing access_token key, which indicates an error communicating with MS Teams. Check the app_id and app_secret." + ) return token def _send(self, content, content_type="message"): From d790829c1c61b90a6265be21c51eda491b72d446 Mon Sep 17 00:00:00 2001 From: Stephen Kiely Date: Wed, 31 May 2023 09:23:01 -0500 Subject: [PATCH 6/6] Fix Pylint errors --- nautobot_chatops/dispatchers/ms_teams.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/nautobot_chatops/dispatchers/ms_teams.py b/nautobot_chatops/dispatchers/ms_teams.py index 7e14eaa2..0944b352 100644 --- a/nautobot_chatops/dispatchers/ms_teams.py +++ b/nautobot_chatops/dispatchers/ms_teams.py @@ -63,16 +63,18 @@ def get_token(): }, timeout=15, ) - logger.debug(f"DEBUG: get_token() response {response.json()}") + logger.debug("DEBUG: get_token() response %s", response.json()) try: token = response.json()["access_token"] - except KeyError: + except KeyError as exc: logger.error( - "ERROR: get_token() response is missing access_token key, which indicates an error communicating with MS Teams. Check the app_id and app_secret." + "get_token() response is missing access_token, which indicates an error authenticating with MS Teams." + "Check the app_id and app_secret." ) raise KeyError( - "get_token() response is missing access_token key, which indicates an error communicating with MS Teams. Check the app_id and app_secret." - ) + "get_token() response is missing access_token, which indicates an error authenticating with MS Teams." + "Check the app_id and app_secret." + ) from exc return token def _send(self, content, content_type="message"):