mirror of
https://github.com/healthchecks/healthchecks.git
synced 2024-11-21 15:17:57 +00:00
24 lines
616 B
Python
24 lines
616 B
Python
from __future__ import annotations
|
|
|
|
from functools import wraps
|
|
from typing import Any, Callable
|
|
|
|
from django.conf import settings
|
|
from django.http import HttpRequest, HttpResponse
|
|
|
|
from hc.lib.typealias import ViewFunc
|
|
|
|
|
|
def require_setting(key: str) -> Callable[[ViewFunc], ViewFunc]:
|
|
def decorator(f: ViewFunc) -> ViewFunc:
|
|
@wraps(f)
|
|
def wrapper(request: HttpRequest, *args: Any, **kwds: Any) -> HttpResponse:
|
|
if not getattr(settings, key):
|
|
return HttpResponse(status=404)
|
|
|
|
return f(request, *args, **kwds)
|
|
|
|
return wrapper
|
|
|
|
return decorator
|