Skip to content

Instantly share code, notes, and snippets.

@rcarmo
Last active August 21, 2019 18:41
Show Gist options
  • Save rcarmo/18716fbb23ed5d953d25272b9c7ad985 to your computer and use it in GitHub Desktop.
Save rcarmo/18716fbb23ed5d953d25272b9c7ad985 to your computer and use it in GitHub Desktop.
Bottle GitHub WebHook Handler
@post("/handler")
def gitdeploy():
signature = request.headers.get("X-Hub-Signature", None)
if not signature:
abort(400, "Invalid Request")
event = request.headers.get("X-GitHub-Event", None)
if event == "push":
hashed = "sha1=" + hmac.new(GITHUB_WEBHOOK_SECRET, request.body.read(), hashlib.sha1).hexdigest()
if signature == hashed:
# Do Stuff
else:
abort(403, "Unauthorized Request Body")
abort(400, "Unhandled Request")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment