Replace webhook manager datetime.utcnow calls (#1499)
Co-authored-by: ghreprimand <203024559+ghreprimand@users.noreply.github.com>
This commit is contained in:
@@ -7,7 +7,7 @@ import ipaddress
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
from datetime import datetime
|
||||
from datetime import datetime, timezone
|
||||
from typing import Optional
|
||||
from urllib.parse import urlparse
|
||||
|
||||
@@ -37,6 +37,11 @@ _PRIVATE_NETWORKS = [
|
||||
]
|
||||
|
||||
|
||||
def _utcnow() -> datetime:
|
||||
"""Return naive UTC for existing DB columns while avoiding datetime.utcnow()."""
|
||||
return datetime.now(timezone.utc).replace(tzinfo=None)
|
||||
|
||||
|
||||
def _ip_is_private(addr: ipaddress._BaseAddress) -> bool:
|
||||
# If the address is IPv4-mapped IPv6, extract and evaluate the embedded IPv4
|
||||
if isinstance(addr, ipaddress.IPv6Address) and addr.ipv4_mapped is not None:
|
||||
@@ -203,7 +208,7 @@ class WebhookManager:
|
||||
logger.warning(f"Webhook {webhook_id} has invalid URL, skipping: {e}")
|
||||
return
|
||||
|
||||
body = json.dumps({"event": event, "timestamp": datetime.utcnow().isoformat(), "data": payload})
|
||||
body = json.dumps({"event": event, "timestamp": _utcnow().isoformat(), "data": payload})
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"X-Odysseus-Event": event,
|
||||
@@ -217,7 +222,7 @@ class WebhookManager:
|
||||
try:
|
||||
resp = await self._client.post(url, content=body, headers=headers)
|
||||
db.query(Webhook).filter(Webhook.id == webhook_id).update({
|
||||
"last_triggered_at": datetime.utcnow(),
|
||||
"last_triggered_at": _utcnow(),
|
||||
"last_status_code": resp.status_code,
|
||||
"last_error": None,
|
||||
})
|
||||
@@ -226,7 +231,7 @@ class WebhookManager:
|
||||
logger.warning(f"Webhook delivery failed for {webhook_id}")
|
||||
try:
|
||||
db.query(Webhook).filter(Webhook.id == webhook_id).update({
|
||||
"last_triggered_at": datetime.utcnow(),
|
||||
"last_triggered_at": _utcnow(),
|
||||
"last_status_code": None,
|
||||
"last_error": sanitize_error(str(e)),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user