From 3afddc0bd9909fa0d31863b5cf1121647504d929 Mon Sep 17 00:00:00 2001 From: Keyur Date: Tue, 28 Nov 2023 21:02:29 -0800 Subject: [PATCH] Refactor: Allow BaseUri to be set without depending on debug mode (#82) Refactor: Allow BaseUri to be set without depending on debug mode Bump version to 2.3.6 --- moesifdjango/logger_helper.py | 9 +++++++++ moesifdjango/middleware.py | 16 +++------------- moesifdjango/middleware_pre19.py | 16 +++------------- setup.py | 2 +- 4 files changed, 16 insertions(+), 27 deletions(-) diff --git a/moesifdjango/logger_helper.py b/moesifdjango/logger_helper.py index 6376b44..b86fd9e 100644 --- a/moesifdjango/logger_helper.py +++ b/moesifdjango/logger_helper.py @@ -289,3 +289,12 @@ def mask_event(cls, event_model, middleware_settings, debug): if debug: print("Can not execute mask_event_model function. Please check moesif settings.") return event_model + + # Function to get configuration uri + @classmethod + def get_configuration_uri(cls, settings, field, deprecated_field): + uri = settings.get(field) + if uri: + return uri + else: + return settings.get(deprecated_field, 'https://api.moesif.net') diff --git a/moesifdjango/middleware.py b/moesifdjango/middleware.py index c734594..d4f9bf3 100644 --- a/moesifdjango/middleware.py +++ b/moesifdjango/middleware.py @@ -49,10 +49,9 @@ def __init__(self, get_response): self.DEBUG = self.middleware_settings.get('LOCAL_DEBUG', False) self.LOG_BODY = self.middleware_settings.get('LOG_BODY', True) self.client = MoesifAPIClient(self.middleware_settings.get('APPLICATION_ID')) - # below comment for setting moesif base_uri to a test server. - if self.middleware_settings.get('LOCAL_DEBUG', False): - Configuration.BASE_URI = self.get_configuration_uri(self.middleware_settings, 'BASE_URI', 'LOCAL_MOESIF_BASEURL') - Configuration.version = 'moesifdjango-python/2.2.0' + self.logger_helper = LoggerHelper() + Configuration.BASE_URI = self.logger_helper.get_configuration_uri(self.middleware_settings, 'BASE_URI', 'LOCAL_MOESIF_BASEURL') + Configuration.version = 'moesifdjango-python/2.3.6' if settings.MOESIF_MIDDLEWARE.get('CAPTURE_OUTGOING_REQUESTS', False): try: if self.DEBUG: @@ -67,7 +66,6 @@ def __init__(self, get_response): self.api_client.http_call_back = self.response_catcher self.app_config = AppConfig() self.client_ip = ClientIp() - self.logger_helper = LoggerHelper() self.event_mapper = EventMapper() self.job_scheduler = JobScheduler() self.mask_helper = MaskData() @@ -100,14 +98,6 @@ def __init__(self, get_response): print('Error while parsing application configuration on initialization') print(str(e)) - # Function to get configuration uri - def get_configuration_uri(self, settings, field, deprecated_field): - uri = settings.get(field) - if uri: - return uri - else: - return settings.get(deprecated_field, 'https://api.moesif.net') - # Function to listen to the send event job response def event_listener(self, event): if event.exception: diff --git a/moesifdjango/middleware_pre19.py b/moesifdjango/middleware_pre19.py index bf7dd46..19a6f76 100644 --- a/moesifdjango/middleware_pre19.py +++ b/moesifdjango/middleware_pre19.py @@ -43,10 +43,9 @@ def __init__(self): self.DEBUG = self.middleware_settings.get('LOCAL_DEBUG', False) self.LOG_BODY = self.middleware_settings.get('LOG_BODY', True) self.client = MoesifAPIClient(self.middleware_settings.get('APPLICATION_ID')) - # below comment for setting moesif base_uri to a test server. - if self.middleware_settings.get('LOCAL_DEBUG', False): - Configuration.BASE_URI = self.get_configuration_uri(self.middleware_settings, 'BASE_URI', 'LOCAL_MOESIF_BASEURL') - Configuration.version = 'moesifdjango-python/2.2.0' + self.logger_helper = LoggerHelper() + Configuration.BASE_URI = self.logger_helper.get_configuration_uri(self.middleware_settings, 'BASE_URI', 'LOCAL_MOESIF_BASEURL') + Configuration.version = 'moesifdjango-python/2.3.6' if settings.MOESIF_MIDDLEWARE.get('CAPTURE_OUTGOING_REQUESTS', False): try: if self.DEBUG: @@ -62,7 +61,6 @@ def __init__(self): self.app_config = AppConfig() self.parse_body = ParseBody() self.client_ip = ClientIp() - self.logger_helper = LoggerHelper() self.event_mapper = EventMapper() self.job_scheduler = JobScheduler() self.mask_helper = MaskData() @@ -86,14 +84,6 @@ def __init__(self): print('Error while parsing application configuration on initialization') self.transaction_id = None - # Function to get configuration uri - def get_configuration_uri(self, settings, field, deprecated_field): - uri = settings.get(field) - if uri: - return uri - else: - return settings.get(deprecated_field, 'https://api.moesif.net') - # Function to listen to the send event job response def event_listener(self, event): if event.exception: diff --git a/setup.py b/setup.py index 99a3683..cfad6c9 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='2.3.5', + version='2.3.6', description='Moesif Middleware for Python Django', long_description=long_description,