Skip to content

Commit

Permalink
Refactor: Allow BaseUri to be set without depending on debug mode (#82)
Browse files Browse the repository at this point in the history
Refactor: Allow BaseUri to be set without depending on debug mode
Bump version to 2.3.6
  • Loading branch information
keyur9 committed Nov 29, 2023
1 parent 3e9e1ec commit 3afddc0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
9 changes: 9 additions & 0 deletions moesifdjango/logger_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
16 changes: 3 additions & 13 deletions moesifdjango/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand Down Expand Up @@ -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:
Expand Down
16 changes: 3 additions & 13 deletions moesifdjango/middleware_pre19.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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()
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 3afddc0

Please sign in to comment.