Changeset View
Changeset View
Standalone View
Standalone View
swh/web/config.py
# Copyright (C) 2017-2019 The Software Heritage developers | # Copyright (C) 2017-2019 The Software Heritage developers | ||||
# See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
# License: GNU Affero General Public License version 3, or any later version | # License: GNU Affero General Public License version 3, or any later version | ||||
# See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
import os | import os | ||||
from typing import Any, Dict | from typing import Any, Dict | ||||
from swh.core import config | from swh.core import config | ||||
from swh.indexer.storage import get_indexer_storage | from swh.indexer.storage import get_indexer_storage | ||||
from swh.scheduler import get_scheduler | from swh.scheduler import get_scheduler | ||||
from swh.search import get_search | |||||
from swh.storage import get_storage | from swh.storage import get_storage | ||||
from swh.vault import get_vault | from swh.vault import get_vault | ||||
from swh.web import settings | from swh.web import settings | ||||
SETTINGS_DIR = os.path.dirname(settings.__file__) | SETTINGS_DIR = os.path.dirname(settings.__file__) | ||||
DEFAULT_CONFIG = { | DEFAULT_CONFIG = { | ||||
'allowed_hosts': ('list', []), | 'allowed_hosts': ('list', []), | ||||
'search': ('dict', { | |||||
'cls': 'remote', | |||||
'args': { | |||||
'url': 'http://127.0.0.1:5010/', | |||||
'timeout': 10, | |||||
}, | |||||
}), | |||||
'storage': ('dict', { | 'storage': ('dict', { | ||||
'cls': 'remote', | 'cls': 'remote', | ||||
'url': 'http://127.0.0.1:5002/', | 'url': 'http://127.0.0.1:5002/', | ||||
'timeout': 10, | 'timeout': 10, | ||||
}), | }), | ||||
'indexer_storage': ('dict', { | 'indexer_storage': ('dict', { | ||||
'cls': 'remote', | 'cls': 'remote', | ||||
'args': { | 'args': { | ||||
▲ Show 20 Lines • Show All 94 Lines • ▼ Show 20 Lines | def get_config(config_file='web/web'): | ||||
if not swhweb_config: | if not swhweb_config: | ||||
config_filename = os.environ.get('SWH_CONFIG_FILENAME') | config_filename = os.environ.get('SWH_CONFIG_FILENAME') | ||||
if config_filename: | if config_filename: | ||||
config_file = config_filename | config_file = config_filename | ||||
cfg = config.load_named_config(config_file, DEFAULT_CONFIG) | cfg = config.load_named_config(config_file, DEFAULT_CONFIG) | ||||
swhweb_config.update(cfg) | swhweb_config.update(cfg) | ||||
config.prepare_folders(swhweb_config, 'log_dir') | config.prepare_folders(swhweb_config, 'log_dir') | ||||
if swhweb_config.get('search'): | |||||
swhweb_config['search'] = get_search(**swhweb_config['search']) | |||||
else: | |||||
swhweb_config['search'] = None | |||||
swhweb_config['storage'] = get_storage(**swhweb_config['storage']) | swhweb_config['storage'] = get_storage(**swhweb_config['storage']) | ||||
swhweb_config['vault'] = get_vault(**swhweb_config['vault']) | swhweb_config['vault'] = get_vault(**swhweb_config['vault']) | ||||
swhweb_config['indexer_storage'] = \ | swhweb_config['indexer_storage'] = \ | ||||
get_indexer_storage(**swhweb_config['indexer_storage']) | get_indexer_storage(**swhweb_config['indexer_storage']) | ||||
swhweb_config['scheduler'] = get_scheduler( | swhweb_config['scheduler'] = get_scheduler( | ||||
**swhweb_config['scheduler']) | **swhweb_config['scheduler']) | ||||
return swhweb_config | return swhweb_config | ||||
def search(): | |||||
"""Return the current application's search. | |||||
""" | |||||
return get_config()['search'] | |||||
def storage(): | def storage(): | ||||
"""Return the current application's storage. | """Return the current application's storage. | ||||
""" | """ | ||||
return get_config()['storage'] | return get_config()['storage'] | ||||
def vault(): | def vault(): | ||||
Show All 18 Lines |