Skip to content

Instantly share code, notes, and snippets.

View Edint386's full-sized avatar
:octocat:
放假

xsNight Edint386

:octocat:
放假
View GitHub Profile
@athoune
athoune / github_webhook.py
Last active October 15, 2022 13:51
aiohttp webhook for github
async def github_webhook(secret :str, request :web.Request) -> dict:
assert request.content_length < 1000000, "Request content too fat" # 1M
digest, signature = request.headers['X-HUB-SIGNATURE'].split("=", 1)
assert digest == "sha1", "Digest must be sha1" # use a whitelist
body = await request.content.read()
h = hmac.HMAC(bytes(secret, "UTF8"), msg=body, digestmod=digest)
assert h.hexdigest() == signature, "Bad signature"
return json.loads(body.decode('UTF8'))