From 14a4bde3e7659b7ab5aef7df86d9bf981abbc588 Mon Sep 17 00:00:00 2001 From: Ignacio Nacho Fernandez Date: Mon, 25 Jan 2021 12:16:54 +0100 Subject: [PATCH 1/5] Adding prints --- flask_githubapp/core.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/flask_githubapp/core.py b/flask_githubapp/core.py index 34af98f..9f0d545 100644 --- a/flask_githubapp/core.py +++ b/flask_githubapp/core.py @@ -100,6 +100,7 @@ def client(self): def payload(self): """GitHub hook payload""" if request and request.json and 'installation' in request.json: + print(f"Received github hook payload! {request.json}") return request.json raise RuntimeError('Payload is only available in the context of a GitHub hook request') @@ -167,6 +168,10 @@ def _flask_view_func(self): functions_to_call = [] calls = {} + print("Request received in _flask_view_func") + print(f"Request headers: {request.headers}") + print(f"Request json: {request.json}") + event = request.headers['X-GitHub-Event'] action = request.json.get('action') From ceeda813d54890cfc25ed5b911668a599388444d Mon Sep 17 00:00:00 2001 From: Ignacio Nacho Fernandez Date: Mon, 25 Jan 2021 14:33:33 +0100 Subject: [PATCH 2/5] Removing prints - totally obliterated verify webhook --- flask_githubapp/core.py | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/flask_githubapp/core.py b/flask_githubapp/core.py index 9f0d545..fd662d9 100644 --- a/flask_githubapp/core.py +++ b/flask_githubapp/core.py @@ -5,7 +5,6 @@ from flask import abort, current_app, jsonify, request, _app_ctx_stack from github3 import GitHub, GitHubEnterprise - LOG = logging.getLogger(__name__) STATUS_FUNC_CALLED = 'HIT' @@ -22,6 +21,7 @@ class GitHubApp(object): Keyword Arguments: app {Flask object} -- App instance - created with Flask(__name__) (default: {None}) """ + def __init__(self, app=None): self._hook_mappings = {} if app is not None: @@ -58,10 +58,10 @@ def init_app(self, app): Path used for GitHub hook requests as a string. Default: '/' """ - required_settings = ['GITHUBAPP_ID', 'GITHUBAPP_KEY', 'GITHUBAPP_SECRET'] + required_settings = ['GITHUBAPP_ID', 'GITHUBAPP_SECRET'] for setting in required_settings: - if not setting in app.config: - raise RuntimeError("Flask-GitHubApp requires the '%s' config var to be set" % setting) + if setting not in app.config: + raise RuntimeError(f"Flask-GitHubApp requires the '{setting}' config var to be set") app.add_url_rule(app.config.get('GITHUBAPP_ROUTE', '/'), view_func=self._flask_view_func, @@ -100,7 +100,6 @@ def client(self): def payload(self): """GitHub hook payload""" if request and request.json and 'installation' in request.json: - print(f"Received github hook payload! {request.json}") return request.json raise RuntimeError('Payload is only available in the context of a GitHub hook request') @@ -152,6 +151,7 @@ def cruel_closer(): event_action {str} -- Name of the event and optional action (separated by a period), e.g. 'issues.opened' or 'pull_request' """ + def decorator(f): if event_action not in self._hook_mappings: self._hook_mappings[event_action] = [f] @@ -168,10 +168,6 @@ def _flask_view_func(self): functions_to_call = [] calls = {} - print("Request received in _flask_view_func") - print(f"Request headers: {request.headers}") - print(f"Request json: {request.json}") - event = request.headers['X-GitHub-Event'] action = request.json.get('action') @@ -196,7 +192,7 @@ def _flask_view_func(self): 'calls': calls}) def _verify_webhook(self): - signature_header ='X-Hub-Signature-256' + signature_header = 'X-Hub-Signature-256' signature_header_legacy = 'X-Hub-Signature' if request.headers.get(signature_header): From d30f76b15b1073f2a28e69b48dae5f6d56d1dc20 Mon Sep 17 00:00:00 2001 From: Ignacio Nacho Fernandez Date: Fri, 29 Jan 2021 06:47:07 +0100 Subject: [PATCH 3/5] Removing 'installation' check --- flask_githubapp/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/flask_githubapp/core.py b/flask_githubapp/core.py index fd662d9..726f070 100644 --- a/flask_githubapp/core.py +++ b/flask_githubapp/core.py @@ -99,7 +99,7 @@ def client(self): @property def payload(self): """GitHub hook payload""" - if request and request.json and 'installation' in request.json: + if request and request.json: return request.json raise RuntimeError('Payload is only available in the context of a GitHub hook request') From a1a68ca39dce53993e1c968eb7c57d333f1f5b81 Mon Sep 17 00:00:00 2001 From: Ignacio Nacho Fernandez Date: Tue, 2 Feb 2021 09:04:59 +0100 Subject: [PATCH 4/5] Adding a wholle lota log again --- flask_githubapp/core.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/flask_githubapp/core.py b/flask_githubapp/core.py index 726f070..6918797 100644 --- a/flask_githubapp/core.py +++ b/flask_githubapp/core.py @@ -165,6 +165,15 @@ def decorator(f): return decorator def _flask_view_func(self): + print("* --------------- *") + print("* --------------- *") + print(f"{request.headers}") + print("* --------------- *") + #print("* --------------- *") + #print(f"{request.json}") + #print("* --------------- *") + print("* --------------- *") + functions_to_call = [] calls = {} From 6c6ef38927b4effcd7dcec74988db48cf83ab2aa Mon Sep 17 00:00:00 2001 From: Ignacio Nacho Fernandez Date: Tue, 2 Feb 2021 13:28:37 +0100 Subject: [PATCH 5/5] Removing signature check --- flask_githubapp/core.py | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/flask_githubapp/core.py b/flask_githubapp/core.py index 6918797..e344957 100644 --- a/flask_githubapp/core.py +++ b/flask_githubapp/core.py @@ -165,24 +165,12 @@ def decorator(f): return decorator def _flask_view_func(self): - print("* --------------- *") - print("* --------------- *") - print(f"{request.headers}") - print("* --------------- *") - #print("* --------------- *") - #print(f"{request.json}") - #print("* --------------- *") - print("* --------------- *") - functions_to_call = [] calls = {} event = request.headers['X-GitHub-Event'] action = request.json.get('action') - if current_app.config['GITHUBAPP_SECRET'] is not False: - self._verify_webhook() - if event in self._hook_mappings: functions_to_call += self._hook_mappings[event]