Skip to content
Snippets Groups Projects
Commit 9f33ba62 authored by Simon Künzel's avatar Simon Künzel
Browse files

Update config loading

parent 4741a39c
No related branches found
No related tags found
No related merge requests found
#
# Common py vars
#
# With the api version and WITHOUT a trailing /
# In production with httpS !
API_BASE_URL = "http://localhost:5000/api/v0"
# WITHOUT a trailing /
PERMANENT_MEDIA_DIR = "permanent_media"
#
# API specific vars
#
# Defaults for development, do not use in production! # Defaults for development, do not use in production!
DEBUG = True DEBUG = True
# Name of this instance # Name of this instance
API_SERVER_NAME = "dev" API_SERVER_NAME = "dev"
# With the api version and WITHOUT a trailing /
# In production with httpS !
API_BASE_URL = "http://localhost:5000/api/v0"
# Prefix which is prepended to paths (which are saved in the database) before they are provided by the api # Prefix which is prepended to paths (which are saved in the database) before they are provided by the api
# Must include the last / # Must include the last /
FILE_PATH_PREFIX = "https://video.fsmpi.rwth-aachen.de/files/" FILE_PATH_PREFIX = "https://video.fsmpi.rwth-aachen.de/files/"
......
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
# We have these here because 'api.config' and 'api.live_config' is nicer than 'app.config' and 'api.live_config.config' # We have these here because 'api.config' and 'api.live_config' is nicer than 'app.config' and 'api.live_config.config'
from app import app, config from app import app
from videoag_common import config
from api.live_config import config as live_config from api.live_config import config as live_config
...@@ -41,12 +41,3 @@ class ApiDatabase(Database): ...@@ -41,12 +41,3 @@ class ApiDatabase(Database):
database = ApiDatabase(api.config["DATABASE"]) database = ApiDatabase(api.config["DATABASE"])
if api.config["DATABASE"].get("log_all_statements", False):
def _init_logger():
import logging
logger = logging.getLogger('sqlalchemy.engine')
handler = logging.StreamHandler(sys.stdout)
logger.addHandler(handler)
logger.setLevel(logging.INFO)
_init_logger()
...@@ -5,7 +5,7 @@ if __name__ == "__main__": ...@@ -5,7 +5,7 @@ if __name__ == "__main__":
import os import os
from flask import Flask, Config, Response from flask import Flask, Response
class ApiFlask(Flask): class ApiFlask(Flask):
...@@ -18,25 +18,14 @@ class ApiFlask(Flask): ...@@ -18,25 +18,14 @@ class ApiFlask(Flask):
app = ApiFlask("api") app = ApiFlask("api")
config = app.config
from videoag_common.miscellaneous.util import load_config_file, merge_config_with
config.from_pyfile(os.path.join(os.getcwd(), os.environ["VIDEOAG_API_CONFIG"])) import videoag_common
if "VIDEOAG_API_TEST_CONFIG_OVERRIDE" in os.environ: merge_config_with(app.config, videoag_common.config, overwrite_non_mergeable=True) # TODO override required?
override_config = Config(config.root_path)
override_config.from_pyfile(os.path.join(os.getcwd(), os.environ["VIDEOAG_API_TEST_CONFIG_OVERRIDE"]))
# Merge the config files manually to also merge dicts (instead of one overwriting the other)
for key, value in override_config.items():
if key not in config:
config[key] = value
continue
if isinstance(value, dict) and isinstance(config[key], dict):
config[key] |= value
else:
config[key] = value
# A key is required for flask (This key is used to sign the cookies) # A key is required for flask (This key is used to sign the cookies)
if "SECRET_KEY" not in config: if "SECRET_KEY" not in app.config:
config["SECRET_KEY"] = os.urandom(24) # pragma: no cover app.config["SECRET_KEY"] = os.urandom(24) # pragma: no cover
# Import routes AFTER initialization # Import routes AFTER initialization
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
......
backend_common_py @ 1ffe9749
Subproject commit 4d05105a1f4664259fe5619d10a71c5712591d39 Subproject commit 1ffe9749b0cbd3965f85cbd80b201a707bb09965
...@@ -115,7 +115,7 @@ def load_config_file(path: Path): ...@@ -115,7 +115,7 @@ def load_config_file(path: Path):
def merge_config_with(config: dict, to_merge: dict, overwrite_non_mergeable: bool = False): def merge_config_with(config: dict, to_merge: dict, overwrite_non_mergeable: bool = False):
for key, item in to_merge: for key, item in to_merge.items():
if key not in config: if key not in config:
config[key] = item config[key] = item
elif isinstance(item, dict) and isinstance(config[key], dict): elif isinstance(item, dict) and isinstance(config[key], dict):
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment