diff --git a/awx/api/generics.py b/awx/api/generics.py index be58b057d8..952fadf450 100644 --- a/awx/api/generics.py +++ b/awx/api/generics.py @@ -164,6 +164,9 @@ class APIView(views.APIView): if custom_header.startswith('HTTP_'): request.environ.pop(custom_header, None) + # WTF, FIXME + request.body + drf_request = super(APIView, self).initialize_request(request, *args, **kwargs) request.drf_request = drf_request try: diff --git a/awx/api/views/webhooks.py b/awx/api/views/webhooks.py index 31b9755575..6e2e2cc5bd 100644 --- a/awx/api/views/webhooks.py +++ b/awx/api/views/webhooks.py @@ -87,7 +87,9 @@ class WebhookReceiverBase(APIView): if not obj.webhook_key: raise PermissionDenied - mac = hmac.new(force_bytes(obj.webhook_key), msg=force_bytes(self.request.read()), digestmod=sha1) + mac = hmac.new(force_bytes(obj.webhook_key), msg=force_bytes(self.request.body), digestmod=sha1) + logger.debug("header signature: %s", self.get_signature()) + logger.debug("calculated signature: %s", force_bytes(mac.hexdigest())) if not hmac.compare_digest(force_bytes(mac.hexdigest()), self.get_signature()): raise PermissionDenied @@ -112,16 +114,17 @@ class WebhookReceiverBase(APIView): logger.debug("Webhook previously received, returning without action.") return Response(status=status.HTTP_202_ACCEPTED) - data = { - 'tower_webhook_event_type': event_type, - 'tower_webhook_event_guid': event_guid, - 'tower_webhook_payload': request.data, - } new_job = obj.create_unified_job( - webhook_service=obj.webhook_service, - webhook_credential=obj.webhook_credential, - webhook_guid=event_guid, - extra_vars=json.dumps(data) + _eager_fields={ + 'webhook_service': obj.webhook_service, + 'webhook_credential': obj.webhook_credential, + 'webhook_guid': event_guid, + }, + extra_vars=json.dumps({ + 'tower_webhook_event_type': event_type, + 'tower_webhook_event_guid': event_guid, + 'tower_webhook_payload': request.data, + }) ) new_job.signal_start() @@ -156,7 +159,7 @@ class GitlabWebhookReceiver(WebhookReceiverBase): def get_event_guid(self): # Gitlab does not provide a unique identifier on events, so construct one. h = sha1() - h.update(force_bytes(self.request.read())) + h.update(force_bytes(self.request.body)) return h.hexdigest() def get_signature(self):