Skip to content

Commit

Permalink
#188481396: update checker for ipv6 (#89)
Browse files Browse the repository at this point in the history
* update checker for ipv6

* update the requires and version

* move to install requires

* remove semicolon

* cleanup

---------

Co-authored-by: Praveen Kumar <praveen@moesif.com>
  • Loading branch information
xinghengwang and praves77 authored Oct 31, 2024
1 parent 6dbd557 commit d42ecf3
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 10 deletions.
11 changes: 7 additions & 4 deletions moesifdjango/client_ip.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import re
import logging
import ipaddress

logger = logging.getLogger(__name__)

Expand All @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions moesifdjango/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions moesifdjango/middleware_pre19.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ moesifapi>=1.5.3
celery>=3.1.25
moesifpythonrequest>=0.3.4
apscheduler==3.10.4

5 changes: 3 additions & 2 deletions 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.10',
version='2.3.11',

description='Moesif Middleware for Python Django',
long_description=long_description,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit d42ecf3

Please sign in to comment.