webhooks: Derive payload from request itself.

This commit is contained in:
Alex Vandiver 2020-09-03 15:29:56 -07:00 committed by Tim Abbott
parent a1f5f6502c
commit 4917391133
2 changed files with 8 additions and 8 deletions

View File

@ -266,14 +266,17 @@ def access_user_by_api_key(request: HttpRequest, api_key: str, email: Optional[s
def log_exception_to_webhook_logger( def log_exception_to_webhook_logger(
request: HttpRequest, request: HttpRequest,
summary: str, summary: str,
payload: str,
unsupported_event: bool, unsupported_event: bool,
) -> None: ) -> None:
if request.content_type == 'application/json': if request.content_type == 'application/json':
try: payload = request.body
payload = orjson.dumps(orjson.loads(payload), option=orjson.OPT_INDENT_2).decode() else:
except orjson.JSONDecodeError: payload = request.POST.get('payload')
pass
try:
payload = orjson.dumps(orjson.loads(payload), option=orjson.OPT_INDENT_2).decode()
except orjson.JSONDecodeError:
pass
custom_header_template = "{header}: {value}\n" custom_header_template = "{header}: {value}\n"
@ -352,7 +355,6 @@ def webhook_view(
log_exception_to_webhook_logger( log_exception_to_webhook_logger(
request=request, request=request,
summary=str(err), summary=str(err),
payload=request.body,
unsupported_event=isinstance(err, UnsupportedWebhookEventType), unsupported_event=isinstance(err, UnsupportedWebhookEventType),
) )
raise err raise err
@ -604,7 +606,6 @@ def authenticated_rest_api_view(
log_exception_to_webhook_logger( log_exception_to_webhook_logger(
request=request, request=request,
summary=str(err), summary=str(err),
payload=request_body,
unsupported_event=isinstance(err, UnsupportedWebhookEventType), unsupported_event=isinstance(err, UnsupportedWebhookEventType),
) )

View File

@ -46,7 +46,6 @@ class Helper:
log_exception_to_webhook_logger( log_exception_to_webhook_logger(
request=request, request=request,
summary=summary, summary=summary,
payload=request.body,
unsupported_event=True, unsupported_event=True,
) )