Skip to content

Commit d816702

Browse files
andrii-balitskyiseambotrazor-x
authored
fix: SeamWebhook: normalize headers before passing to svix + add docstrings (#113)
* Normalize headers to lowercase keys before passing to svix * docs: Add docstrings to SeamWebhook class * ci: Format code * Update seam/seam_webhook.py Co-authored-by: Evan Sosenko <evan@getseam.com> * Update SeamWebhook dosctring and import * Export WebhookVerificationError * Update SeamWebhook docstrings * Update seam/seam_webhook.py Co-authored-by: Evan Sosenko <evan@getseam.com> * Update seam/seam_webhook.py Co-authored-by: Evan Sosenko <evan@getseam.com> * Update seam/seam_webhook.py Co-authored-by: Evan Sosenko <evan@getseam.com> * Alias WebhookVerificationError to SeamWebhookVerificationError * Fix typo --------- Co-authored-by: Seam Bot <devops@getseam.com> Co-authored-by: Evan Sosenko <evan@getseam.com>
1 parent 2ed6e11 commit d816702

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

seam/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@
1414
SeamActionAttemptTimeoutError,
1515
)
1616
from .seam_webhook import SeamWebhook
17+
from svix.webhooks import WebhookVerificationError as SeamWebhookVerificationError

seam/seam_webhook.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,33 @@
11
from typing import Dict
2-
from svix import Webhook
2+
from svix.webhooks import Webhook
33
from .routes.models import SeamEvent
44

55

66
class SeamWebhook:
7+
"""Verifies and parses incoming Seam webhook events using the Svix library."""
8+
79
def __init__(self, secret: str):
10+
"""
11+
:param secret: The secret key used for webhook verification.
12+
:type secret: str
13+
"""
814
self._webhook = Webhook(secret)
915

1016
def verify(self, payload: str, headers: Dict[str, str]) -> SeamEvent:
11-
res = self._webhook.verify(payload, headers)
17+
"""Verify and parse an incoming HTTP webhook request.
18+
19+
Normalizes the headers, verifies the payload using the Svix
20+
Webhook instance, and returns a SeamEvent object.
21+
22+
:param payload: The raw HTTP request body.
23+
:type payload: str
24+
:param headers: The HTTP request headers.
25+
:type headers: Dict[str, str]
26+
:return: The SeamEvent object created from the verified payload.
27+
:rtype: SeamEvent
28+
:raises WebhookVerificationError: If the webhook signature verification fails.
29+
"""
30+
normalized_headers = {k.lower(): v for k, v in headers.items()}
31+
res = self._webhook.verify(payload, normalized_headers)
1232

1333
return SeamEvent.from_dict(res)

0 commit comments

Comments
 (0)