Compare commits

...

3 Commits

Author SHA1 Message Date
6e2e5e73da fix: handle empty string
Some checks failed
ci / docker (push) Failing after 6s
2024-11-03 14:11:12 +01:00
2305bc9789 fix: include yaml for server & docker build 2024-11-03 14:11:12 +01:00
cdb4a8aeb9 feat: implement substitution map 2024-11-03 14:11:12 +01:00
4 changed files with 26 additions and 3 deletions

2
.gitignore vendored
View File

@@ -5,3 +5,5 @@ instance/
__pycache__/
signal_targets.txt
sqlite.db
substitutions.yaml
test.env

View File

@@ -14,7 +14,7 @@ RUN python3 -m pip install --no-cache-dir --break-system-packages -r req.txt
# precreate database directory for mount (will otherwise be created at before_first_request)
COPY ./ .
RUN mkdir /app/instance/
RUN mkdir -p /app/instance/
EXPOSE 5000/tcp

View File

@@ -7,6 +7,7 @@ import subprocess
import os
import datetime
import secrets
import yaml
import ldaptools
import messagetools
@@ -27,6 +28,16 @@ db = SQLAlchemy(app)
BAD_DISPATCH_ACCESS_TOKEN = "Invalid or missing dispatch-access-token parameter in URL"
def _apply_substitution(string):
if not string:
return string
for replace, match in app.config["SUBSTITUTIONS"].items():
string = string.replace(match, replace)
return string
class WebHookPaths(db.Model):
__tablename__ = "webhook_paths"
@@ -85,8 +96,8 @@ class DispatchObject(db.Model):
"timestamp" : self.timestamp,
"phone" : self.phone,
"email" : self.email,
"title" : self.title,
"message" : self.message,
"title" : _apply_substitution(self.title),
"message" : _apply_substitution(self.message),
"uuid" : self.dispatch_secret,
"method" : self.method,
"error" : self.dispatch_error,
@@ -414,6 +425,15 @@ def create_app():
app.config["SETTINGS_ACCESS_TOKEN"] = os.environ["SETTINGS_ACCESS_TOKEN"]
app.config["DISPATCH_ACCESS_TOKEN"] = os.environ["DISPATCH_ACCESS_TOKEN"]
substitution_config_file = os.environ.get("SUBSTITUTION_MAP") or "substitutions.yaml"
app.config["SUBSTITUTIONS"] = {}
if os.path.isfile(substitution_config_file):
with open(substitution_config_file) as f:
app.config["SUBSTITUTIONS"] = yaml.safe_load(f)
print("Loaded subs:", substitution_config_file, app.config["SUBSTITUTIONS"], file=sys.stderr)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description='Simple Telegram Notification Interface',

View File

@@ -1,4 +1,5 @@
python-ldap
pyyaml
flask
flask-sqlalchemy
sqlalchemy