Last active
August 21, 2019 18:41
-
-
Save rcarmo/18716fbb23ed5d953d25272b9c7ad985 to your computer and use it in GitHub Desktop.
Bottle GitHub WebHook Handler
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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