Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

insping: Strengthen types using WildValue.

Hari Prashant Bhimaraju6f374b666eb6
diff --git a/zerver/webhooks/insping/view.py b/zerver/webhooks/insping/view.py
index 001515a4e8d..0aaa4b2b8b3 100644
--- a/zerver/webhooks/insping/view.py
+++ b/zerver/webhooks/insping/view.py
@@ -1,11 +1,11 @@
import time
-from typing import Any, Dict
from django.http import HttpRequest, HttpResponse
from zerver.decorator import webhook_view
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success
+from zerver.lib.validator import WildValue, check_int, check_string, to_wild_value
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
@@ -22,15 +22,15 @@ State changed to **{state}**:
def api_insping_webhook(
request: HttpRequest,
user_profile: UserProfile,
- payload: Dict[str, Dict[str, Any]] = REQ(argument_type="body"),
+ payload: WildValue = REQ(argument_type="body", converter=to_wild_value),
) -> HttpResponse:
data = payload["webhook_event_data"]
- state_name = data["check_state_name"]
- url_tested = data["request_url"]
- response_time = data["response_time"]
- timestamp = data["request_start_time"]
+ state_name = data["check_state_name"].tame(check_string)
+ url_tested = data["request_url"].tame(check_string)
+ response_time = data["response_time"].tame(check_int)
+ timestamp = data["request_start_time"].tame(check_string)
time_formatted = time.strftime("%c", time.strptime(timestamp, "%Y-%m-%dT%H:%M:%S.%f+00:00"))