Prepare configuration for externalisation

This commit is contained in:
Benjamin Bohard 2020-04-02 14:16:18 +02:00
parent 8eadc93c95
commit 1e88a5eab0
1 changed files with 16 additions and 4 deletions

View File

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