diff --git a/examples/fastapi/requirements.txt b/examples/fastapi/requirements.txt index 79d03c5..ba6628c 100644 --- a/examples/fastapi/requirements.txt +++ b/examples/fastapi/requirements.txt @@ -1,8 +1,8 @@ moesifasgi uvicorn passlib==1.7.4 -moesifapi==1.4.1 -moesifpythonrequest==0.3.2 +moesifapi==1.4.2 +moesifpythonrequest==0.3.3 fastapi==0.108.0 jose==1.0.0 python-jose==3.3.0 @@ -14,4 +14,5 @@ cffi==1.15.0 six==1.16.0 pycparser==2.21 bcrypt -python-multipart \ No newline at end of file +python-multipart +importlib-metadata \ No newline at end of file diff --git a/moesifasgi/app_config.py b/moesifasgi/app_config.py index a87ea15..cf9333e 100644 --- a/moesifasgi/app_config.py +++ b/moesifasgi/app_config.py @@ -1,6 +1,9 @@ from datetime import datetime from moesifapi.exceptions.api_exception import * import json +import logging + +logger = logging.getLogger(__name__) # Application Configuration class AppConfig: @@ -16,14 +19,12 @@ def get_config(cls, api_client, debug): return config_api_response except APIException as inst: if 401 <= inst.response_code <= 403: - print("Unauthorized access getting application configuration. Please check your Application Id.") + logger.error("Unauthorized access getting application configuration. Please check your Application Id.") if debug: - print("Error getting application configuration, with status code:") - print(inst.response_code) + logger.info(f"Error getting application configuration, with status code: {inst.response_code}") except Exception as ex: if debug: - print("Error getting application configuration:") - print(str(ex)) + logger.info(f"Error getting application configuration: {str(ex)}") @classmethod def parse_configuration(cls, config, debug): @@ -32,7 +33,7 @@ def parse_configuration(cls, config, debug): return config.headers.get("X-Moesif-Config-ETag"), json.loads(config.raw_body).get('sample_rate', 100), datetime.utcnow() except: if debug: - print('Error while parsing the configuration object, setting the sample rate to default') + logger.info('Error while parsing the configuration object, setting the sample rate to default') return None, 100, datetime.utcnow() @classmethod @@ -55,8 +56,7 @@ def get_sampling_percentage(cls, config, user_id, company_id): return config_body.get('sample_rate', 100) except Exception as e: - print("Error while parsing user or company sample rate") - print(e) + logger.warning(f"Error while parsing user or company sample rate:{str(e)}") # Use default return 100 diff --git a/moesifasgi/client_ip.py b/moesifasgi/client_ip.py index bb98471..148b155 100644 --- a/moesifasgi/client_ip.py +++ b/moesifasgi/client_ip.py @@ -1,5 +1,9 @@ import re +import logging + +logger = logging.getLogger(__name__) + class ClientIp: @@ -13,14 +17,15 @@ def is_ip(cls, value): ipv6 = r"^((?=.*::)(?!.*::.+::)(::)?([\dA-F]{1,4}:(:|\b)|){5}|([\dA-F]{1,4}:){6})((([\dA-F]{1,4}((?!\3)::|:\b|$))|(?!\2\3)){2}|(((2[0-4]|1\d|[1-9])?\d|25[0-5])\.?\b){4})$/i" return re.match(ipv4, value) or re.match(ipv6, value) - def getClientIpFromXForwardedFor(self, value): + def getClientIpFromXForwardedFor(self, value, debug = False): try: if not value or value is None: return None if not isinstance(value, str): - print("Expected a string, got -" + str(type(value))) + if debug: + logger.info(f"Expected a string, got - {str(type(value))}") else: # x-forwarded-for may return multiple IP addresses in the format: # "client IP, proxy 1 IP, proxy 2 IP" @@ -45,7 +50,7 @@ def getClientIpFromXForwardedFor(self, value): except StopIteration: return value.encode('utf-8') - def get_client_address(self, request_headers, default_host): + def get_client_address(self, request_headers, default_host, debug = False): try: # Standard headers used by Amazon EC2, Heroku, and others. if 'x-client-ip' in request_headers: @@ -54,7 +59,7 @@ def get_client_address(self, request_headers, default_host): # Load-balancers (AWS ELB) or proxies. if 'x-forwarded-for' in request_headers: - xForwardedFor = self.getClientIpFromXForwardedFor(request_headers['x-forwarded-for']) + xForwardedFor = self.getClientIpFromXForwardedFor(request_headers['x-forwarded-for'], debug) if self.is_ip(xForwardedFor): return xForwardedFor diff --git a/moesifasgi/event_mapper.py b/moesifasgi/event_mapper.py index 521a547..74c1326 100644 --- a/moesifasgi/event_mapper.py +++ b/moesifasgi/event_mapper.py @@ -22,7 +22,7 @@ async def to_event(self, request, response, event_req, event_rsp, moesif_setting metadata=await self.logger_helper.get_metadata(moesif_settings, request, response, debug), direction="Incoming") - def to_request(self, request, request_time, request_body, api_version, disable_capture_transaction_id): + def to_request(self, request, request_time, request_body, api_version, disable_capture_transaction_id, debug=False): # Request URI request_uri = request.url._url # Request Verb @@ -41,7 +41,7 @@ def to_request(self, request, request_time, request_body, api_version, disable_c # Add transaction id to the request header request_headers["X-Moesif-Transaction-Id"] = self.transaction_id # Request Ip address - request_ip_address = self.client_ip.get_client_address(request_headers, request.client.host) + request_ip_address = self.client_ip.get_client_address(request_headers, request.client.host, debug) # Request Body req_body = None req_transfer_encoding = None diff --git a/moesifasgi/logger_helper.py b/moesifasgi/logger_helper.py index 1cbd55b..684545d 100644 --- a/moesifasgi/logger_helper.py +++ b/moesifasgi/logger_helper.py @@ -1,6 +1,9 @@ import inspect import json import base64 +import logging + +logger = logging.getLogger(__name__) class LoggerHelper: @@ -44,8 +47,7 @@ def parse_authorization_header(self, token, field, debug): return str(json_decode[field]) except Exception as e: if debug: - print("Error while parsing authorization header to fetch user id.") - print(e) + logger.info(f"Error while parsing authorization header to fetch user id: {str(e)}") return None async def get_user_id(self, middleware_settings, request, response, request_headers, debug): @@ -116,8 +118,7 @@ async def get_user_id(self, middleware_settings, request, response, request_head user_id = self.parse_authorization_header(token, field, debug) except Exception as e: if debug: - print("can not execute identify_user function, please check moesif settings.") - print(e) + logger.info(f"can not execute identify_user function, please check moesif settings: {str(e)}") return user_id async def get_company_id(self, middleware_settings, request, response, debug): @@ -131,8 +132,7 @@ async def get_company_id(self, middleware_settings, request, response, debug): company_id = identify_company(request, response) except Exception as e: if debug: - print("can not execute identify_company function, please check moesif settings.") - print(e) + logger.info(f"can not execute identify_company function, please check moesif settings: {str(e)}") return company_id async def get_metadata(self, middleware_settings, request, response, debug): @@ -146,8 +146,7 @@ async def get_metadata(self, middleware_settings, request, response, debug): metadata = get_metadata(request, response) except Exception as e: if debug: - print("can not execute get_metadata function, please check moesif settings.") - print(e) + logger.info(f"can not execute get_metadata function, please check moesif settings: {str(e)}") return metadata async def get_session_token(self, middleware_settings, request, response, debug): @@ -161,8 +160,7 @@ async def get_session_token(self, middleware_settings, request, response, debug) session_token = get_session_token(request, response) except Exception as e: if debug: - print("Can not execute get_session_token function. Please check moesif settings.") - print(e) + logger.info(f"Can not execute get_session_token function. Please check moesif settings: {str(e)}") return session_token async def should_skip(self, middleware_settings, request, response, debug): @@ -177,7 +175,7 @@ async def should_skip(self, middleware_settings, request, response, debug): return False except Exception as e: if debug: - print("error trying to execute skip function.") + logger.info("error trying to execute skip function.") return False async def mask_event(self, event_model, middleware_settings, debug): @@ -190,5 +188,5 @@ async def mask_event(self, event_model, middleware_settings, debug): event_model = mask_event_model(event_model) except Exception as e: if debug: - print("Can not execute MASK_EVENT_MODEL function. Please check moesif settings.") + logger.info("Can not execute MASK_EVENT_MODEL function. Please check moesif settings.") return event_model diff --git a/moesifasgi/middleware.py b/moesifasgi/middleware.py index cd2a5c6..90c33a2 100644 --- a/moesifasgi/middleware.py +++ b/moesifasgi/middleware.py @@ -22,6 +22,9 @@ import random import queue import atexit +import logging + +logger = logging.getLogger(__name__) class MoesifMiddleware(BaseHTTPMiddleware): @@ -44,11 +47,11 @@ def __init__(self, settings=None, *args, **kwargs): if self.moesif_settings.get('CAPTURE_OUTGOING_REQUESTS', False): try: if self.DEBUG: - print('Start capturing outgoing requests') + logger.info('Start capturing outgoing requests') # Start capturing outgoing requests StartCapture().start_capture_outgoing(self.moesif_settings) except: - print('Error while starting to capture the outgoing events') + logger.warning('Error while starting to capture the outgoing events') self.api_client = self.client.api self.app_config = AppConfig() self.send_async_events = SendEventAsync() @@ -75,14 +78,13 @@ def __init__(self, settings=None, *args, **kwargs): self.config, self.DEBUG) except Exception as ex: if self.DEBUG: - print('Error while parsing application configuration on initialization') - print(str(ex)) + logger.info(f'Error while parsing application configuration on initialization:{str(ex)}') # Function to listen to the send event job response def moesif_event_listener(self, event): if event.exception: if self.DEBUG: - print('Error reading response from the scheduled job') + logger.info('Error reading response from the scheduled job') else: if event.retval: response_etag, self.last_event_job_run_time = event.retval @@ -96,8 +98,7 @@ def moesif_event_listener(self, event): self.config, self.DEBUG) except Exception as ex: if self.DEBUG: - print('Error while updating the application configuration') - print(str(ex)) + logger.info(f'Error while updating the application configuration: {str(ex)}') def schedule_background_job(self): try: @@ -122,8 +123,7 @@ def schedule_background_job(self): atexit.register(lambda: self.send_async_events.exit_handler(self.scheduler, self.DEBUG)) except Exception as ex: if self.DEBUG: - print("Error when scheduling the job") - print(str(ex)) + logger.info(f"Error when scheduling the job: {str(ex)}") def update_user(self, user_profile): User().update_user(user_profile, self.api_client, self.DEBUG) @@ -159,7 +159,7 @@ async def dispatch(self, request, call_next): # request time request_time = self.get_time() if self.DEBUG: - print("event request time: ", request_time) + logger.info(f"event request time: {str(request_time)}") # Read Request Body request_body = None @@ -172,7 +172,7 @@ async def dispatch(self, request, call_next): # response time response_time = self.get_time() if self.DEBUG: - print("event response time: ", response_time) + logger.info(f"event response time: {str(response_time)}") skip = await self.logger_helper.should_skip(self.moesif_settings, request, response, self.DEBUG) if not skip: @@ -184,7 +184,7 @@ async def dispatch(self, request, call_next): if self.sampling_percentage >= random_percentage: # Prepare Event Request Model - event_req = self.event_mapper.to_request(request, request_time, request_body, self.api_version, self.disable_transaction_id) + event_req = self.event_mapper.to_request(request, request_time, request_body, self.api_version, self.disable_transaction_id, self.DEBUG) # Read Response Body resp_body = None @@ -219,25 +219,22 @@ async def dispatch(self, request, call_next): except Exception as ex: self.is_event_job_scheduled = False if self.DEBUG: - print('Error while starting the event scheduler job in background') - print(str(ex)) + logger.info(f'Error while starting the event scheduler job in background: {str(ex)}') # Add Event to the queue if self.DEBUG: - print('Add Event to the queue') + logger.info('Add Event to the queue') self.moesif_events_queue.put(event_data) except Exception as ex: if self.DEBUG: - print("Error while adding event to the queue") - print(str(ex)) + logger.info(f"Error while adding event to the queue: {str(ex)}") else: if self.DEBUG: - print('Skipped Event as the moesif event model is None') + logger.info('Skipped Event as the moesif event model is None') else: if self.DEBUG: - print("Skipped Event due to sampling percentage: " + str(self.sampling_percentage) - + " and random percentage: " + str(random_percentage)) + logger.info(f"Skipped Event due to sampling percentage: {str(self.sampling_percentage)} and random percentage: {str(random_percentage)}") else: if self.DEBUG: - print('Skipped Event using should_skip configuration option') + logger.info('Skipped Event using should_skip configuration option') return response diff --git a/moesifasgi/send_batch_events.py b/moesifasgi/send_batch_events.py index 64abd9d..608fb78 100644 --- a/moesifasgi/send_batch_events.py +++ b/moesifasgi/send_batch_events.py @@ -1,5 +1,7 @@ from datetime import datetime +import logging +logger = logging.getLogger(__name__) class SendEventAsync: @@ -14,25 +16,23 @@ def exit_handler(cls, scheduler, debug): scheduler.shutdown() except Exception as ex: if debug: - print("Error while closing the queue or scheduler shut down") - print(str(ex)) + logger.info(f"Error while closing the queue or scheduler shut down: {str(ex)}") @classmethod def send_events(cls, api_client, batch_events, debug): try: if debug: - print("Sending events to Moesif") + logger.info("Sending events to Moesif") batch_events_api_response = api_client.create_events_batch(batch_events) if debug: - print("Events sent successfully") + logger.info("Events sent successfully") # Fetch Config ETag from response header batch_events_response_config_etag = batch_events_api_response.get("X-Moesif-Config-ETag") # Return Config Etag return batch_events_response_config_etag except Exception as ex: if debug: - print("Error sending event to Moesif") - print(str(ex)) + logger.info(f"Error sending event to Moesif: {str(ex)}") return None def batch_events(self, api_client, moesif_events_queue, debug, batch_size): @@ -49,11 +49,11 @@ def batch_events(self, api_client, moesif_events_queue, debug, batch_size): return batch_response, datetime.utcnow() else: if debug: - print("No events to send") + logger.info("No events to send") # Set the last time event job ran but no message to read from the queue return None, datetime.utcnow() except: if debug: - print("No message to read from the queue") + logger.info("No message to read from the queue") # Set the last time event job ran when exception occurred while sending event return None, datetime.utcnow() diff --git a/moesifasgi/update_companies.py b/moesifasgi/update_companies.py index c6e836c..f02fe2e 100644 --- a/moesifasgi/update_companies.py +++ b/moesifasgi/update_companies.py @@ -1,6 +1,9 @@ from moesifapi.models import * from moesifapi.exceptions.api_exception import * from moesifapi.api_helper import * +import logging + +logger = logging.getLogger(__name__) class Company: @@ -11,37 +14,38 @@ def __init__(self): @classmethod def update_company(cls, company_profile, api_client, DEBUG): if not company_profile: - print('Expecting the input to be either of the type - CompanyModel, dict or json while updating company') + if DEBUG: + logger.info('Expecting the input to be either of the type - CompanyModel, dict or json while updating company') else: if isinstance(company_profile, dict): if 'company_id' in company_profile: try: api_client.update_company(CompanyModel.from_dictionary(company_profile)) if DEBUG: - print('Company Profile updated successfully') + logger.info('Company Profile updated successfully') except APIException as inst: if 401 <= inst.response_code <= 403: - print("Unauthorized access sending event to Moesif. Please check your Appplication Id.") + logger.error("Unauthorized access sending event to Moesif. Please check your Appplication Id.") if DEBUG: - print("Error while updating company, with status code:") - print(inst.response_code) + logger.info(f"Error while updating company, with status code: {str(inst.response_code)}") else: - print('To update an company, an company_id field is required') + if DEBUG: + logger.info('To update an company, an company_id field is required') elif isinstance(company_profile, CompanyModel): if company_profile.company_id is not None: try: api_client.update_company(company_profile) if DEBUG: - print('Company Profile updated successfully') + logger.info('Company Profile updated successfully') except APIException as inst: if 401 <= inst.response_code <= 403: - print("Unauthorized access sending event to Moesif. Please check your Appplication Id.") + logger.error("Unauthorized access sending event to Moesif. Please check your Appplication Id.") if DEBUG: - print("Error while updating company, with status code:") - print(inst.response_code) + logger.info(f"Error while updating company, with status code: {str(inst.response_code)}") else: - print('To update a company, a company_id field is required') + if DEBUG: + logger.info('To update a company, a company_id field is required') else: try: company_profile_json = APIHelper.json_deserialize(company_profile) @@ -49,22 +53,22 @@ def update_company(cls, company_profile, api_client, DEBUG): try: api_client.update_company(CompanyModel.from_dictionary(company_profile_json)) if DEBUG: - print('Company Profile updated successfully') + logger.info('Company Profile updated successfully') except APIException as inst: if 401 <= inst.response_code <= 403: - print("Unauthorized access sending event to Moesif. Please check your Appplication Id.") + logger.error("Unauthorized access sending event to Moesif. Please check your Appplication Id.") if DEBUG: - print("Error while updating company, with status code:") - print(inst.response_code) + logger.info(f"Error while updating company, with status code: {str(inst.response_code)}") else: - print('To update a company, an company_id field is required') + if DEBUG: + logger.info('To update a company, an company_id field is required') except: - print('Error while deserializing the json, please make sure the json is valid') + logger.warning('Error while deserializing the json, please make sure the json is valid') @classmethod def update_companies_batch(cls, company_profiles, api_client, DEBUG): if not company_profiles: - print('Expecting the input to be either of the type - List of CompanyModel, dict or json while updating companies') + logger.info('Expecting the input to be either of the type - List of CompanyModel, dict or json while updating companies') else: if all(isinstance(company, dict) for company in company_profiles): if all('company_id' in company for company in company_profiles): @@ -72,30 +76,28 @@ def update_companies_batch(cls, company_profiles, api_client, DEBUG): batch_profiles = [CompanyModel.from_dictionary(d) for d in company_profiles] api_client.update_companies_batch(batch_profiles) if DEBUG: - print('Company Profile updated successfully') + logger.info('Company Profile updated successfully') except APIException as inst: if 401 <= inst.response_code <= 403: - print("Unauthorized access sending event to Moesif. Please check your Appplication Id.") + logger.error("Unauthorized access sending event to Moesif. Please check your Appplication Id.") if DEBUG: - print("Error while updating companies, with status code:") - print(inst.response_code) + logger.info("Error while updating companies, with status code: {str(inst.response_code)}") else: - print('To update companies, an company_id field is required') + logger.error('To update companies, an company_id field is required') elif all(isinstance(company, CompanyModel) for company in company_profiles): if all(company.company_id is not None for company in company_profiles): try: api_client.update_companies_batch(company_profiles) if DEBUG: - print('Company Profile updated successfully') + logger.info('Company Profile updated successfully') except APIException as inst: if 401 <= inst.response_code <= 403: - print("Unauthorized access sending event to Moesif. Please check your Appplication Id.") + logger.error("Unauthorized access sending event to Moesif. Please check your Appplication Id.") if DEBUG: - print("Error while updating companies, with status code:") - print(inst.response_code) + logger.info(f"Error while updating companies, with status code: {str(inst.response_code)}") else: - print('To update companies, an company_id field is required') + logger.error('To update companies, an company_id field is required') else: try: company_profiles_json = [APIHelper.json_deserialize(d) for d in company_profiles] @@ -105,14 +107,13 @@ def update_companies_batch(cls, company_profiles, api_client, DEBUG): batch_profiles = [CompanyModel.from_dictionary(d) for d in company_profiles_json] api_client.update_companies_batch(batch_profiles) if DEBUG: - print('Company Profile updated successfully') + logger.info('Company Profile updated successfully') except APIException as inst: if 401 <= inst.response_code <= 403: - print("Unauthorized access sending event to Moesif. Please check your Appplication Id.") + logger.error("Unauthorized access sending event to Moesif. Please check your Appplication Id.") if DEBUG: - print("Error while updating companies, with status code:") - print(inst.response_code) + logger.info(f"Error while updating companies, with status code: {str(inst.response_code)}") else: - print('To update companies, an company_id field is required') + logger.error('To update companies, an company_id field is required') except: - print('Error while deserializing the json, please make sure the json is valid') + logger.warning('Error while deserializing the json, please make sure the json is valid') diff --git a/moesifasgi/update_users.py b/moesifasgi/update_users.py index d64e531..1dbd04e 100644 --- a/moesifasgi/update_users.py +++ b/moesifasgi/update_users.py @@ -1,7 +1,9 @@ from moesifapi.models import * from moesifapi.exceptions.api_exception import * from moesifapi.api_helper import * +import logging +logger = logging.getLogger(__name__) class User: @@ -11,37 +13,36 @@ def __init__(self): @classmethod def update_user(cls, user_profile, api_client, DEBUG): if not user_profile: - print('Expecting the input to be either of the type - UserModel, dict or json while updating user') + if DEBUG: + logger.info('Expecting the input to be either of the type - UserModel, dict or json while updating user') else: if isinstance(user_profile, dict): if 'user_id' in user_profile: try: api_client.update_user(UserModel.from_dictionary(user_profile)) if DEBUG: - print('User Profile updated successfully') + logger.info('User Profile updated successfully') except APIException as inst: if 401 <= inst.response_code <= 403: - print("Unauthorized access sending event to Moesif. Please check your Appplication Id.") + logger.error("Unauthorized access sending event to Moesif. Please check your Appplication Id.") if DEBUG: - print("Error while updating user, with status code:") - print(inst.response_code) + logger.info(f"Error while updating user, with status code: {str(inst.response_code)}") else: - print('To update an user, an user_id field is required') + logger.error('To update an user, an user_id field is required') elif isinstance(user_profile, UserModel): if user_profile.user_id is not None: try: api_client.update_user(user_profile) if DEBUG: - print('User Profile updated successfully') + logger.info('User Profile updated successfully') except APIException as inst: if 401 <= inst.response_code <= 403: - print("Unauthorized access sending event to Moesif. Please check your Appplication Id.") + logger.error("Unauthorized access sending event to Moesif. Please check your Appplication Id.") if DEBUG: - print("Error while updating user, with status code:") - print(inst.response_code) + logger.info(f"Error while updating user, with status code: {str(inst.response_code)}") else: - print('To update an user, an user_id field is required') + logger.error('To update an user, an user_id field is required') else: try: user_profile_json = APIHelper.json_deserialize(user_profile) @@ -49,22 +50,22 @@ def update_user(cls, user_profile, api_client, DEBUG): try: api_client.update_user(UserModel.from_dictionary(user_profile_json)) if DEBUG: - print('User Profile updated successfully') + logger.info('User Profile updated successfully') except APIException as inst: if 401 <= inst.response_code <= 403: - print("Unauthorized access sending event to Moesif. Please check your Appplication Id.") + logger.error("Unauthorized access sending event to Moesif. Please check your Appplication Id.") if DEBUG: - print("Error while updating user, with status code:") - print(inst.response_code) + logger.info(f"Error while updating user, with status code: {str(inst.response_code)}") else: - print('To update an user, an user_id field is required') + logger.error('To update an user, an user_id field is required') except: - print('Error while deserializing the json, please make sure the json is valid') + logger.warning('Error while deserializing the json, please make sure the json is valid') @classmethod def update_users_batch(cls, user_profiles, api_client, DEBUG): if not user_profiles: - print('Expecting the input to be either of the type - List of UserModel, dict or json while updating users') + if DEBUG: + logger.info('Expecting the input to be either of the type - List of UserModel, dict or json while updating users') else: if all(isinstance(user, dict) for user in user_profiles): if all('user_id' in user for user in user_profiles): @@ -72,30 +73,28 @@ def update_users_batch(cls, user_profiles, api_client, DEBUG): batch_profiles = [UserModel.from_dictionary(d) for d in user_profiles] api_client.update_users_batch(batch_profiles) if DEBUG: - print('User Profile updated successfully') + logger.info('User Profile updated successfully') except APIException as inst: if 401 <= inst.response_code <= 403: - print("Unauthorized access sending event to Moesif. Please check your Appplication Id.") + logger.error("Unauthorized access sending event to Moesif. Please check your Appplication Id.") if DEBUG: - print("Error while updating users, with status code:") - print(inst.response_code) + logger.info(f"Error while updating users, with status code: {str(inst.response_code)}") else: - print('To update users, an user_id field is required') + logger.error('To update users, an user_id field is required') elif all(isinstance(user, UserModel) for user in user_profiles): if all(user.user_id is not None for user in user_profiles): try: api_client.update_users_batch(user_profiles) if DEBUG: - print('User Profile updated successfully') + logger.info('User Profile updated successfully') except APIException as inst: if 401 <= inst.response_code <= 403: - print("Unauthorized access sending event to Moesif. Please check your Appplication Id.") + logger.error("Unauthorized access sending event to Moesif. Please check your Appplication Id.") if DEBUG: - print("Error while updating users, with status code:") - print(inst.response_code) + logger.info(f"Error while updating users, with status code: {str(inst.response_code)}") else: - print('To update users, an user_id field is required') + logger.error('To update users, an user_id field is required') else: try: user_profiles_json = [APIHelper.json_deserialize(d) for d in user_profiles] @@ -105,14 +104,13 @@ def update_users_batch(cls, user_profiles, api_client, DEBUG): batch_profiles = [UserModel.from_dictionary(d) for d in user_profiles_json] api_client.update_users_batch(batch_profiles) if DEBUG: - print('User Profile updated successfully') + logger.info('User Profile updated successfully') except APIException as inst: if 401 <= inst.response_code <= 403: - print("Unauthorized access sending event to Moesif. Please check your Appplication Id.") + logger.error("Unauthorized access sending event to Moesif. Please check your Appplication Id.") if DEBUG: - print("Error while updating users, with status code:") - print(inst.response_code) + logger.info(f"Error while updating users, with status code: {str(inst.response_code)}") else: - print('To update users, an user_id field is required') + logger.error('To update users, an user_id field is required') except: - print('Error while deserializing the json, please make sure the json is valid') + logger.warning('Error while deserializing the json, please make sure the json is valid') diff --git a/requirements.txt b/requirements.txt index e966651..db391eb 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,4 +1,4 @@ nose==1.3.7 -moesifapi==1.4.0 -moesifpythonrequest==0.3.2 +moesifapi==1.4.2 +moesifpythonrequest==0.3.3 starlette==0.16.0 \ No newline at end of file diff --git a/setup.py b/setup.py index 63be906..25d3cef 100644 --- a/setup.py +++ b/setup.py @@ -28,7 +28,7 @@ # Versions should comply with PEP440. For a discussion on single-sourcing # the version across setup.py and the project code, see # https://packaging.python.org/en/latest/single_source_version.html - version='0.1.6', + version='0.1.7', description='Moesif Middleware for Python ASGI based platforms (FastAPI & Others)', long_description=long_description, @@ -82,7 +82,7 @@ # your project is installed. For an analysis of "install_requires" vs pip's # requirements files see: # https://packaging.python.org/en/latest/requirements.html - install_requires=['starlette', 'moesifapi>=1.4.0', 'moesifpythonrequest>=0.2.0', 'apscheduler'], + install_requires=['starlette', 'moesifapi>=1.4.2', 'moesifpythonrequest>=0.3.3', 'apscheduler'], # List additional groups of dependencies here (e.g. development # dependencies). You can install these using the following syntax,