Changeset View
Changeset View
Standalone View
Standalone View
swh/vault/api/server.py
Show First 20 Lines • Show All 193 Lines • ▼ Show 20 Lines | def make_app(backend, **kwargs): | ||||
# Endpoints for batch requests | # Endpoints for batch requests | ||||
app.router.add_route('POST', '/batch_cook', batch_cook) | app.router.add_route('POST', '/batch_cook', batch_cook) | ||||
app.router.add_route('GET', '/batch_progress/{batch_id}', batch_progress) | app.router.add_route('GET', '/batch_progress/{batch_id}', batch_progress) | ||||
app['backend'] = backend | app['backend'] = backend | ||||
return app | return app | ||||
def get_local_backend(config_file): | def get_local_backend(cfg): | ||||
if os.path.isfile(config_file): | |||||
cfg = config.read(config_file, DEFAULT_CONFIG) | |||||
else: | |||||
cfg = config.load_named_config(config_file, DEFAULT_CONFIG) | |||||
if 'vault' not in cfg: | if 'vault' not in cfg: | ||||
raise ValueError("missing '%vault' configuration") | raise ValueError("missing '%vault' configuration") | ||||
vcfg = cfg['vault'] | vcfg = cfg['vault'] | ||||
if vcfg['cls'] != 'local': | if vcfg['cls'] != 'local': | ||||
raise EnvironmentError( | raise EnvironmentError( | ||||
"The vault backend can only be started with a 'local' " | "The vault backend can only be started with a 'local' " | ||||
"configuration", err=True) | "configuration", err=True) | ||||
Show All 10 Lines | for key in ('cache', 'storage', 'scheduler'): | ||||
raise ValueError( | raise ValueError( | ||||
"invalid configuration; missing %s config entry." % key) | "invalid configuration; missing %s config entry." % key) | ||||
return get_vault('local', args) | return get_vault('local', args) | ||||
def make_app_from_configfile(config_file=DEFAULT_CONFIG_PATH, **kwargs): | def make_app_from_configfile(config_file=DEFAULT_CONFIG_PATH, **kwargs): | ||||
config_file = os.environ.get('SWH_CONFIG_FILENAME', config_file) | config_file = os.environ.get('SWH_CONFIG_FILENAME', config_file) | ||||
vault = get_local_backend(config_file) | if os.path.isfile(config_file): | ||||
cfg = config.read(config_file, DEFAULT_CONFIG) | |||||
else: | |||||
cfg = config.load_named_config(config_file, DEFAULT_CONFIG) | |||||
vault = get_local_backend(cfg) | |||||
return make_app(backend=vault, **kwargs) | return make_app(backend=vault, **kwargs) | ||||
if __name__ == '__main__': | if __name__ == '__main__': | ||||
print('Deprecated. Use swh-vault ') | print('Deprecated. Use swh-vault ') |