mirror of
https://github.com/Kozea/Radicale.git
synced 2025-06-26 16:45:52 +00:00
hook: gracefully ignore non functional hooks and fall back to none
In case a hook fails to load for some reason, fall back to the default hook "none" and treat errors as warnings in the log. This will gracefully ignore typos in hook names without crashing the server, and it will also allow configuration of "rabbitmq" where i.e. "pika" is missing. Closes: #1490 Signed-off-by: Henning Schild <henning@hennsch.de>
This commit is contained in:
parent
45f0b8809b
commit
773f09fe74
1 changed files with 11 additions and 2 deletions
|
@ -3,14 +3,23 @@ from enum import Enum
|
||||||
from typing import Sequence
|
from typing import Sequence
|
||||||
|
|
||||||
from radicale import pathutils, utils
|
from radicale import pathutils, utils
|
||||||
|
from radicale.log import logger
|
||||||
|
|
||||||
INTERNAL_TYPES: Sequence[str] = ("none", "rabbitmq")
|
INTERNAL_TYPES: Sequence[str] = ("none", "rabbitmq")
|
||||||
|
|
||||||
|
|
||||||
def load(configuration):
|
def load(configuration):
|
||||||
"""Load the storage module chosen in configuration."""
|
"""Load the storage module chosen in configuration."""
|
||||||
return utils.load_plugin(
|
try:
|
||||||
INTERNAL_TYPES, "hook", "Hook", BaseHook, configuration)
|
return utils.load_plugin(
|
||||||
|
INTERNAL_TYPES, "hook", "Hook", BaseHook, configuration)
|
||||||
|
except Exception as e:
|
||||||
|
logger.warn(e)
|
||||||
|
logger.warn("Hook \"%s\" failed to load, falling back to \"none\"." % configuration.get("hook", "type"))
|
||||||
|
configuration = configuration.copy()
|
||||||
|
configuration.update({"hook": {"type": "none"}}, "hook", privileged=True)
|
||||||
|
return utils.load_plugin(
|
||||||
|
INTERNAL_TYPES, "hook", "Hook", BaseHook, configuration)
|
||||||
|
|
||||||
|
|
||||||
class BaseHook:
|
class BaseHook:
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue