From 1e88a5eab0841ccd1f5db22739072fd431caf7e9 Mon Sep 17 00:00:00 2001 From: Benjamin Bohard Date: Thu, 2 Apr 2020 14:16:18 +0200 Subject: [PATCH] Prepare configuration for externalisation --- src/risotto/config.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/risotto/config.py b/src/risotto/config.py index f04515d..a8bfa42 100644 --- a/src/risotto/config.py +++ b/src/risotto/config.py @@ -5,17 +5,29 @@ CONFIGURATION_DIR = 'configurations' PROVIDER_FACTORY_CONFIG_DIR = environ.get('PROVIDER_FACTORY_CONFIG_DIR', 'factory') TMP_DIR = 'tmp' DEFAULT_USER = environ.get('DEFAULT_USER', 'Anonymous') -DEFAULT_DSN = environ.get('DEFAULT_DSN', 'postgres:///risotto?host=/var/run/postgresql/&user=risotto') -DEFAULT_TIRAMISU_DSN = environ.get('DEFAULT_TIRAMISU_DSN', 'postgres:///tiramisu?host=/var/run/postgresql/&user=tiramisu') +#DEFAULT_DSN = environ.get('DEFAULT_DSN', 'postgres:///risotto?host=/var/run/postgresql/&user=risotto') +#DEFAULT_TIRAMISU_DSN = environ.get('DEFAULT_TIRAMISU_DSN', 'postgres:///tiramisu?host=/var/run/postgresql/&user=tiramisu') +RISOTTO_DB_NAME = environ.get('RISOTTO_DB_NAME', 'risotto') +RISOTTO_DB_PASSWORD = environ.get('RISOTTO_DB_PASSWORD', 'risotto') +RISOTTO_DB_USER = environ.get('RISOTTO_DB_USER', 'risotto') +TIRAMISU_DB_NAME = environ.get('TIRAMISU_DB_NAME', 'tiramisu') +TIRAMISU_DB_PASSWORD = environ.get('TIRAMISU_DB_PASSWORD', 'tiramisu') +TIRAMISU_DB_USER = environ.get('TIRAMISU_DB_USER', 'tiramisu') +DB_ADDRESS = environ.get('DB_ADDRESS', 'localhost') MESSAGE_PATH = environ.get('MESSAGE_PATH', '/root/risotto-message/messages') SQL_DIR = environ.get('SQL_DIR', './sql') CACHE_ROOT_PATH = environ.get('CACHE_ROOT_PATH', '/var/cache/risotto') SRV_SEED_PATH = environ.get('SRV_SEED_PATH', '/srv/seed') +def dsn_factory(database, user, password, address=db_address): + mangled_address = '/var/run/postgresql' if address == 'localhost' else address + return f'postgres:///{database}?host={mangled_address}/&user={user}&password={password}' + + def get_config(): - return {'database': {'dsn': DEFAULT_DSN, - 'tiramisu_dsn': DEFAULT_TIRAMISU_DSN, + return {'database': {'dsn': dsn_factory(RISOTTO_DB_NAME, RISOTTO_DB_USER, RISOTTO_DB_PASSWORD), + 'tiramisu_dsn': dsn_factory(TIRAMISU_DB_NAME, TIRAMISU_DB_USER, TIRAMISU_DB_PASSWORD), }, 'http_server': {'port': 8080, 'default_user': DEFAULT_USER},