Changeset View
Changeset View
Standalone View
Standalone View
swh/objstorage/api/server.py
Show First 20 Lines • Show All 169 Lines • ▼ Show 20 Lines | def make_app(config): | ||||
""" | """ | ||||
client_max_size = config.get("client_max_size", 1024 * 1024 * 1024) | client_max_size = config.get("client_max_size", 1024 * 1024 * 1024) | ||||
app = RPCServerApp(client_max_size=client_max_size) | app = RPCServerApp(client_max_size=client_max_size) | ||||
app.client_exception_classes = (ObjNotFoundError, Error) | app.client_exception_classes = (ObjNotFoundError, Error) | ||||
# retro compatibility configuration settings | # retro compatibility configuration settings | ||||
app["config"] = config | app["config"] = config | ||||
_cfg = config["objstorage"] | app["objstorage"] = get_objstorage(**config["objstorage"]) | ||||
app["objstorage"] = get_objstorage(_cfg["cls"], _cfg["args"]) | |||||
app.router.add_route("GET", "/", index) | app.router.add_route("GET", "/", index) | ||||
app.router.add_route("POST", "/check_config", check_config) | app.router.add_route("POST", "/check_config", check_config) | ||||
app.router.add_route("POST", "/content/contains", contains) | app.router.add_route("POST", "/content/contains", contains) | ||||
app.router.add_route("POST", "/content/add", add_bytes) | app.router.add_route("POST", "/content/add", add_bytes) | ||||
app.router.add_route("POST", "/content/add/batch", add_batch) | app.router.add_route("POST", "/content/add/batch", add_batch) | ||||
app.router.add_route("POST", "/content/get", get_bytes) | app.router.add_route("POST", "/content/get", get_bytes) | ||||
app.router.add_route("POST", "/content/get/batch", get_batch) | app.router.add_route("POST", "/content/get/batch", get_batch) | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | Returns: | ||||
configuration as a dict | configuration as a dict | ||||
""" | """ | ||||
if "objstorage" not in cfg: | if "objstorage" not in cfg: | ||||
raise KeyError("Invalid configuration; missing objstorage config entry") | raise KeyError("Invalid configuration; missing objstorage config entry") | ||||
missing_keys = [] | missing_keys = [] | ||||
vcfg = cfg["objstorage"] | vcfg = cfg["objstorage"] | ||||
for key in ("cls", "args"): | if "cls" not in vcfg: | ||||
v = vcfg.get(key) | raise KeyError("Invalid configuration; missing cls config entry") | ||||
if v is None: | |||||
missing_keys.append(key) | |||||
if missing_keys: | cls = vcfg["cls"] | ||||
raise KeyError( | |||||
"Invalid configuration; missing %s config entry" | |||||
% (", ".join(missing_keys),) | |||||
) | |||||
cls = vcfg.get("cls") | |||||
if cls == "pathslicing": | if cls == "pathslicing": | ||||
args = vcfg["args"] | # Backwards-compatibility: either get the deprecated `args` from the | ||||
# objstorage config, or use the full config itself to check for keys | |||||
args = vcfg.get("args", vcfg) | |||||
for key in ("root", "slicing"): | for key in ("root", "slicing"): | ||||
v = args.get(key) | v = args.get(key) | ||||
if v is None: | if v is None: | ||||
missing_keys.append(key) | missing_keys.append(key) | ||||
if missing_keys: | if missing_keys: | ||||
raise KeyError( | raise KeyError( | ||||
"Invalid configuration; missing args.%s config entry" | "Invalid configuration; missing %s config entry" | ||||
% (", ".join(missing_keys),) | % (", ".join(missing_keys),) | ||||
) | ) | ||||
return cfg | return cfg | ||||
def make_app_from_configfile(): | def make_app_from_configfile(): | ||||
"""Load configuration and then build application to run | """Load configuration and then build application to run | ||||
Show All 9 Lines |