mirror of
https://github.com/Xevion/linkpulse.git
synced 2025-12-06 13:15:35 -06:00
Fix unspecified IPv6 addresses from being malformed by hide_ip, fix double private get_database_url breaking
This commit is contained in:
@@ -13,7 +13,7 @@ logger = structlog.get_logger()
|
||||
|
||||
|
||||
# I can't pollute the class definition with these lines, so I'll move them to a separate function.
|
||||
def __get_database_url():
|
||||
def _get_database_url():
|
||||
url = getenv("DATABASE_URL")
|
||||
if url is None or url.strip() == "":
|
||||
raise ValueError("DATABASE_URL is not set")
|
||||
@@ -23,7 +23,7 @@ def __get_database_url():
|
||||
class BaseModel(Model):
|
||||
class Meta:
|
||||
# accessed via `BaseModel._meta.database`
|
||||
database = connect(url=__get_database_url())
|
||||
database = connect(url=_get_database_url())
|
||||
|
||||
|
||||
class IPAddress(BaseModel):
|
||||
|
||||
@@ -88,6 +88,10 @@ def hide_ip(ip: str, hidden_octets: Optional[int] = None) -> str:
|
||||
if ipv6 == ("." in ip):
|
||||
raise ValueError("Invalid IP address format. Must be either IPv4 or IPv6.")
|
||||
|
||||
# Secondary check, if the IP address is an IPv6 address with unspecified address (::), return it as is.
|
||||
if ipv6 and ip.startswith("::"):
|
||||
return ip
|
||||
|
||||
total_octets = 8 if ipv6 else 4
|
||||
separator = ":" if ipv6 else "."
|
||||
replacement = "XXXX" if ipv6 else "X"
|
||||
|
||||
Reference in New Issue
Block a user