From 5718696cea84d8072a5b9e43e3ac4e0646ee2ae4 Mon Sep 17 00:00:00 2001
From: Stefan Hynek <stefan.hynek@uni-goettingen.de>
Date: Mon, 9 Jan 2023 10:33:11 +0100
Subject: [PATCH] refactor(main): configure certain wsgidav settings from
 AppConfig

this includes, host, port, and the newly introduced tg_host key
---
 src/main.py | 24 +++++++++++-------------
 1 file changed, 11 insertions(+), 13 deletions(-)

diff --git a/src/main.py b/src/main.py
index 1bd0276..3bf7cd8 100644
--- a/src/main.py
+++ b/src/main.py
@@ -4,8 +4,6 @@
 
 """Configure and start the WSGI DAV Server."""
 import logging
-import os
-
 import sentry_sdk
 from cheroot import wsgi
 from wsgidav.wsgidav_app import WsgiDAVApp
@@ -14,13 +12,11 @@ from repdav.config import AppConfig
 app_config = AppConfig()
 
 if app_config.dsn:
-    sentry_sdk.init(
-        app_config.dsn,
-        traces_sample_rate=1.0
-    )
+    sentry_sdk.init(app_config.dsn, traces_sample_rate=1.0)
 
-logging.basicConfig(level=logging.DEBUG,
-                    format='%(name)s %(levelname)s %(asctime)s %(message)s')
+logging.basicConfig(
+    level=logging.DEBUG, format="%(name)s %(levelname)s %(asctime)s %(message)s"
+)
 _logger = logging.getLogger(__name__)
 _logger.propagate = True
 
@@ -31,12 +27,13 @@ tmp_logger.setLevel(logging.DEBUG)
 
 # Configuration of the WsgiDAVApp.
 # https://wsgidav.readthedocs.io/en/latest/user_guide_configure.html
-# TODO: move to config.py
 config = {
-    "host": os.getenv("host") or "localhost",
-    "port": int(os.getenv("port") or "8080"),
+    "host": app_config.host,
+    "port": app_config.port,
     "provider_mapping": {
-        "/": {"class": "repdav.textgrid_named_dav_provider.TextgridNamedResourceProvider"},
+        "/": {
+            "class": "repdav.textgrid_named_dav_provider.TextgridNamedResourceProvider"
+        },
     },
     "verbose": 4,
     "http_authenticator": {
@@ -47,7 +44,8 @@ config = {
         "default_to_digest": False,
         # Name of a header field that will be accepted as authorized user
         "trusted_auth_header": None,
-    }
+    },
+    "tg_host": app_config.tg_host,
 }
 
 app = WsgiDAVApp(config)
-- 
GitLab