Skip to content

Commit 5934a8c

Browse files
author
Maria Korlotian
authored
Add webhooks validation (#95)
1 parent 6f97c00 commit 5934a8c

19 files changed

Lines changed: 152 additions & 1 deletion

File tree

castle/api/__init__.py

Whitespace-only changes.

castle/client_id/__init__.py

Whitespace-only changes.

castle/commands/__init__.py

Whitespace-only changes.

castle/context/__init__.py

Whitespace-only changes.

castle/core/__init__.py

Whitespace-only changes.

castle/core/process_response.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from castle.errors import BadRequestError, UnauthorizedError, ForbiddenError, NotFoundError, \
22
UserUnauthorizedError, InvalidParametersError, APIError, InternalServerError
3-
3+
from castle.logger import Logger
44

55
RESPONSE_ERRORS = {
66
400: BadRequestError,
@@ -22,6 +22,7 @@ def call(self):
2222

2323
self.verify()
2424

25+
Logger.call("response:", self.response.text)
2526
return self.response.json()
2627

2728
def verify(self):

castle/core/process_webhook.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
from castle.errors import APIError
2+
from castle.logger import Logger
3+
4+
5+
class CoreProcessWebhook(object):
6+
def __init__(self, webhook):
7+
self.webhook = webhook
8+
9+
def call(self):
10+
self.verify()
11+
12+
Logger.call("webhook:", self.webhook.data)
13+
return self.webhook.data
14+
15+
def verify(self):
16+
if self.webhook.data is not None and len(self.webhook.data) != 0:
17+
return
18+
19+
raise APIError("Invalid webhook from Castle API")

castle/errors.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,10 @@ class APIError(CastleError):
1919
pass
2020

2121

22+
class WebhookVerificationError(CastleError):
23+
pass
24+
25+
2226
class InvalidParametersError(APIError):
2327
pass
2428

castle/failover/__init__.py

Whitespace-only changes.

castle/headers/__init__.py

Whitespace-only changes.

0 commit comments

Comments
 (0)