From 3f7ab6705fecb956050013cfa685da2d6fef8634 Mon Sep 17 00:00:00 2001 From: Kyle Jones Date: Mon, 14 Jan 2019 11:45:56 -0600 Subject: [PATCH] Strip out the web server --- Pipfile | 2 -- Procfile | 1 - pyproject.toml | 2 -- sms_printer/__init__.py | 2 -- sms_printer/application.py | 54 -------------------------------------- 5 files changed, 61 deletions(-) delete mode 100644 Procfile delete mode 100644 sms_printer/application.py diff --git a/Pipfile b/Pipfile index 7101660..59bf79b 100644 --- a/Pipfile +++ b/Pipfile @@ -4,8 +4,6 @@ url = "https://pypi.python.org/simple" name = "pypi" [packages] -gunicorn = "*" -flask = "*" pyxdg = "*" [dev-packages] diff --git a/Procfile b/Procfile deleted file mode 100644 index b309cb3..0000000 --- a/Procfile +++ /dev/null @@ -1 +0,0 @@ -web: gunicorn sms_printer diff --git a/pyproject.toml b/pyproject.toml index 9dffdae..86df700 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -8,8 +8,6 @@ author = "Kyle Jones" author-email = "kyle@kf5jwc.us" requires-python = ">=3.7" requires = [ - "gunicorn", - "flask", "pyxdg", "setuptools", # for pkg_resources ] diff --git a/sms_printer/__init__.py b/sms_printer/__init__.py index 50c2f59..f53ee6a 100644 --- a/sms_printer/__init__.py +++ b/sms_printer/__init__.py @@ -4,5 +4,3 @@ This prints SMS messages (on a real printer) using CUPS. This is a web server which accepts JSON-formatted SMS messages at /sms-printer from brokers (such as bandwidth.com) for printing. """ - -from .application import APP as application diff --git a/sms_printer/application.py b/sms_printer/application.py deleted file mode 100644 index e216467..0000000 --- a/sms_printer/application.py +++ /dev/null @@ -1,54 +0,0 @@ -import logging - -from flask import Flask, Response, json, request - -from sms_broker_parsers import get_mimetype_parser -from sms_broker_parsers.errors import NoMatchingSchema, NoParserForMimeType -from .utils import allowed_sender, log_request, print_message - -APP = Flask(__name__) -logging.basicConfig(level=logging.DEBUG) - - -@APP.route("/", methods=["GET"]) -def main() -> Response: - return Response(status=204) - - -@APP.route("/sms-printer", methods=["POST"]) -def sms_printer() -> Response: - # If this throws, flask takes care of it - sms_input = request.get_json(force=True) - - try: - parser = get_mimetype_parser(request.mimetype) - - except NoParserForMimeType: - logging.warning("No parsers available for the given mimetype!") - logging.debug("mimetype: {}".format(request.mimetype)) - logging.debug("header: {}".format(request.headers["Content-Type"])) - return Response(status=415) - - try: - sms_list = parser(sms_input) - log_request(sms_input) - - except NoMatchingSchema: - logging.warning("Unrecognized message format!") - logging.debug(json.dumps(sms_input)) - return Response(status=415) - - for sms in sms_list: - - logging.info("Recieved sms from %s", sms.sender) - if not allowed_sender(sms.sender): - logging.warning("Unauthorized sender %s", sms.sender) - return Response(status=401) - - logging.info("Printing sms from %s", sms.sender) - logging.debug("Text: %s", sms.text) - if not print_message(sms.text): - logging.error("Error printing sms") - return Response(status=500) - - return Response(status=200) -- 2.26.2