PKõEBH”š$Ý!django_github_webhook/__init__.py__version__ = "0.1.1" PKsJAHnÂKãu u django_github_webhook/views.py# -*- coding: utf-8 -*- import hashlib import hmac import json from django.utils.decorators import method_decorator from django.views.decorators.csrf import csrf_exempt from django.core.exceptions import ImproperlyConfigured from django.http import HttpResponseBadRequest, JsonResponse from django.views.generic import View class WebHookView(View): secret = None allowed_events = [ 'commit_comment', 'create', 'delete', 'deployment', 'deployment_status', 'fork', 'gollum', 'issue_comment', 'issues', 'member', 'membership', 'page_build', 'ping', 'public', 'pull_request', 'pull_request_review_comment', 'push', 'release', 'repository', 'status', 'team_add', 'watch', ] def get_secret(self): return self.secret def get_allowed_events(self): return self.allowed_events @method_decorator(csrf_exempt) def dispatch(self, request, *args, **kwargs): return super(WebHookView, self).dispatch(request, *args, **kwargs) def post(self, request, *args, **kwargs): secret = self.get_secret() if not secret: raise ImproperlyConfigured('GitHub webhook secret ist not defined.') if 'HTTP_X_HUB_SIGNATURE' not in request.META: return HttpResponseBadRequest('Request does not contain X-GITHUB-SIGNATURE header') if 'HTTP_X_GITHUB_EVENT' not in request.META: return HttpResponseBadRequest('Request does not contain X-GITHUB-EVENT header') digest_name, signature = request.META['HTTP_X_HUB_SIGNATURE'].split('=') if digest_name != 'sha1': return HttpResponseBadRequest('Unsupported X-HUB-SIGNATURE digest mode found: {}'.format(digest_name)) mac = hmac.new( secret.encode('utf-8'), msg=request.body, digestmod=hashlib.sha1 ) if not hmac.compare_digest(mac.hexdigest(), signature): return HttpResponseBadRequest('Invalid X-HUB-SIGNATURE header found') event = request.META['HTTP_X_GITHUB_EVENT'] if event not in self.get_allowed_events(): return HttpResponseBadRequest('Unsupported X-GITHUB-EVENT header found: {}'.format(event)) handler = getattr(self, event, None) if not handler: return HttpResponseBadRequest('Unsupported X-GITHUB-EVENT header found: {}'.format(event)) payload = json.loads(request.body.decode('utf-8')) response = handler(payload, request, *args, **kwargs) return JsonResponse(response) PKFBHŒ|¡ª  5django_github_webhook-0.1.1.dist-info/DESCRIPTION.rst======== Overview ======== A class based view for Django that can act as an receiver for GitHub webhooks. It is designed to validate all requests through their ``X-Hub-Signature`` headers. Handling of GitHub events is done by implementing a class method with the same name as the event, e.g. ``ping``, ``push`` or ``fork``. See the documentation for more in-depth information and examples. * Free software: BSD license Installation ============ :: pip install django-github-webhook Documentation ============= https://django-github-webhook.readthedocs.org/ Development =========== To run the all tests run:: tox Note, to combine the coverage data from all the tox environments run: .. list-table:: :widths: 10 90 :stub-columns: 1 - - Windows - :: set PYTEST_ADDOPTS=--cov-append tox - - Other - :: PYTEST_ADDOPTS=--cov-append tox Changelog ========= 0.1.0 (2016-01-29) ----------------------------------------- * First release on PyPI. PKFBH`îŒaýý3django_github_webhook-0.1.1.dist-info/metadata.json{"classifiers": ["Development Status :: 5 - Production/Stable", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Programming Language :: Python", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.4", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: Implementation :: CPython", "Programming Language :: Python :: Implementation :: PyPy", "Topic :: Utilities"], "extensions": {"python.details": {"contacts": [{"email": "michael@openservices.at", "name": "Michael Fladischer", "role": "author"}], "document_names": {"description": "DESCRIPTION.rst"}, "project_urls": {"Home": "https://github.com/fladi/django-github-webhook"}}}, "extras": [], "generator": "bdist_wheel (0.26.0)", "keywords": ["django", "view", "github", "webhook", "signature"], "license": "BSD", "metadata_version": "2.0", "name": "django-github-webhook", "run_requires": [{"requires": ["Django"]}], "summary": "Django view for GitHub webhook recievers", "version": "0.1.1"}PKFBH…v¹Ù3django_github_webhook-0.1.1.dist-info/top_level.txtdjango_github_webhook PKFBHìndªnn+django_github_webhook-0.1.1.dist-info/WHEELWheel-Version: 1.0 Generator: bdist_wheel (0.26.0) Root-Is-Purelib: true Tag: py2-none-any Tag: py3-none-any PKFBHÓ3Žc^^.django_github_webhook-0.1.1.dist-info/METADATAMetadata-Version: 2.0 Name: django-github-webhook Version: 0.1.1 Summary: Django view for GitHub webhook recievers Home-page: https://github.com/fladi/django-github-webhook Author: Michael Fladischer Author-email: michael@openservices.at License: BSD Keywords: django,view,github,webhook,signature Platform: UNKNOWN Classifier: Development Status :: 5 - Production/Stable Classifier: Intended Audience :: Developers Classifier: License :: OSI Approved :: BSD License Classifier: Programming Language :: Python Classifier: Programming Language :: Python :: 3 Classifier: Programming Language :: Python :: 3.4 Classifier: Programming Language :: Python :: 3.5 Classifier: Programming Language :: Python :: Implementation :: CPython Classifier: Programming Language :: Python :: Implementation :: PyPy Classifier: Topic :: Utilities Requires-Dist: Django ======== Overview ======== A class based view for Django that can act as an receiver for GitHub webhooks. It is designed to validate all requests through their ``X-Hub-Signature`` headers. Handling of GitHub events is done by implementing a class method with the same name as the event, e.g. ``ping``, ``push`` or ``fork``. See the documentation for more in-depth information and examples. * Free software: BSD license Installation ============ :: pip install django-github-webhook Documentation ============= https://django-github-webhook.readthedocs.org/ Development =========== To run the all tests run:: tox Note, to combine the coverage data from all the tox environments run: .. list-table:: :widths: 10 90 :stub-columns: 1 - - Windows - :: set PYTEST_ADDOPTS=--cov-append tox - - Other - :: PYTEST_ADDOPTS=--cov-append tox Changelog ========= 0.1.0 (2016-01-29) ----------------------------------------- * First release on PyPI. PKFBH‹¶ô¶ôô,django_github_webhook-0.1.1.dist-info/RECORDdjango_github_webhook/__init__.py,sha256=rnObPjuBcEStqSO0S6gsdS_ot8ITOQjVj_-P1LUUYpg,22 django_github_webhook/views.py,sha256=7a_oBVPgsz-_HXfsBv1dmKqHcv7CSIZtLP9TLZBC-jI,2677 django_github_webhook-0.1.1.dist-info/DESCRIPTION.rst,sha256=SFhlweWGxAefFdFWUIyHHLXxNSQID0xBrBzMskDrunA,1033 django_github_webhook-0.1.1.dist-info/METADATA,sha256=uZZuC9tl8mCsK39EZ3yh7mbqkilnG3wY1fBDWVIvAMM,1886 django_github_webhook-0.1.1.dist-info/RECORD,, django_github_webhook-0.1.1.dist-info/WHEEL,sha256=GrqQvamwgBV4nLoJe0vhYRSWzWsx7xjlt74FT0SWYfE,110 django_github_webhook-0.1.1.dist-info/metadata.json,sha256=F1Ys8QwBLHDk1Gr5btQwNNcUvU_ccFTZr7DLCqrmufY,1021 django_github_webhook-0.1.1.dist-info/top_level.txt,sha256=wpCvLvwSEg8ALuF5ZSgosYmbSowG26GSHRdTIdbFcCs,22 PKõEBH”š$Ý!django_github_webhook/__init__.pyPKsJAHnÂKãu u Udjango_github_webhook/views.pyPKFBHŒ|¡ª  5 django_github_webhook-0.1.1.dist-info/DESCRIPTION.rstPKFBH`îŒaýý3bdjango_github_webhook-0.1.1.dist-info/metadata.jsonPKFBH…v¹Ù3°django_github_webhook-0.1.1.dist-info/top_level.txtPKFBHìndªnn+django_github_webhook-0.1.1.dist-info/WHEELPKFBHÓ3Žc^^.Îdjango_github_webhook-0.1.1.dist-info/METADATAPKFBH‹¶ô¶ôô,xdjango_github_webhook-0.1.1.dist-info/RECORDPK϶