Skip to content

Commit

Permalink
fix: use the timestamp of the notification attempt to be used on the …
Browse files Browse the repository at this point in the history
…sign call instead of the event timestamp
  • Loading branch information
jfcalvo committed Sep 23, 2024
1 parent 107d571 commit d14253b
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions argilla-server/src/argilla_server/webhooks/v1/commons.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,15 @@
# NOTE: We are using standard webhooks implementation.
# For more information take a look to https://www.standardwebhooks.com
def notify_event(webhook: WebhookModel, event: str, timestamp: datetime, data: Dict) -> httpx.Response:
timestamp_attempt = datetime.utcnow()

msg_id = _generate_msg_id()
payload = json.dumps(_build_payload(event, timestamp, data))
signature = Webhook(webhook.secret).sign(msg_id, timestamp, payload)
signature = Webhook(webhook.secret).sign(msg_id, timestamp_attempt, payload)

return httpx.post(
webhook.url,
headers=_build_headers(msg_id, signature),
headers=_build_headers(msg_id, timestamp_attempt, signature),
content=payload,
timeout=NOTIFY_EVENT_DEFAULT_TIMEOUT,
)
Expand All @@ -47,10 +49,10 @@ def _generate_msg_id() -> str:
return f"msg_{secrets.token_urlsafe(MSG_ID_BYTES_LENGTH)}"


def _build_headers(msg_id: str, signature: str) -> Dict:
def _build_headers(msg_id: str, timestamp: datetime, signature: str) -> Dict:
return {
"webhook-id": msg_id,
"webhook-timestamp": str(floor(datetime.utcnow().replace(tzinfo=timezone.utc).timestamp())),
"webhook-timestamp": str(floor(timestamp.replace(tzinfo=timezone.utc).timestamp())),
"webhook-signature": signature,
"content-type": "application/json",
}
Expand Down

0 comments on commit d14253b

Please sign in to comment.