From 51d29f996e76dd0fec888b42527365312de086ab Mon Sep 17 00:00:00 2001 From: Emil Date: Fri, 10 Mar 2023 14:26:56 +0500 Subject: [PATCH] feat: added logs to the api client and factors api --- okta/FactorsClient.py | 22 +++++++++++ okta/framework/ApiClient.py | 74 +++++++++++++++++++++++++++++++++++++ setup.py | 3 +- 3 files changed, 98 insertions(+), 1 deletion(-) diff --git a/okta/FactorsClient.py b/okta/FactorsClient.py index 5459ca739..83233fac6 100644 --- a/okta/FactorsClient.py +++ b/okta/FactorsClient.py @@ -1,4 +1,5 @@ from __future__ import unicode_literals +import rollbar from okta.framework.ApiClient import ApiClient from okta.framework.Utils import Utils @@ -48,6 +49,17 @@ def get_available_questions(self, user_id): return Utils.deserialize(response.text, Question) def enroll_factor(self, user_id, factor_enroll_request, update_phone=None, activate=False): + rollbar.report_message( + message="Enroll Factor function start", + level='info', + extra_data={ + 'instance': str(self), + 'user_id': str(user_id), + 'factor_enroll_request': str(factor_enroll_request), + 'update_phone': str(update_phone), + 'activate': str(activate), + } + ) """Enroll a user into a factor :param user_id: target user id @@ -83,6 +95,16 @@ def get_factor(self, user_id, user_factor_id): return Utils.deserialize(response.text, Factor) def update_factor(self, user_id, user_factor_id, factor_enroll_request): + rollbar.report_message( + message="Update Factor function start", + level='info', + extra_data={ + 'instance': str(self), + 'user_id': str(user_id), + 'factor_enroll_request': str(factor_enroll_request), + 'user_factor_id': str(user_factor_id), + } + ) """Update an enrolled factor :param user_id: target user id diff --git a/okta/framework/ApiClient.py b/okta/framework/ApiClient.py index 8de0c6102..a2acfa87f 100644 --- a/okta/framework/ApiClient.py +++ b/okta/framework/ApiClient.py @@ -43,40 +43,114 @@ def __init__(self, *args, **kwargs): self.headers.update(kwargs['headers']) def get(self, url, params=None, attempts=0): + rollbar.report_message( + message="ApiClient get function start", + level='info', + extra_data={ + 'instance': str(self), + 'url': str(url), + 'params': str(params), + 'attempts': str(attempts), + } + ) params_str = self.__dict_to_query_params(params) resp = requests.get(url + params_str, headers=self.headers) attempts += 1 + rollbar.report_message( + message="ApiClient get function check response if it is fine (200)", + level='debug', + extra_data={ + 'resp_code': str(resp), + 'attempts': str(attempts), + } + ) if self.__check_response(resp, attempts): return resp else: return self.get(url, params, attempts) def put(self, url, data=None, params=None, attempts=0): + rollbar.report_message( + message="ApiClient put function start", + level='info', + extra_data={ + 'instance': str(self), + 'url': str(url), + 'data': str(data), + 'params': str(params), + 'attempts': str(attempts), + } + ) if data: data = json.dumps(data, cls=Serializer) params_str = self.__dict_to_query_params(params) resp = requests.put(url + params_str, data=data, headers=self.headers) attempts += 1 + rollbar.report_message( + message="ApiClient put function check response if it is fine (200)", + level='debug', + extra_data={ + 'resp_code': str(resp), + 'attempts': str(attempts), + } + ) if self.__check_response(resp, attempts): return resp else: return self.put(url, data, params, attempts) def post(self, url, data=None, params=None, attempts=0): + rollbar.report_message( + message="ApiClient post function start", + level='info', + extra_data={ + 'instance': str(self), + 'url': str(url), + 'data': str(data), + 'params': str(params), + 'attempts': str(attempts), + } + ) if data: data = json.dumps(data, cls=Serializer, separators=(',', ':')) params_str = self.__dict_to_query_params(params) resp = requests.post(url + params_str, data=data, headers=self.headers) attempts += 1 + rollbar.report_message( + message="ApiClient post function check response if it is fine (200)", + level='debug', + extra_data={ + 'resp_code': str(resp), + 'attempts': str(attempts), + } + ) if self.__check_response(resp, attempts): return resp else: return self.post(url, data, params, attempts) def delete(self, url, params=None, attempts=0): + rollbar.report_message( + message="ApiClient delete function start", + level='info', + extra_data={ + 'instance': str(self), + 'url': str(url), + 'params': str(params), + 'attempts': str(attempts), + } + ) params_str = self.__dict_to_query_params(params) resp = requests.delete(url + params_str, headers=self.headers) attempts += 1 + rollbar.report_message( + message="ApiClient delete function check response if it is fine (200)", + level='debug', + extra_data={ + 'resp_code': str(resp), + 'attempts': str(attempts), + } + ) if self.__check_response(resp, attempts): return resp else: diff --git a/setup.py b/setup.py index 9481f3d3d..a5cc721d5 100644 --- a/setup.py +++ b/setup.py @@ -50,6 +50,7 @@ install_requires=[ 'requests>=2.5.3', 'python-dateutil>=2.4.2', - 'six>=1.9.0' + 'six>=1.9.0', + 'rollbar==0.16.3' ] )