From fbcf071e898c17ba2211a773c43054ba3b186511 Mon Sep 17 00:00:00 2001 From: missytake Date: Fri, 1 Dec 2023 18:32:45 +0100 Subject: [PATCH] doveauth-http: deploying HTTP route for account creation --- chatmaild/pyproject.toml | 2 ++ chatmaild/src/chatmaild/doveauth-http.service | 10 ++++++++++ chatmaild/src/chatmaild/web.py | 9 +++++++++ deploy-chatmail/src/deploy_chatmail/__init__.py | 1 + .../src/deploy_chatmail/nginx/nginx.conf.j2 | 4 ++++ 5 files changed, 26 insertions(+) create mode 100644 chatmaild/src/chatmaild/doveauth-http.service diff --git a/chatmaild/pyproject.toml b/chatmaild/pyproject.toml index 473c406e..d31854ef 100644 --- a/chatmaild/pyproject.toml +++ b/chatmaild/pyproject.toml @@ -8,10 +8,12 @@ version = "0.1" dependencies = [ "aiosmtpd", "flask", + "gunicorn", ] [project.scripts] doveauth = "chatmaild.doveauth:main" +doveauth-http = "chatmaild.web:main" filtermail = "chatmaild.filtermail:main" [tool.pytest.ini_options] diff --git a/chatmaild/src/chatmaild/doveauth-http.service b/chatmaild/src/chatmaild/doveauth-http.service new file mode 100644 index 00000000..bc5879d8 --- /dev/null +++ b/chatmaild/src/chatmaild/doveauth-http.service @@ -0,0 +1,10 @@ +[Unit] +Description=HTTP endpoint for creating chatmail accounts + +[Service] +ExecStart=/usr/local/bin/gunicorn --timeout 60 -b :3691 -w 1 chatmaild.web:main +Restart=always +RestartSec=30 + +[Install] +WantedBy=multi-user.target diff --git a/chatmaild/src/chatmaild/web.py b/chatmaild/src/chatmaild/web.py index e4ae3bd2..822ad9b6 100644 --- a/chatmaild/src/chatmaild/web.py +++ b/chatmaild/src/chatmaild/web.py @@ -1,5 +1,6 @@ from flask import Flask, jsonify, request import time +import os from database import Database from util import gen_password, get_valid_email_addr, encrypt_password @@ -37,3 +38,11 @@ def create_app_from_db(db): ) return app + + +def main(): + """(debugging-only!) serve http account creation Web API on localhost""" + db_path = os.getenv("CHATMAIL_DATABASE", "/home/vmail/passdb.sqlite") + app = create_app_from_db_path(db_path) + if __name__ == "__main__": + app.run(debug=True, host="localhost", port=3691) diff --git a/deploy-chatmail/src/deploy_chatmail/__init__.py b/deploy-chatmail/src/deploy_chatmail/__init__.py index 7b80fb8b..ad60963e 100644 --- a/deploy-chatmail/src/deploy_chatmail/__init__.py +++ b/deploy-chatmail/src/deploy_chatmail/__init__.py @@ -46,6 +46,7 @@ def _install_chatmaild() -> None: for fn in ( "doveauth", + "doveauth-http", "filtermail", ): files.put( diff --git a/deploy-chatmail/src/deploy_chatmail/nginx/nginx.conf.j2 b/deploy-chatmail/src/deploy_chatmail/nginx/nginx.conf.j2 index 7484d339..83abf281 100644 --- a/deploy-chatmail/src/deploy_chatmail/nginx/nginx.conf.j2 +++ b/deploy-chatmail/src/deploy_chatmail/nginx/nginx.conf.j2 @@ -42,6 +42,10 @@ http { # as directory, then fall back to displaying a 404. try_files $uri $uri/ =404; } + + location /new_email { + proxy_pass http://localhost:3691/; + } } }