app: add waitress

This commit is contained in:
xeals 2022-09-03 14:48:45 +10:00
parent 686c9efc2c
commit 9f1b765e06
Signed by: xeals
GPG Key ID: A498C7AF27EC6B5C
4 changed files with 28 additions and 6 deletions

View File

@ -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
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)

View File

@ -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)

18
poetry.lock generated
View File

@ -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"},

View File

@ -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"