mirror of https://github.com/zulip/zulip.git
webhooks: Rename UnexpectedWebhookEventType to UnsupportedWebhookEventType.
Any exception is an "unexpected event", which means talking about having an "unexpected event logger" or "unexpected event exception" is confusing. As the error message in `exceptions.py` already explains, this is about an _unsupported_ event type. This also switches the path that these exceptions are written to, accordingly.
This commit is contained in:
parent
8016769613
commit
9ea9752e0e
|
@ -622,11 +622,11 @@ webhook bot, notifying them of the missing header.
|
|||
Many third-party services have dozens of different event types. In some cases, we
|
||||
may choose to explicitly ignore specific events. In other cases, there may be
|
||||
events that are new or events that we don't know about. In such cases, we
|
||||
recommend raising `UnexpectedWebhookEventType` (found in
|
||||
recommend raising `UnsupportedWebhookEventType` (found in
|
||||
`zerver/lib/exceptions.py`), like so:
|
||||
|
||||
```
|
||||
raise UnexpectedWebhookEventType(webhook_name, event_type)
|
||||
raise UnsupportedWebhookEventType(webhook_name, event_type)
|
||||
```
|
||||
|
||||
`webhook_name` is the name of the integration that raises the exception.
|
||||
|
|
|
@ -12,7 +12,7 @@ exclude_lines =
|
|||
# Don't require coverage for __str__ statements just used for printing
|
||||
def __str__[(]self[)] -> .*:
|
||||
# Don't require coverage for errors about unsupported webhook event types
|
||||
raise UnexpectedWebhookEventType
|
||||
raise UnsupportedWebhookEventType
|
||||
# Don't require coverage for blocks only run when type-checking
|
||||
if TYPE_CHECKING:
|
||||
# Don't require coverage for abstract methods; they're never called.
|
||||
|
|
|
@ -32,7 +32,7 @@ from zerver.lib.exceptions import (
|
|||
OrganizationAdministratorRequired,
|
||||
OrganizationMemberRequired,
|
||||
OrganizationOwnerRequired,
|
||||
UnexpectedWebhookEventType,
|
||||
UnsupportedWebhookEventType,
|
||||
)
|
||||
from zerver.lib.logging_util import log_to_file
|
||||
from zerver.lib.queue import queue_json_publish
|
||||
|
@ -52,9 +52,9 @@ if settings.ZILENCER_ENABLED:
|
|||
webhook_logger = logging.getLogger("zulip.zerver.webhooks")
|
||||
log_to_file(webhook_logger, settings.API_KEY_ONLY_WEBHOOK_LOG_PATH)
|
||||
|
||||
webhook_unexpected_events_logger = logging.getLogger("zulip.zerver.lib.webhooks.common")
|
||||
log_to_file(webhook_unexpected_events_logger,
|
||||
settings.WEBHOOK_UNEXPECTED_EVENTS_LOG_PATH)
|
||||
webhook_unsupported_events_logger = logging.getLogger("zulip.zerver.lib.webhooks.common")
|
||||
log_to_file(webhook_unsupported_events_logger,
|
||||
settings.WEBHOOK_UNSUPPORTED_EVENTS_LOG_PATH)
|
||||
|
||||
FuncT = TypeVar('FuncT', bound=Callable[..., object])
|
||||
|
||||
|
@ -268,7 +268,7 @@ def log_exception_to_webhook_logger(
|
|||
user_profile: UserProfile,
|
||||
summary: str,
|
||||
payload: str,
|
||||
unexpected_event: bool,
|
||||
unsupported_event: bool,
|
||||
) -> None:
|
||||
if request.content_type == 'application/json':
|
||||
try:
|
||||
|
@ -309,8 +309,8 @@ body:
|
|||
)
|
||||
message = message.strip(' ')
|
||||
|
||||
if unexpected_event:
|
||||
webhook_unexpected_events_logger.exception(message, stack_info=True)
|
||||
if unsupported_event:
|
||||
webhook_unsupported_events_logger.exception(message, stack_info=True)
|
||||
else:
|
||||
webhook_logger.exception(message, stack_info=True)
|
||||
|
||||
|
@ -352,7 +352,7 @@ def api_key_only_webhook_view(
|
|||
user_profile=user_profile,
|
||||
summary=str(err),
|
||||
payload=request.body,
|
||||
unexpected_event=isinstance(err, UnexpectedWebhookEventType),
|
||||
unsupported_event=isinstance(err, UnsupportedWebhookEventType),
|
||||
)
|
||||
raise err
|
||||
|
||||
|
@ -603,7 +603,7 @@ def authenticated_rest_api_view(
|
|||
user_profile=profile,
|
||||
summary=str(err),
|
||||
payload=request_body,
|
||||
unexpected_event=isinstance(err, UnexpectedWebhookEventType),
|
||||
unsupported_event=isinstance(err, UnsupportedWebhookEventType),
|
||||
)
|
||||
|
||||
raise err
|
||||
|
|
|
@ -36,7 +36,7 @@ class ErrorCode(AbstractEnum):
|
|||
MISSING_HTTP_EVENT_HEADER = ()
|
||||
STREAM_DOES_NOT_EXIST = ()
|
||||
UNAUTHORIZED_PRINCIPAL = ()
|
||||
UNEXPECTED_WEBHOOK_EVENT_TYPE = ()
|
||||
UNSUPPORTED_WEBHOOK_EVENT_TYPE = ()
|
||||
BAD_EVENT_QUEUE_ID = ()
|
||||
CSRF_FAILED = ()
|
||||
INVITATION_FAILED = ()
|
||||
|
@ -257,8 +257,8 @@ class InvalidAPIKeyFormatError(InvalidAPIKeyError):
|
|||
def msg_format() -> str:
|
||||
return _("Malformed API key")
|
||||
|
||||
class UnexpectedWebhookEventType(JsonableError):
|
||||
code = ErrorCode.UNEXPECTED_WEBHOOK_EVENT_TYPE
|
||||
class UnsupportedWebhookEventType(JsonableError):
|
||||
code = ErrorCode.UNSUPPORTED_WEBHOOK_EVENT_TYPE
|
||||
data_fields = ['webhook_name', 'event_type']
|
||||
|
||||
def __init__(self, webhook_name: str, event_type: Optional[str]) -> None:
|
||||
|
|
|
@ -40,7 +40,7 @@ from zerver.lib.exceptions import (
|
|||
InvalidAPIKeyError,
|
||||
InvalidAPIKeyFormatError,
|
||||
JsonableError,
|
||||
UnexpectedWebhookEventType,
|
||||
UnsupportedWebhookEventType,
|
||||
)
|
||||
from zerver.lib.initial_password import initial_password
|
||||
from zerver.lib.request import (
|
||||
|
@ -269,9 +269,9 @@ class DecoratorTestCase(ZulipTestCase):
|
|||
raise Exception("raised by webhook function")
|
||||
|
||||
@api_key_only_webhook_view('ClientName')
|
||||
def my_webhook_raises_exception_unexpected_event(
|
||||
def my_webhook_raises_exception_unsupported_event(
|
||||
request: HttpRequest, user_profile: UserProfile) -> None:
|
||||
raise UnexpectedWebhookEventType("helloworld", "test_event")
|
||||
raise UnsupportedWebhookEventType("helloworld", "test_event")
|
||||
|
||||
webhook_bot_email = 'webhook-bot@zulip.com'
|
||||
webhook_bot_realm = get_realm('zulip')
|
||||
|
@ -361,14 +361,14 @@ body:
|
|||
body=request.body,
|
||||
), stack_info=True)
|
||||
|
||||
# Test when an unexpected webhook event occurs
|
||||
with mock.patch('zerver.decorator.webhook_unexpected_events_logger.exception') as mock_exception:
|
||||
# Test when an unsupported webhook event occurs
|
||||
with mock.patch('zerver.decorator.webhook_unsupported_events_logger.exception') as mock_exception:
|
||||
exception_msg = "The 'test_event' event isn't currently supported by the helloworld webhook"
|
||||
with self.assertRaisesRegex(UnexpectedWebhookEventType, exception_msg):
|
||||
with self.assertRaisesRegex(UnsupportedWebhookEventType, exception_msg):
|
||||
request.body = "invalidjson"
|
||||
request.content_type = 'application/json'
|
||||
request.META['HTTP_X_CUSTOM_HEADER'] = 'custom_value'
|
||||
my_webhook_raises_exception_unexpected_event(request)
|
||||
my_webhook_raises_exception_unsupported_event(request)
|
||||
|
||||
message = """
|
||||
summary: {summary}
|
||||
|
@ -540,10 +540,10 @@ body:
|
|||
body=request.body,
|
||||
), stack_info=True)
|
||||
|
||||
def test_authenticated_rest_api_view_logging_unexpected_event(self) -> None:
|
||||
def test_authenticated_rest_api_view_logging_unsupported_event(self) -> None:
|
||||
@authenticated_rest_api_view(webhook_client_name="ClientName")
|
||||
def my_webhook_raises_exception(request: HttpRequest, user_profile: UserProfile) -> None:
|
||||
raise UnexpectedWebhookEventType("helloworld", "test_event")
|
||||
raise UnsupportedWebhookEventType("helloworld", "test_event")
|
||||
|
||||
webhook_bot_email = 'webhook-bot@zulip.com'
|
||||
webhook_bot_realm = get_realm('zulip')
|
||||
|
@ -557,9 +557,9 @@ body:
|
|||
request.POST['payload'] = '{}'
|
||||
request.content_type = 'text/plain'
|
||||
|
||||
with mock.patch('zerver.decorator.webhook_unexpected_events_logger.exception') as mock_exception:
|
||||
with mock.patch('zerver.decorator.webhook_unsupported_events_logger.exception') as mock_exception:
|
||||
exception_msg = "The 'test_event' event isn't currently supported by the helloworld webhook"
|
||||
with self.assertRaisesRegex(UnexpectedWebhookEventType, exception_msg):
|
||||
with self.assertRaisesRegex(UnsupportedWebhookEventType, exception_msg):
|
||||
my_webhook_raises_exception(request)
|
||||
|
||||
message = """
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any, Dict
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
|
@ -30,7 +30,7 @@ def api_basecamp_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||
event = get_event_type(payload)
|
||||
|
||||
if event not in SUPPORT_EVENTS:
|
||||
raise UnexpectedWebhookEventType('Basecamp', event)
|
||||
raise UnsupportedWebhookEventType('Basecamp', event)
|
||||
|
||||
subject = get_project_name(payload)
|
||||
if event.startswith('document_'):
|
||||
|
@ -48,7 +48,7 @@ def api_basecamp_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||
elif event.startswith('comment_'):
|
||||
body = get_comment_body(event, payload)
|
||||
else:
|
||||
raise UnexpectedWebhookEventType('Basecamp', event)
|
||||
raise UnsupportedWebhookEventType('Basecamp', event)
|
||||
|
||||
check_send_webhook_message(request, user_profile, subject, body)
|
||||
return json_success()
|
||||
|
|
|
@ -8,7 +8,7 @@ from typing import Any, Dict, List, Optional
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import (
|
||||
|
@ -161,7 +161,7 @@ def get_type(request: HttpRequest, payload: Dict[str, Any]) -> str:
|
|||
if event_key == 'repo:updated':
|
||||
return event_key
|
||||
|
||||
raise UnexpectedWebhookEventType('BitBucket2', event_key)
|
||||
raise UnsupportedWebhookEventType('BitBucket2', event_key)
|
||||
|
||||
def get_body_based_on_type(type: str) -> Any:
|
||||
fn = GET_SINGLE_MESSAGE_BODY_DEPENDING_ON_TYPE_MAPPER.get(type)
|
||||
|
|
|
@ -6,7 +6,7 @@ from typing import Any, Callable, Dict, List, Optional
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
|
@ -134,7 +134,7 @@ def repo_push_branch_data(payload: Dict[str, Any], change: Dict[str, Any]) -> Di
|
|||
body = get_remove_branch_event_message(user_name, branch_name)
|
||||
else:
|
||||
message = "{}.{}".format(payload["eventKey"], event_type) # nocoverage
|
||||
raise UnexpectedWebhookEventType("BitBucket Server", message)
|
||||
raise UnsupportedWebhookEventType("BitBucket Server", message)
|
||||
|
||||
subject = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=repo_name, branch=branch_name)
|
||||
return {"subject": subject, "body": body}
|
||||
|
@ -150,7 +150,7 @@ def repo_push_tag_data(payload: Dict[str, Any], change: Dict[str, Any]) -> Dict[
|
|||
action = "removed"
|
||||
else:
|
||||
message = "{}.{}".format(payload["eventKey"], event_type) # nocoverage
|
||||
raise UnexpectedWebhookEventType("BitBucket Server", message)
|
||||
raise UnsupportedWebhookEventType("BitBucket Server", message)
|
||||
|
||||
subject = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name)
|
||||
body = get_push_tag_event_message(get_user_name(payload), tag_name, action=action)
|
||||
|
@ -171,7 +171,7 @@ def repo_push_handler(payload: Dict[str, Any], branches: Optional[str]=None,
|
|||
data.append(repo_push_tag_data(payload, change))
|
||||
else:
|
||||
message = "{}.{}".format(payload["eventKey"], event_target_type) # nocoverage
|
||||
raise UnexpectedWebhookEventType("BitBucket Server", message)
|
||||
raise UnsupportedWebhookEventType("BitBucket Server", message)
|
||||
return data
|
||||
|
||||
def get_assignees_string(pr: Dict[str, Any]) -> Optional[str]:
|
||||
|
@ -351,7 +351,7 @@ def get_event_handler(eventkey: str) -> Callable[..., List[Dict[str, str]]]:
|
|||
# The main reason for this function existence is because of mypy
|
||||
handler: Any = EVENT_HANDLER_MAP.get(eventkey)
|
||||
if handler is None:
|
||||
raise UnexpectedWebhookEventType("BitBucket Server", eventkey)
|
||||
raise UnsupportedWebhookEventType("BitBucket Server", eventkey)
|
||||
return handler
|
||||
|
||||
@api_key_only_webhook_view("Bitbucket3")
|
||||
|
|
|
@ -4,7 +4,7 @@ from typing import Any, Dict, Optional
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
|
@ -534,7 +534,7 @@ def api_clubhouse_webhook(
|
|||
body_func: Any = EVENT_BODY_FUNCTION_MAPPER.get(event)
|
||||
topic_func = get_topic_function_based_on_type(payload)
|
||||
if body_func is None or topic_func is None:
|
||||
raise UnexpectedWebhookEventType('Clubhouse', event)
|
||||
raise UnsupportedWebhookEventType('Clubhouse', event)
|
||||
topic = topic_func(payload)
|
||||
body = body_func(payload)
|
||||
|
||||
|
|
|
@ -439,7 +439,7 @@ A temporary team so that I can get some webhook fixtures!
|
|||
),
|
||||
)
|
||||
|
||||
log_mock = patch("zerver.decorator.webhook_unexpected_events_logger.exception")
|
||||
log_mock = patch("zerver.decorator.webhook_unsupported_events_logger.exception")
|
||||
|
||||
with log_mock as m:
|
||||
stream_message = self.send_webhook_payload(
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any, Callable, Dict, Optional
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view, log_exception_to_webhook_logger
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import (
|
||||
|
@ -42,7 +42,7 @@ class Helper:
|
|||
self._request = request
|
||||
self._user_profile = user_profile
|
||||
|
||||
def log_unexpected(self, event: str) -> None:
|
||||
def log_unsupported(self, event: str) -> None:
|
||||
summary = f"The '{event}' event isn't currently supported by the GitHub webhook"
|
||||
request = self._request
|
||||
log_exception_to_webhook_logger(
|
||||
|
@ -50,7 +50,7 @@ class Helper:
|
|||
user_profile=self._user_profile,
|
||||
summary=summary,
|
||||
payload=request.body,
|
||||
unexpected_event=True,
|
||||
unsupported_event=True,
|
||||
)
|
||||
|
||||
def get_opened_or_update_pull_request_body(helper: Helper) -> str:
|
||||
|
@ -301,7 +301,7 @@ def get_team_body(helper: Helper) -> str:
|
|||
return f"Team visibility changed to `{new_visibility}`"
|
||||
|
||||
missing_keys = "/".join(sorted(list(changes.keys())))
|
||||
helper.log_unexpected(f"team/edited (changes: {missing_keys})")
|
||||
helper.log_unsupported(f"team/edited (changes: {missing_keys})")
|
||||
|
||||
# Do our best to give useful info to the customer--at least
|
||||
# if they know something changed, they can go to GitHub for
|
||||
|
@ -620,7 +620,7 @@ def api_github_webhook(
|
|||
"""
|
||||
header_event = validate_extract_webhook_http_header(request, "X_GITHUB_EVENT", "GitHub")
|
||||
if header_event is None:
|
||||
raise UnexpectedWebhookEventType("GitHub", "no header provided")
|
||||
raise UnsupportedWebhookEventType("GitHub", "no header provided")
|
||||
|
||||
event = get_zulip_event_name(header_event, payload, branches)
|
||||
if event is None:
|
||||
|
@ -691,11 +691,11 @@ def get_zulip_event_name(
|
|||
else:
|
||||
# this means GH has actually added new actions since September 2020,
|
||||
# so it's a bit more cause for alarm
|
||||
raise UnexpectedWebhookEventType("GitHub", f"unexpected team action {action}")
|
||||
raise UnsupportedWebhookEventType("GitHub", f"unsupported team action {action}")
|
||||
elif header_event in list(EVENT_FUNCTION_MAPPER.keys()):
|
||||
return header_event
|
||||
elif header_event in IGNORED_EVENTS:
|
||||
return None
|
||||
|
||||
complete_event = "{}:{}".format(header_event, payload.get("action", "???")) # nocoverage
|
||||
raise UnexpectedWebhookEventType('GitHub', complete_event)
|
||||
raise UnsupportedWebhookEventType('GitHub', complete_event)
|
||||
|
|
|
@ -6,7 +6,7 @@ from typing import Any, Dict, Optional
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.validator import check_bool
|
||||
|
@ -452,4 +452,4 @@ def get_event(request: HttpRequest, payload: Dict[str, Any], branches: Optional[
|
|||
if event in list(EVENT_FUNCTION_MAPPER.keys()):
|
||||
return event
|
||||
|
||||
raise UnexpectedWebhookEventType('GitLab', event)
|
||||
raise UnsupportedWebhookEventType('GitLab', event)
|
||||
|
|
|
@ -4,7 +4,7 @@ from typing import Any, Callable, Dict, Optional
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import (
|
||||
|
@ -197,7 +197,7 @@ def gogs_webhook_main(integration_name: str, http_header_name: str,
|
|||
)
|
||||
|
||||
else:
|
||||
raise UnexpectedWebhookEventType('Gogs', event)
|
||||
raise UnsupportedWebhookEventType('Gogs', event)
|
||||
|
||||
check_send_webhook_message(request, user_profile, topic, body)
|
||||
return json_success()
|
||||
|
|
|
@ -3,7 +3,7 @@ from typing import Any, Dict
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
|
@ -55,6 +55,6 @@ def api_gosquared_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||
)
|
||||
check_send_webhook_message(request, user_profile, topic, body)
|
||||
else:
|
||||
raise UnexpectedWebhookEventType('GoSquared', 'unknown_event')
|
||||
raise UnsupportedWebhookEventType('GoSquared', 'unknown_event')
|
||||
|
||||
return json_success()
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any, Callable, Dict, Optional
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import (
|
||||
|
@ -79,7 +79,7 @@ def get_event_handler(event: str) -> Callable[..., str]:
|
|||
# The main reason for this function existence is because of mypy
|
||||
handler: Any = EVENTS_FUNCTION_MAPPER.get(event)
|
||||
if handler is None:
|
||||
raise UnexpectedWebhookEventType("Groove", event)
|
||||
raise UnsupportedWebhookEventType("Groove", event)
|
||||
return handler
|
||||
|
||||
@api_key_only_webhook_view('Groove')
|
||||
|
|
|
@ -5,7 +5,7 @@ from django.db.models import Q
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
|
@ -107,7 +107,7 @@ def api_harbor_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||
content_func = EVENT_FUNCTION_MAPPER.get(event)
|
||||
|
||||
if content_func is None:
|
||||
raise UnexpectedWebhookEventType('Harbor', event)
|
||||
raise UnsupportedWebhookEventType('Harbor', event)
|
||||
|
||||
content: str = content_func(payload, user_profile, operator_username)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any, Callable, Dict, List, Tuple
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
|
@ -279,7 +279,7 @@ EVENT_TO_FUNCTION_MAPPER = {
|
|||
def get_event_handler(event_type: str) -> Callable[..., Tuple[str, str]]:
|
||||
handler: Any = EVENT_TO_FUNCTION_MAPPER.get(event_type)
|
||||
if handler is None:
|
||||
raise UnexpectedWebhookEventType("Intercom", event_type)
|
||||
raise UnsupportedWebhookEventType("Intercom", event_type)
|
||||
return handler
|
||||
|
||||
@api_key_only_webhook_view('Intercom')
|
||||
|
|
|
@ -7,7 +7,7 @@ from django.db.models import Q
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
|
@ -328,7 +328,7 @@ def api_jira_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||
content_func = get_event_handler(event)
|
||||
|
||||
if content_func is None:
|
||||
raise UnexpectedWebhookEventType('Jira', event)
|
||||
raise UnsupportedWebhookEventType('Jira', event)
|
||||
|
||||
subject = get_issue_subject(payload)
|
||||
content: str = content_func(payload, user_profile)
|
||||
|
|
|
@ -3,7 +3,7 @@ from typing import Any, Dict, Iterable
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import (
|
||||
|
@ -51,4 +51,4 @@ def get_template(request: HttpRequest, payload: Dict[str, Any]) -> str:
|
|||
elif event in EVENTS:
|
||||
return message_template + 'is now {state}.'.format(state=payload['state'])
|
||||
else:
|
||||
raise UnexpectedWebhookEventType('Netlify', event)
|
||||
raise UnsupportedWebhookEventType('Netlify', event)
|
||||
|
|
|
@ -4,7 +4,7 @@ from typing import Any, Dict, Optional
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.validator import check_dict
|
||||
|
@ -43,7 +43,7 @@ def api_newrelic_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||
subject = "{} deploy".format(deployment['application_name'])
|
||||
content = DEPLOY_TEMPLATE.format(**deployment)
|
||||
else:
|
||||
raise UnexpectedWebhookEventType('New Relic', 'Unknown Event Type')
|
||||
raise UnsupportedWebhookEventType('New Relic', 'Unknown Event Type')
|
||||
|
||||
check_send_webhook_message(request, user_profile, subject, content)
|
||||
return json_success()
|
||||
|
|
|
@ -4,7 +4,7 @@ from typing import Any, Dict, Iterable
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
|
@ -172,7 +172,7 @@ def api_pagerduty_webhook(
|
|||
break
|
||||
|
||||
if message_type not in PAGER_DUTY_EVENT_NAMES:
|
||||
raise UnexpectedWebhookEventType('Pagerduty', message_type)
|
||||
raise UnsupportedWebhookEventType('Pagerduty', message_type)
|
||||
|
||||
format_dict = build_pagerduty_formatdict(message)
|
||||
send_formated_pagerduty(request, user_profile, message_type, format_dict)
|
||||
|
@ -186,7 +186,7 @@ def api_pagerduty_webhook(
|
|||
break
|
||||
|
||||
if event not in PAGER_DUTY_EVENT_NAMES_V2:
|
||||
raise UnexpectedWebhookEventType('Pagerduty', event)
|
||||
raise UnsupportedWebhookEventType('Pagerduty', event)
|
||||
|
||||
format_dict = build_pagerduty_formatdict_v2(message)
|
||||
send_formated_pagerduty(request, user_profile, event, format_dict)
|
||||
|
|
|
@ -4,7 +4,7 @@ from typing import Any, Dict
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
|
@ -47,7 +47,7 @@ def api_pingdom_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||
subject = get_subject_for_http_request(payload)
|
||||
body = get_body_for_http_request(payload)
|
||||
else:
|
||||
raise UnexpectedWebhookEventType('Pingdom', check_type)
|
||||
raise UnsupportedWebhookEventType('Pingdom', check_type)
|
||||
|
||||
check_send_webhook_message(request, user_profile, subject, body)
|
||||
return json_success()
|
||||
|
|
|
@ -8,7 +8,7 @@ from django.http import HttpRequest, HttpResponse
|
|||
from django.utils.translation import ugettext as _
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import has_request_variables
|
||||
from zerver.lib.response import json_error, json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
|
@ -152,7 +152,7 @@ def api_pivotal_webhook_v5(request: HttpRequest, user_profile: UserProfile) -> T
|
|||
# Known but unsupported Pivotal event types
|
||||
pass
|
||||
else:
|
||||
raise UnexpectedWebhookEventType('Pivotal Tracker', event_type)
|
||||
raise UnsupportedWebhookEventType('Pivotal Tracker', event_type)
|
||||
|
||||
return subject, content
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ from typing import Any, Dict
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
|
@ -31,7 +31,7 @@ def api_raygun_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||
elif event == 'error_activity':
|
||||
message = compose_activity_message(payload)
|
||||
else:
|
||||
raise UnexpectedWebhookEventType('Raygun', event)
|
||||
raise UnsupportedWebhookEventType('Raygun', event)
|
||||
|
||||
topic = 'test'
|
||||
|
||||
|
@ -220,7 +220,7 @@ def compose_notification_message(payload: Dict[str, Any]) -> str:
|
|||
elif "FollowUp" in event_type:
|
||||
return notification_message_follow_up(payload)
|
||||
else:
|
||||
raise UnexpectedWebhookEventType('Raygun', event_type)
|
||||
raise UnsupportedWebhookEventType('Raygun', event_type)
|
||||
|
||||
|
||||
def activity_message(payload: Dict[str, Any]) -> str:
|
||||
|
@ -276,7 +276,7 @@ def compose_activity_message(payload: Dict[str, Any]) -> str:
|
|||
or event_type == "CommentAdded":
|
||||
return activity_message(payload)
|
||||
else:
|
||||
raise UnexpectedWebhookEventType('Raygun', event_type)
|
||||
raise UnsupportedWebhookEventType('Raygun', event_type)
|
||||
|
||||
|
||||
def parse_time(timestamp: str) -> str:
|
||||
|
|
|
@ -3,7 +3,7 @@ from typing import Any, Dict, Iterable
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import (
|
||||
|
@ -180,6 +180,6 @@ def api_reviewboard_webhook(
|
|||
topic = get_review_request_repo_title(payload)
|
||||
check_send_webhook_message(request, user_profile, topic, body)
|
||||
else:
|
||||
raise UnexpectedWebhookEventType('ReviewBoard', event_type)
|
||||
raise UnsupportedWebhookEventType('ReviewBoard', event_type)
|
||||
|
||||
return json_success()
|
||||
|
|
|
@ -4,7 +4,7 @@ from typing import Any, Dict, List, Optional, Tuple
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
|
@ -92,7 +92,7 @@ def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]:
|
|||
|
||||
# We shouldn't support the officially deprecated Raven series of SDKs.
|
||||
if int(event["version"]) < 7:
|
||||
raise UnexpectedWebhookEventType("Sentry", "Raven SDK")
|
||||
raise UnsupportedWebhookEventType("Sentry", "Raven SDK")
|
||||
|
||||
platform_name = event["platform"]
|
||||
syntax_highlight_as = syntax_highlight_as_map.get(platform_name, "")
|
||||
|
@ -155,7 +155,7 @@ def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]:
|
|||
body = MESSAGE_EVENT_TEMPLATE.format(**context)
|
||||
|
||||
else:
|
||||
raise UnexpectedWebhookEventType("Sentry", "unknown-event type")
|
||||
raise UnsupportedWebhookEventType("Sentry", "unknown-event type")
|
||||
|
||||
return (subject, body)
|
||||
|
||||
|
@ -205,7 +205,7 @@ def handle_issue_payload(action: str, issue: Dict[str, Any], actor: Dict[str, An
|
|||
body = ISSUE_IGNORED_MESSAGE_TEMPLATE.format(**context)
|
||||
|
||||
else:
|
||||
raise UnexpectedWebhookEventType("Sentry", "unknown-issue-action type")
|
||||
raise UnsupportedWebhookEventType("Sentry", "unknown-issue-action type")
|
||||
|
||||
return (subject, body)
|
||||
|
||||
|
@ -233,7 +233,7 @@ def api_sentry_webhook(request: HttpRequest, user_profile: UserProfile,
|
|||
elif "issue" in data:
|
||||
subject, body = handle_issue_payload(payload["action"], data["issue"], payload["actor"])
|
||||
else:
|
||||
raise UnexpectedWebhookEventType("Sentry", str(list(data.keys())))
|
||||
raise UnsupportedWebhookEventType("Sentry", str(list(data.keys())))
|
||||
else:
|
||||
subject, body = handle_deprecated_payload(payload)
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any, Dict, Optional, Sequence, Tuple
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.timestamp import timestamp_to_datetime
|
||||
|
@ -191,7 +191,7 @@ def topic_and_body(payload: Dict[str, Any]) -> Tuple[str, str]:
|
|||
raise NotImplementedEventType()
|
||||
|
||||
if body is None:
|
||||
raise UnexpectedWebhookEventType('Stripe', event_type)
|
||||
raise UnsupportedWebhookEventType('Stripe', event_type)
|
||||
return (topic, body)
|
||||
|
||||
def amount_string(amount: int, currency: str) -> str:
|
||||
|
|
|
@ -4,7 +4,7 @@ from typing import Optional
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.validator import check_int
|
||||
|
@ -29,6 +29,6 @@ def api_transifex_webhook(
|
|||
elif reviewed:
|
||||
body = f"Resource {resource} fully reviewed."
|
||||
else:
|
||||
raise UnexpectedWebhookEventType('Transifex', 'Unknown Event Type')
|
||||
raise UnsupportedWebhookEventType('Transifex', 'Unknown Event Type')
|
||||
check_send_webhook_message(request, user_profile, subject, body)
|
||||
return json_success()
|
||||
|
|
|
@ -5,7 +5,7 @@ import orjson
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view, return_success_on_head_request
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
|
@ -40,4 +40,4 @@ def get_subject_and_body(payload: Mapping[str, Any], action_type: str) -> Option
|
|||
if action_type in SUPPORTED_BOARD_ACTIONS:
|
||||
return process_board_action(payload, action_type)
|
||||
|
||||
raise UnexpectedWebhookEventType("Trello", action_type)
|
||||
raise UnsupportedWebhookEventType("Trello", action_type)
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Any, Mapping, Optional, Tuple
|
||||
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
|
||||
SUPPORTED_BOARD_ACTIONS = [
|
||||
'removeMemberFromBoard',
|
||||
|
@ -39,7 +39,7 @@ def get_proper_action(payload: Mapping[str, Any], action_type: Optional[str]) ->
|
|||
return None
|
||||
elif data['old']['name']:
|
||||
return CHANGE_NAME
|
||||
raise UnexpectedWebhookEventType("Trello", action_type)
|
||||
raise UnsupportedWebhookEventType("Trello", action_type)
|
||||
return action_type
|
||||
|
||||
def get_subject(payload: Mapping[str, Any]) -> str:
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
from typing import Any, Mapping, Optional, Tuple
|
||||
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
|
||||
SUPPORTED_CARD_ACTIONS = [
|
||||
'updateCard',
|
||||
|
@ -115,7 +115,7 @@ def get_proper_action(payload: Mapping[str, Any], action_type: str) -> Optional[
|
|||
for field in ignored_fields:
|
||||
if old_data.get(field):
|
||||
return None
|
||||
raise UnexpectedWebhookEventType("Trello", action_type)
|
||||
raise UnsupportedWebhookEventType("Trello", action_type)
|
||||
|
||||
return action_type
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ from typing import Any, Dict, List
|
|||
from django.http import HttpRequest, HttpResponse
|
||||
|
||||
from zerver.decorator import api_key_only_webhook_view
|
||||
from zerver.lib.exceptions import UnexpectedWebhookEventType
|
||||
from zerver.lib.exceptions import UnsupportedWebhookEventType
|
||||
from zerver.lib.request import REQ, has_request_variables
|
||||
from zerver.lib.response import json_success
|
||||
from zerver.lib.webhooks.common import check_send_webhook_message
|
||||
|
@ -75,4 +75,4 @@ def get_event_type(event: Dict[str, Any]) -> str:
|
|||
event_type = event_type_match.group(1)
|
||||
if event_type in EVENT_TYPE_BODY_MAPPER:
|
||||
return event_type
|
||||
raise UnexpectedWebhookEventType('Updown', event['event'])
|
||||
raise UnsupportedWebhookEventType('Updown', event['event'])
|
||||
|
|
|
@ -685,7 +685,7 @@ DIGEST_LOG_PATH = zulip_path("/var/log/zulip/digest.log")
|
|||
ANALYTICS_LOG_PATH = zulip_path("/var/log/zulip/analytics.log")
|
||||
ANALYTICS_LOCK_DIR = zulip_path("/home/zulip/deployments/analytics-lock-dir")
|
||||
API_KEY_ONLY_WEBHOOK_LOG_PATH = zulip_path("/var/log/zulip/webhooks_errors.log")
|
||||
WEBHOOK_UNEXPECTED_EVENTS_LOG_PATH = zulip_path("/var/log/zulip/webhooks_unexpected_events.log")
|
||||
WEBHOOK_UNSUPPORTED_EVENTS_LOG_PATH = zulip_path("/var/log/zulip/webhooks_unsupported_events.log")
|
||||
SOFT_DEACTIVATION_LOG_PATH = zulip_path("/var/log/zulip/soft_deactivation.log")
|
||||
TRACEMALLOC_DUMP_DIR = zulip_path("/var/log/zulip/tracemalloc")
|
||||
SCHEDULED_MESSAGE_DELIVERER_LOG_PATH = zulip_path("/var/log/zulip/scheduled_message_deliverer.log")
|
||||
|
|
Loading…
Reference in New Issue