2020-04-18 23:18:50 -07:00
|
|
|
"""Convenience functions for webhooks."""
|
|
|
|
|
|
|
|
# Project
|
|
|
|
from hyperglass.exceptions import HyperglassError
|
|
|
|
from hyperglass.external._base import BaseExternal
|
|
|
|
from hyperglass.external.slack import SlackHook
|
2020-04-21 03:29:42 -07:00
|
|
|
from hyperglass.external.generic import GenericHook
|
2020-06-26 12:23:11 -07:00
|
|
|
from hyperglass.external.msteams import MSTeams
|
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."""
|
|
|
|
|
2020-04-21 03:29:42 -07:00
|
|
|
def __new__(cls, config):
|
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)
|
2020-04-18 23:18:50 -07:00
|
|
|
except KeyError:
|
|
|
|
raise HyperglassError(
|
2020-04-21 03:29:42 -07:00
|
|
|
f"'{config.provider.title()}' is not yet supported as a webhook target."
|
2020-04-18 23:18:50 -07:00
|
|
|
)
|