From 9f1b765e06c92efa7187e84555d400db2ef0c847 Mon Sep 17 00:00:00 2001 From: xeals Date: Sat, 3 Sep 2022 14:48:45 +1000 Subject: [PATCH] app: add waitress --- frontpage/app.py | 12 ++++++++---- frontpage/config.py | 3 ++- poetry.lock | 18 +++++++++++++++++- pyproject.toml | 1 + 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/frontpage/app.py b/frontpage/app.py index 285c18c..37e5726 100644 --- a/frontpage/app.py +++ b/frontpage/app.py @@ -2,6 +2,8 @@ import argparse import secrets +import waitress + from flask import Flask from flask_pyoidc import OIDCAuthentication from flask_pyoidc.provider_configuration import ClientMetadata, ProviderConfiguration @@ -18,7 +20,6 @@ def _init_oidc(cfg: OidcConfig) -> OIDCAuthentication: secret = f.read() else: secret = cfg.client_secret - print(secret) client = ClientMetadata(client_id=cfg.client_id, client_secret=secret) # Ensure we have the minimum set of scopes for things to work. @@ -49,8 +50,11 @@ def main(): app.register_blueprint(routes.register(auth, "default")) - app.config.update({"DEBUG": cfg.app.debug, "SECRET_KEY": secrets.token_hex()}) + app.config.update({"DEBUG": cfg.core.debug, "SECRET_KEY": secrets.token_hex()}) app.config["user_config"] = cfg - # Reloader doesn't work on NixOS - app.run(use_reloader=False) + if cfg.core.debug: + # Reloader doesn't work on Nix + app.run(use_reloader=False) + else: + waitress.serve(app, host="127.0.0.1", port=cfg.core.port) diff --git a/frontpage/config.py b/frontpage/config.py index 397c917..2dcca99 100644 --- a/frontpage/config.py +++ b/frontpage/config.py @@ -14,6 +14,7 @@ class CoreConfig: """Core application configuration.""" debug: bool = False + port: int = 5000 @dataclass @@ -42,7 +43,7 @@ class AppConfig: class Config: """Top-level configuration.""" - app: CoreConfig + core: CoreConfig oidc: OidcConfig apps: Dict[str, AppConfig] = field(default_factory=dict) diff --git a/poetry.lock b/poetry.lock index 5bbee57..f8b73fe 100644 --- a/poetry.lock +++ b/poetry.lock @@ -420,6 +420,18 @@ brotli = ["brotlicffi (>=0.8.0)", "brotli (>=1.0.9)", "brotlipy (>=0.6.0)"] secure = ["pyOpenSSL (>=0.14)", "cryptography (>=1.3.4)", "idna (>=2.0.0)", "certifi", "urllib3-secure-extra", "ipaddress"] socks = ["PySocks (>=1.5.6,!=1.5.7,<2.0)"] +[[package]] +name = "waitress" +version = "2.1.2" +description = "Waitress WSGI server" +category = "main" +optional = false +python-versions = ">=3.7.0" + +[package.extras] +docs = ["Sphinx (>=1.8.1)", "docutils", "pylons-sphinx-themes (>=1.0.9)"] +testing = ["pytest", "pytest-cover", "coverage (>=5.0)"] + [[package]] name = "werkzeug" version = "2.2.2" @@ -449,7 +461,7 @@ testing = ["pytest (>=6)", "pytest-checkdocs (>=2.4)", "pytest-flake8", "pytest- [metadata] lock-version = "1.1" python-versions = "^3.9" -content-hash = "9f2fbbfe6e41a73d49bc730c9607c1128a6a8d6acee4b362aedddf294b2c6b42" +content-hash = "dcd1f67c1a5fd78cb252808867be01588c56361e81086915d82d844f204d6197" [metadata.files] beaker = [ @@ -758,6 +770,10 @@ urllib3 = [ {file = "urllib3-1.26.12-py2.py3-none-any.whl", hash = "sha256:b930dd878d5a8afb066a637fbb35144fe7901e3b209d1cd4f524bd0e9deee997"}, {file = "urllib3-1.26.12.tar.gz", hash = "sha256:3fa96cf423e6987997fc326ae8df396db2a8b7c667747d47ddd8ecba91f4a74e"}, ] +waitress = [ + {file = "waitress-2.1.2-py3-none-any.whl", hash = "sha256:7500c9625927c8ec60f54377d590f67b30c8e70ef4b8894214ac6e4cad233d2a"}, + {file = "waitress-2.1.2.tar.gz", hash = "sha256:780a4082c5fbc0fde6a2fcfe5e26e6efc1e8f425730863c04085769781f51eba"}, +] werkzeug = [ {file = "Werkzeug-2.2.2-py3-none-any.whl", hash = "sha256:f979ab81f58d7318e064e99c4506445d60135ac5cd2e177a2de0089bfd4c9bd5"}, {file = "Werkzeug-2.2.2.tar.gz", hash = "sha256:7ea2d48322cc7c0f8b3a215ed73eabd7b5d75d0b50e31ab006286ccff9e00b8f"}, diff --git a/pyproject.toml b/pyproject.toml index 9fe1dd1..f839165 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,6 +14,7 @@ Flask = "^2.2.2" Flask-pyoidc-oda = "^0.6.3" toml = "^0.10.2" dacite = "^1.6.0" +waitress = "^2.1.2" [tool.poetry.dev-dependencies] black = "^22.8.0"