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 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', []), | ||||
'storage': ('dict', { | 'storage': ('dict', { | ||||
'cls': 'remote', | 'cls': 'remote', | ||||
'args': { | 'args': { | ||||
'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': { | ||||
'url': 'http://127.0.0.1:5007/', | 'url': 'http://127.0.0.1:5007/', | ||||
'timeout': 1, | 'timeout': 1, | ||||
} | } | ||||
}), | }), | ||||
'search': ('dict', { | |||||
'cls': 'remote', | |||||
'args': { | |||||
'url': 'http://127.0.0.1:5010/', | |||||
'timeout': 10, | |||||
}, | |||||
}), | |||||
'log_dir': ('string', '/tmp/swh/log'), | 'log_dir': ('string', '/tmp/swh/log'), | ||||
'debug': ('bool', False), | 'debug': ('bool', False), | ||||
'serve_assets': ('bool', False), | 'serve_assets': ('bool', False), | ||||
'host': ('string', '127.0.0.1'), | 'host': ('string', '127.0.0.1'), | ||||
'port': ('int', 5004), | 'port': ('int', 5004), | ||||
'secret_key': ('string', 'development key'), | 'secret_key': ('string', 'development key'), | ||||
# do not display code highlighting for content > 1MB | # do not display code highlighting for content > 1MB | ||||
'content_display_max_size': ('int', 5 * 1024 * 1024), | 'content_display_max_size': ('int', 5 * 1024 * 1024), | ||||
▲ Show 20 Lines • Show All 75 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') | ||||
swhweb_config['search'] = get_search(**swhweb_config['search']) | |||||
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 |