diff --git a/moesifdjango/client_ip.py b/moesifdjango/client_ip.py index 8f68cf9..70e8578 100644 --- a/moesifdjango/client_ip.py +++ b/moesifdjango/client_ip.py @@ -1,5 +1,6 @@ import re import logging +import ipaddress logger = logging.getLogger(__name__) @@ -10,10 +11,12 @@ def __init__(self): @classmethod def is_ip(cls, value): - if not value is None: - ipv4 = r"^(?:(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])\.){3}(?:\d|[1-9]\d|1\d{2}|2[0-4]\d|25[0-5])$" - 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) + # https://docs.python.org/3/library/ipaddress.html#ipaddress.ip_address + try: + ip = ipaddress.ip_address(value) + return True + except ValueError: + return False def get_client_ip_from_x_forwarded_for(self, value): try: diff --git a/moesifdjango/middleware.py b/moesifdjango/middleware.py index 3da47fb..0059e02 100644 --- a/moesifdjango/middleware.py +++ b/moesifdjango/middleware.py @@ -52,7 +52,7 @@ def __init__(self, get_response): self.client = MoesifAPIClient(self.middleware_settings.get('APPLICATION_ID')) 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.10' + Configuration.version = 'moesifdjango-python/2.3.11' if settings.MOESIF_MIDDLEWARE.get('CAPTURE_OUTGOING_REQUESTS', False): try: if self.DEBUG: @@ -347,6 +347,6 @@ def update_companies_batch(self, companies_profiles): def update_subscription(self, subscription): self.subscription.update_subscription(subscription, self.api_client, self.DEBUG) - + def update_subscriptions_batch(self, subscriptions): self.subscription.update_subscriptions_batch(subscriptions, self.api_client, self.DEBUG) diff --git a/moesifdjango/middleware_pre19.py b/moesifdjango/middleware_pre19.py index 83c7ff8..2aa5ae5 100644 --- a/moesifdjango/middleware_pre19.py +++ b/moesifdjango/middleware_pre19.py @@ -46,7 +46,7 @@ def __init__(self): self.client = MoesifAPIClient(self.middleware_settings.get('APPLICATION_ID')) 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.10' + Configuration.version = 'moesifdjango-python/2.3.11' if settings.MOESIF_MIDDLEWARE.get('CAPTURE_OUTGOING_REQUESTS', False): try: if self.DEBUG: @@ -298,6 +298,6 @@ def update_companies_batch(self, companies_profiles): def update_subscription(self, subscription): self.subscription.update_subscription(subscription, self.api_client, self.DEBUG) - + def update_subscriptions_batch(self, subscriptions): self.subscription.update_subscriptions_batch(subscriptions, self.api_client, self.DEBUG) diff --git a/requirements.txt b/requirements.txt index 013b528..03bd083 100644 --- a/requirements.txt +++ b/requirements.txt @@ -7,3 +7,4 @@ moesifapi>=1.5.3 celery>=3.1.25 moesifpythonrequest>=0.3.4 apscheduler==3.10.4 + diff --git a/setup.py b/setup.py index 96b5a84..bd969e2 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.10', + version='2.3.11', description='Moesif Middleware for Python Django', long_description=long_description, @@ -83,7 +83,8 @@ # requirements files see: # https://packaging.python.org/en/latest/requirements.html install_requires=['requests', 'jsonpickle', 'python-dateutil', 'isodatetimehandler', 'moesifapi>=1.5.3', - 'moesifpythonrequest>=0.3.4', 'apscheduler', 'nose'], + 'moesifpythonrequest>=0.3.4', 'apscheduler', 'nose' + ], # List additional groups of dependencies here (e.g. development # dependencies). You can install these using the following syntax,