1
0
mirror of https://github.com/checktheroads/hyperglass synced 2024-05-11 05:55:08 +00:00
Files
checktheroads-hyperglass/hyperglass/external/webhooks.py

39 lines
989 B
Python
Raw Normal View History

2020-04-18 23:18:50 -07:00
"""Convenience functions for webhooks."""
# Standard Library
import typing as t
2020-04-18 23:18:50 -07:00
# Project
from hyperglass.exceptions.private import UnsupportedError
2020-04-18 23:18:50 -07:00
# Local
from ._base import BaseExternal
from .slack import SlackHook
from .generic import GenericHook
from .msteams import MSTeams
if t.TYPE_CHECKING:
# Project
from hyperglass.models.config.logging import Http
2020-04-18 23:18:50 -07:00
PROVIDER_MAP = {
2020-04-21 03:29:42 -07:00
"generic": GenericHook,
2020-06-26 12:23:11 -07:00
"msteams": MSTeams,
"slack": SlackHook,
2020-04-18 23:18:50 -07:00
}
class Webhook(BaseExternal):
"""Get webhook for provider name."""
def __new__(cls: "Webhook", config: "Http") -> "BaseExternal":
2020-04-18 23:18:50 -07:00
"""Return instance for correct provider handler."""
try:
2020-04-21 03:29:42 -07:00
provider_class = PROVIDER_MAP[config.provider]
return provider_class(config)
except KeyError as err:
raise UnsupportedError(
2021-12-06 17:12:30 -07:00
message="{p} is not yet supported as a webhook target.",
p=config.provider.title(),
) from err