forked from Flagsmith/flagsmith
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement GitHub Webhook (Flagsmith#3906)
- Loading branch information
1 parent
4a0de93
commit 9303267
Showing
7 changed files
with
199 additions
and
11 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
import hashlib | ||
import hmac | ||
|
||
|
||
def github_webhook_payload_is_valid( | ||
payload_body: bytes, secret_token: str, signature_header: str | ||
) -> bool: | ||
"""Verify that the payload was sent from GitHub by validating SHA256. | ||
Raise and return 403 if not authorized. | ||
""" | ||
if not signature_header: | ||
return False | ||
hash_object = hmac.new( | ||
secret_token.encode("utf-8"), msg=payload_body, digestmod=hashlib.sha1 | ||
) | ||
expected_signature = "sha1=" + hash_object.hexdigest() | ||
if not hmac.compare_digest(expected_signature, signature_header): | ||
return False | ||
|
||
return True |
This file contains 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
This file contains 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
This file contains 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
This file contains 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