From 583583ae5f8151664c7bdfd3aba650487e24747b Mon Sep 17 00:00:00 2001 From: eyjhb Date: Wed, 12 Mar 2025 00:04:36 +0100 Subject: [PATCH] notify: added support for quick URLs --- machines/gerd/services/notify/app.py | 32 ++++++++++++++++------------ 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/machines/gerd/services/notify/app.py b/machines/gerd/services/notify/app.py index 2de7532..abd2e5f 100644 --- a/machines/gerd/services/notify/app.py +++ b/machines/gerd/services/notify/app.py @@ -9,14 +9,8 @@ import os import jq import json -# TODO(eyJhb): add the following -# - example of bash alias -# - jq filter parameter documentation -# - jq filter example -# - easy way to run it ONLY with curl -# - e.g. curl notify.fricloud.dk/notify//msg - app = Flask(__name__) +app.url_map.strict_slashes = False import logging @@ -175,11 +169,16 @@ def index():
- - + +
+
+
+ + +

This notification service has support for both matrix and email. @@ -293,18 +292,23 @@ def index(): return tmpl -@app.route("/notify", methods=["GET", "POST"]) -def send_notification(): +@app.route("/notify", methods=["GET", "POST"], defaults={"token": "", "body": ""}) +@app.route("/notify/", methods=["GET", "POST"], defaults={"body": ""}) +@app.route("/notify//", methods=["GET", "POST"]) +def send_notification(token: str, body: str): # default to this ntype = request.args.get("type", "matrix") title = request.args.get("title", "Notification") - body = request.args.get("body", request.get_data().decode("utf-8")) + body = request.args.get("body", request.get_data().decode("utf-8") or body) if not body: body = " " - token = request.authorization.token or request.authorization.password + + if request.authorization: + token = request.authorization.token or request.authorization.password + if not token: return ( - "No token found, please either specify with Authorization: Bearer or HTTPBasic", + "No token found, please either specify with Authorization: Bearer , HTTPBasic or in the URL path", 401, )