mirror of
https://github.com/healthchecks/healthchecks.git
synced 2025-04-14 17:08:29 +00:00
Improve type hints in hc.api.decorators
This commit is contained in:
parent
5ebc7696d7
commit
33a0f65144
1 changed files with 5 additions and 5 deletions
|
@ -18,11 +18,11 @@ class ApiRequest(HttpRequest):
|
||||||
v: int
|
v: int
|
||||||
|
|
||||||
|
|
||||||
def error(msg, status=400):
|
def error(msg: str, status: int = 400) -> JsonResponse:
|
||||||
return JsonResponse({"error": msg}, status=status)
|
return JsonResponse({"error": msg}, status=status)
|
||||||
|
|
||||||
|
|
||||||
def _get_api_version(request) -> int:
|
def _get_api_version(request: HttpRequest) -> int:
|
||||||
if request.path_info.startswith("/api/v3/"):
|
if request.path_info.startswith("/api/v3/"):
|
||||||
return 3
|
return 3
|
||||||
if request.path_info.startswith("/api/v2/"):
|
if request.path_info.startswith("/api/v2/"):
|
||||||
|
@ -32,7 +32,7 @@ def _get_api_version(request) -> int:
|
||||||
|
|
||||||
def authorize(f: ViewFunc) -> ViewFunc:
|
def authorize(f: ViewFunc) -> ViewFunc:
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def wrapper(request, *args, **kwds):
|
def wrapper(request: ApiRequest, *args: Any, **kwds: Any) -> HttpResponse:
|
||||||
# For POST requests, we may need to look for the API key inside the
|
# For POST requests, we may need to look for the API key inside the
|
||||||
# request body. Parse the body and put it in request.json
|
# request body. Parse the body and put it in request.json
|
||||||
# so views can avoid parsing it again.
|
# so views can avoid parsing it again.
|
||||||
|
@ -70,7 +70,7 @@ def authorize(f: ViewFunc) -> ViewFunc:
|
||||||
|
|
||||||
def authorize_read(f: ViewFunc) -> ViewFunc:
|
def authorize_read(f: ViewFunc) -> ViewFunc:
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def wrapper(request, *args, **kwds):
|
def wrapper(request: ApiRequest, *args: Any, **kwds: Any) -> HttpResponse:
|
||||||
if "HTTP_X_API_KEY" in request.META:
|
if "HTTP_X_API_KEY" in request.META:
|
||||||
api_key = request.META["HTTP_X_API_KEY"]
|
api_key = request.META["HTTP_X_API_KEY"]
|
||||||
else:
|
else:
|
||||||
|
@ -100,7 +100,7 @@ def cors(*methods: str) -> Callable[[ViewFunc], ViewFunc]:
|
||||||
|
|
||||||
def decorator(f: ViewFunc) -> ViewFunc:
|
def decorator(f: ViewFunc) -> ViewFunc:
|
||||||
@wraps(f)
|
@wraps(f)
|
||||||
def wrapper(request, *args, **kwds):
|
def wrapper(request: HttpRequest, *args: Any, **kwds: Any) -> HttpResponse:
|
||||||
if request.method == "OPTIONS":
|
if request.method == "OPTIONS":
|
||||||
# Handle OPTIONS here
|
# Handle OPTIONS here
|
||||||
response = HttpResponse(status=204)
|
response = HttpResponse(status=204)
|
||||||
|
|
Loading…
Add table
Reference in a new issue