This commit is contained in:
Matthias 2021-09-12 16:32:40 +02:00
parent f600083dee
commit 5bf9561984
No known key found for this signature in database
GPG Key ID: F50EF5741D33E076

View File

@ -54,15 +54,17 @@ class WebhookView(CsrfExemptMixin, APIView):
self.init(request, *args, **kwargs) self.init(request, *args, **kwargs)
# get webhook definition # get webhook definition
self.get_webhook(endpoint, *args, **kwargs) self.get_webhook(endpoint, *args, **kwargs)
# check headers # check headers
headers = request.headers headers = request.headers
self.validate_token(headers)
# process data
try: try:
payload = json.loads(request.body) payload = json.loads(request.body)
except json.decoder.JSONDecodeError as error: except json.decoder.JSONDecodeError as error:
raise NotAcceptable(error.msg) raise NotAcceptable(error.msg)
# validate
self.validate_token(payload, headers)
# process data
self.save_data(payload, headers, request) self.save_data(payload, headers, request)
self.process_payload(payload, headers, request) self.process_payload(payload, headers, request)
@ -87,24 +89,24 @@ class WebhookView(CsrfExemptMixin, APIView):
if self.webhook.token: if self.webhook.token:
self.token = self.webhook.token self.token = self.webhook.token
self.verify = VerificationMethod.TOKEN self.verify = VerificationMethod.TOKEN
# TODO make a object-setting
return True return True
def validate_token(self, headers): def validate_token(self, payload, headers):
token = headers.get(self.TOKEN_NAME, "") token = headers.get(self.TOKEN_NAME, "")
# no token # no token
if self.verify == VerificationMethod.NONE: if self.verify == VerificationMethod.NONE:
return True pass
# static token # static token
elif self.verify == VerificationMethod.TOKEN: elif self.verify == VerificationMethod.TOKEN:
if not compare_digest(token, self.token): if not compare_digest(token, self.token):
raise PermissionDenied(self.MESSAGE_TOKEN_ERROR) raise PermissionDenied(self.MESSAGE_TOKEN_ERROR)
return True
# hmac token # hmac token
elif self.verify == VerificationMethod.HMAC: elif self.verify == VerificationMethod.HMAC:
# TODO write check
return True return True
def save_data(self, payload, headers=None, request=None): def save_data(self, payload, headers=None, request=None):