Skip to content

Commit

Permalink
Update dependency django-ipware to v7 (#935)
Browse files Browse the repository at this point in the history
* Update dependency django-ipware to v7

* fixing is_private method

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: shankar ambady <[email protected]>
  • Loading branch information
renovate[bot] and shanbady authored May 21, 2024
1 parent 9f07465 commit 6bbdf4a
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 8 deletions.
6 changes: 4 additions & 2 deletions authentication/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.core.exceptions import ValidationError
from django.db import models
from django.utils.safestring import mark_safe
from ipware.utils import is_private_ip
from python_ipware import IpWare

from main.models import TimestampedModel

Expand Down Expand Up @@ -40,11 +40,13 @@ class BlockedIPRange(TimestampedModel):
ip_end = models.GenericIPAddressField(null=False, blank=False)

def clean(self):
ipw = IpWare()
for ip in (self.ip_start, self.ip_end):
if ip is None:
msg = "IP cannot be null"
raise ValidationError(msg, code="invalid")
if is_private_ip(ip):
ipw_ip = ipw.parse_ip_address(ip)
if ipw_ip.is_private:
msg = f"IP {ip} is not routable"
raise ValidationError(msg, code="invalid")
if ip_address(self.ip_start) > ip_address(self.ip_end):
Expand Down
27 changes: 22 additions & 5 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ django-filter = "^2.4.0"
django-guardian = "^2.4.0"
django-hijack = "^3.4.1"
django-imagekit = "^5.0.0"
django-ipware = "^3.0.7"
django-ipware = "^7.0.0"
django-json-widget = "^1.0.0"
django-redis = "^5.2.0"
django-server-status = "^0.7.0"
Expand Down

0 comments on commit 6bbdf4a

Please sign in to comment.