From 5b75a80ee19bfd75cde8a3bc6e29160bd2ccc26b Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 20 May 2022 20:08:12 +0700 Subject: [PATCH] store incoming hooks --- tubearchivist/web/src/webhook_docker.py | 11 ++++++++++- tubearchivist/web/src/webhook_github.py | 7 +++++++ tubearchivist/web/views.py | 2 ++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/tubearchivist/web/src/webhook_docker.py b/tubearchivist/web/src/webhook_docker.py index 7a2b0b0..080101c 100644 --- a/tubearchivist/web/src/webhook_docker.py +++ b/tubearchivist/web/src/webhook_docker.py @@ -1,7 +1,9 @@ """parse and forward docker webhooks""" -import requests +import json +from datetime import datetime +import requests from src.webhook_base import WebhookBase @@ -117,3 +119,10 @@ class DockerHook(WebhookBase): response = self._forward_message(message_data, url) return response + + def save_hook(self): + """save hook to disk for easy debugging""" + now = datetime.now().strftime("%s") + filename = f"/data/hooks/docker_hook-{now}.json" + with open(filename, "w", encoding="utf-8") as f: + f.write(json.dumps(self.hook)) diff --git a/tubearchivist/web/src/webhook_github.py b/tubearchivist/web/src/webhook_github.py index eabfdc9..50f8ba7 100644 --- a/tubearchivist/web/src/webhook_github.py +++ b/tubearchivist/web/src/webhook_github.py @@ -103,6 +103,13 @@ class GithubHook(WebhookBase): task.create_task("build_release") GithubBackup(tag_name).save_tag() + def save_hook(self): + """save hook to disk for easy debugging""" + now = datetime.now().strftime("%s") + filename = f"/data/hooks/github_hook-{now}.json" + with open(filename, "w", encoding="utf-8") as f: + f.write(json.dumps(self.hook)) + class GithubBackup: """backup release and notes""" diff --git a/tubearchivist/web/views.py b/tubearchivist/web/views.py index f617405..8aaf195 100644 --- a/tubearchivist/web/views.py +++ b/tubearchivist/web/views.py @@ -37,6 +37,7 @@ def webhook_docker(): print(request.json) message = handler.process() + handler.save_hook() print(message, "hook sent to discord") return jsonify(message) @@ -53,5 +54,6 @@ def webhook_github(): print(request.json) handler.create_hook_task() + handler.save_hook() message = {"success": True} return jsonify(message)