Skip to content

Commit

Permalink
root: add silk and debugging views
Browse files Browse the repository at this point in the history
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
  • Loading branch information
BeryJu committed Apr 21, 2022
1 parent 2399fa4 commit 9077eff
Show file tree
Hide file tree
Showing 7 changed files with 441 additions and 228 deletions.
7 changes: 7 additions & 0 deletions authentik/core/urls.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
"""authentik URL Configuration"""
from django.conf import settings
from django.contrib.auth.decorators import login_required
from django.urls import path
from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.generic import RedirectView
from django.views.generic.base import TemplateView

from authentik.core.views import apps, impersonate
from authentik.core.views.debug import AccessDeniedView
from authentik.core.views.interface import FlowInterfaceView
from authentik.core.views.session import EndSessionView

Expand Down Expand Up @@ -60,3 +62,8 @@
TemplateView.as_view(template_name="if/admin.html"),
),
]

if settings.DEBUG:
urlpatterns += [
path("debug/policy/deny/", AccessDeniedView.as_view(), name="debug-policy-deny"),
]
12 changes: 12 additions & 0 deletions authentik/core/views/debug.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
"""debug view"""
from django.http import HttpRequest, HttpResponse
from django.views.generic import View

from authentik.policies.denied import AccessDeniedResponse


class AccessDeniedView(View):
"""Easily access AccessDeniedResponse"""

def dispatch(self, request: HttpRequest) -> HttpResponse:
return AccessDeniedResponse(request)
9 changes: 7 additions & 2 deletions authentik/events/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,18 @@
from authentik.lib.sentry import before_send
from authentik.lib.utils.errors import exception_to_string

IGNORED_MODELS = (
IGNORED_MODELS = [
Event,
Notification,
UserObjectPermission,
AuthenticatedSession,
StaticToken,
)
]
try:
from silk.models import Request, Response
IGNORED_MODELS += [Request, Response]
except:
pass


class AuditMiddleware:
Expand Down
7 changes: 6 additions & 1 deletion authentik/root/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,14 +460,14 @@ def j_print(event: str, log_level: str = "info", **kwargs):
"django": "WARNING",
"celery": "WARNING",
"selenium": "WARNING",
"grpc": LOG_LEVEL,
"docker": "WARNING",
"urllib3": "WARNING",
"websockets": "WARNING",
"daphne": "WARNING",
"kubernetes": "INFO",
"asyncio": "WARNING",
"aioredis": "WARNING",
"silk": "INFO",
}
for handler_name, level in _LOGGING_HANDLER_MAP.items():
# pyright: reportGeneralTypeIssues=false
Expand Down Expand Up @@ -504,6 +504,11 @@ def j_print(event: str, log_level: str = "info", **kwargs):
if DEBUG:
CELERY_TASK_ALWAYS_EAGER = True
os.environ[ENV_GIT_HASH_KEY] = "dev"
INSTALLED_APPS.append("silk")
SILKY_PYTHON_PROFILER = True
MIDDLEWARE = [
"silk.middleware.SilkyMiddleware"
] + MIDDLEWARE

INSTALLED_APPS.append("authentik.core")

Expand Down
6 changes: 6 additions & 0 deletions authentik/root/urls.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""authentik URL Configuration"""
from django.urls import include, path
from structlog.stdlib import get_logger
from django.conf import settings

from authentik.core.views import error
from authentik.lib.utils.reflection import get_apps
Expand Down Expand Up @@ -47,3 +48,8 @@
path("-/health/live/", LiveView.as_view(), name="health-live"),
path("-/health/ready/", ReadyView.as_view(), name="health-ready"),
]

if settings.DEBUG:
urlpatterns += [
path("debug/silk/", include("silk.urls", namespace="silk")),
]

0 comments on commit 9077eff

Please sign in to comment.