Exemple #1
0
        def _wrapped_func_arguments(request: HttpRequest, api_key: str=REQ(),
                                    *args: object, **kwargs: object) -> HttpResponse:
            user_profile = validate_api_key(request, None, api_key, allow_webhook_access=True,
                                            client_name=full_webhook_client_name(webhook_client_name))

            if settings.RATE_LIMITING:
                rate_limit_user(request, user_profile, domain='api_by_user')
            try:
                return view_func(request, user_profile, *args, **kwargs)
            except Exception as err:
                if isinstance(err, InvalidJSONError) and notify_bot_owner_on_invalid_json:
                    # NOTE: importing this at the top of file leads to a
                    # cyclic import; correct fix is probably to move
                    # notify_bot_owner_about_invalid_json to a smaller file.
                    from zerver.lib.webhooks.common import notify_bot_owner_about_invalid_json
                    notify_bot_owner_about_invalid_json(user_profile, webhook_client_name)
                elif isinstance(err, JsonableError) and not isinstance(err, UnsupportedWebhookEventType):
                    pass
                else:
                    if isinstance(err, UnsupportedWebhookEventType):
                        err.webhook_name = webhook_client_name
                    log_exception_to_webhook_logger(
                        summary=str(err),
                        unsupported_event=isinstance(err, UnsupportedWebhookEventType),
                    )
                raise err
Exemple #2
0
        def _wrapped_func_arguments(request: HttpRequest,
                                    api_key: str = REQ(),
                                    *args: Any,
                                    **kwargs: Any) -> HttpResponse:
            user_profile = validate_api_key(
                request,
                None,
                api_key,
                is_webhook=True,
                client_name=full_webhook_client_name(webhook_client_name))

            if settings.RATE_LIMITING:
                rate_limit_user(request, user_profile, domain='all')
            try:
                return view_func(request, user_profile, *args, **kwargs)
            except InvalidJSONError as e:
                if not notify_bot_owner_on_invalid_json:
                    raise e
                # NOTE: importing this at the top of file leads to a
                # cyclic import; correct fix is probably to move
                # notify_bot_owner_about_invalid_json to a smaller file.
                from zerver.lib.webhooks.common import notify_bot_owner_about_invalid_json
                notify_bot_owner_about_invalid_json(user_profile,
                                                    webhook_client_name)
            except Exception as err:
                log_exception_to_webhook_logger(request, user_profile)
                raise err
Exemple #3
0
        def _wrapped_func_arguments(request: HttpRequest,
                                    api_key: str = REQ(),
                                    *args: Any,
                                    **kwargs: Any) -> HttpResponse:
            user_profile = validate_api_key(
                request,
                None,
                api_key,
                is_webhook=True,
                client_name=full_webhook_client_name(webhook_client_name))

            if settings.RATE_LIMITING:
                rate_limit_user(request, user_profile, domain='api_by_user')
            try:
                return view_func(request, user_profile, *args, **kwargs)
            except Exception as err:
                if isinstance(
                        err,
                        InvalidJSONError) and notify_bot_owner_on_invalid_json:
                    # NOTE: importing this at the top of file leads to a
                    # cyclic import; correct fix is probably to move
                    # notify_bot_owner_about_invalid_json to a smaller file.
                    from zerver.lib.webhooks.common import notify_bot_owner_about_invalid_json
                    notify_bot_owner_about_invalid_json(
                        user_profile, webhook_client_name)
                else:
                    kwargs = {'request': request, 'user_profile': user_profile}
                    if isinstance(err, UnexpectedWebhookEventType):
                        kwargs['unexpected_event'] = True

                    log_exception_to_webhook_logger(**kwargs)
                raise err
Exemple #4
0
        def _wrapped_func_arguments(request: HttpRequest, api_key: str=REQ(),
                                    *args: Any, **kwargs: Any) -> HttpResponse:
            user_profile = validate_api_key(request, None, api_key, is_webhook=True,
                                            client_name=full_webhook_client_name(webhook_client_name))

            if settings.RATE_LIMITING:
                rate_limit_user(request, user_profile, domain='all')
            try:
                return view_func(request, user_profile, *args, **kwargs)
            except Exception as err:
                if isinstance(err, InvalidJSONError) and notify_bot_owner_on_invalid_json:
                    # NOTE: importing this at the top of file leads to a
                    # cyclic import; correct fix is probably to move
                    # notify_bot_owner_about_invalid_json to a smaller file.
                    from zerver.lib.webhooks.common import notify_bot_owner_about_invalid_json
                    notify_bot_owner_about_invalid_json(user_profile, webhook_client_name)
                else:
                    log_exception_to_webhook_logger(request, user_profile)
                raise err