mirror of
https://github.com/Xevion/linkpulse.git
synced 2025-12-11 00:07:45 -06:00
Fix unspecified IPv6 addresses from being malformed by hide_ip, fix double private get_database_url breaking
This commit is contained in:
@@ -30,6 +30,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
- Mildly reformatted `README.md`
|
- Mildly reformatted `README.md`
|
||||||
- A development mode check for the `app.state.ip_pool`'s initialization (caused application failure in production only)
|
- A development mode check for the `app.state.ip_pool`'s initialization (caused application failure in production only)
|
||||||
- Applied `get_db` utility function in all applicable areas.
|
- Applied `get_db` utility function in all applicable areas.
|
||||||
|
- Unspecified IPv6 addresses are returned without hiding in `utilities.hide_ip`
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
|
|
||||||
|
|||||||
@@ -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.
|
# 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")
|
url = getenv("DATABASE_URL")
|
||||||
if url is None or url.strip() == "":
|
if url is None or url.strip() == "":
|
||||||
raise ValueError("DATABASE_URL is not set")
|
raise ValueError("DATABASE_URL is not set")
|
||||||
@@ -23,7 +23,7 @@ def __get_database_url():
|
|||||||
class BaseModel(Model):
|
class BaseModel(Model):
|
||||||
class Meta:
|
class Meta:
|
||||||
# accessed via `BaseModel._meta.database`
|
# accessed via `BaseModel._meta.database`
|
||||||
database = connect(url=__get_database_url())
|
database = connect(url=_get_database_url())
|
||||||
|
|
||||||
|
|
||||||
class IPAddress(BaseModel):
|
class IPAddress(BaseModel):
|
||||||
|
|||||||
@@ -88,6 +88,10 @@ def hide_ip(ip: str, hidden_octets: Optional[int] = None) -> str:
|
|||||||
if ipv6 == ("." in ip):
|
if ipv6 == ("." in ip):
|
||||||
raise ValueError("Invalid IP address format. Must be either IPv4 or IPv6.")
|
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
|
total_octets = 8 if ipv6 else 4
|
||||||
separator = ":" if ipv6 else "."
|
separator = ":" if ipv6 else "."
|
||||||
replacement = "XXXX" if ipv6 else "X"
|
replacement = "XXXX" if ipv6 else "X"
|
||||||
|
|||||||
Reference in New Issue
Block a user