root: early spring clean for linting (#8498)
* remove pyright Signed-off-by: Jens Langhammer <jens@goauthentik.io> * remove pylint Signed-off-by: Jens Langhammer <jens@goauthentik.io> * replace pylint with ruff Signed-off-by: Jens Langhammer <jens@goauthentik.io> * ruff fix Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * fix UP038 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix DJ012 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix default arg Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix UP031 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * rename stage type to view Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix DJ008 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix remaining upgrade Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix PLR2004 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix B904 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix PLW2901 Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix remaining issues Signed-off-by: Jens Langhammer <jens@goauthentik.io> * prevent ruff from breaking the code Signed-off-by: Jens Langhammer <jens@goauthentik.io> * stages/prompt: refactor field building Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> * fix tests Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fix lint Signed-off-by: Jens Langhammer <jens@goauthentik.io> * fully remove isort Signed-off-by: Jens Langhammer <jens@goauthentik.io> --------- Signed-off-by: Jens Langhammer <jens@goauthentik.io> Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> Co-authored-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
@ -18,8 +18,8 @@ from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
|
||||
defuse_stdlib()
|
||||
django.setup()
|
||||
|
||||
# pylint: disable=wrong-import-position
|
||||
from authentik.root import websocket # noqa # isort:skip
|
||||
|
||||
from authentik.root import websocket # noqa
|
||||
|
||||
|
||||
class LifespanApp:
|
||||
|
||||
@ -1,11 +1,11 @@
|
||||
"""authentik core celery"""
|
||||
|
||||
import os
|
||||
from collections.abc import Callable
|
||||
from contextvars import ContextVar
|
||||
from logging.config import dictConfig
|
||||
from pathlib import Path
|
||||
from tempfile import gettempdir
|
||||
from typing import Callable
|
||||
|
||||
from celery import bootsteps
|
||||
from celery.apps.worker import Worker
|
||||
|
||||
@ -1,15 +1,16 @@
|
||||
"""Dynamically set SameSite depending if the upstream connection is TLS or not"""
|
||||
|
||||
from collections.abc import Callable
|
||||
from hashlib import sha512
|
||||
from time import perf_counter, time
|
||||
from typing import Any, Callable, Optional
|
||||
from typing import Any
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.sessions.backends.base import UpdateError
|
||||
from django.contrib.sessions.exceptions import SessionInterrupted
|
||||
from django.contrib.sessions.middleware import SessionMiddleware as UpstreamSessionMiddleware
|
||||
from django.http.request import HttpRequest
|
||||
from django.http.response import HttpResponse
|
||||
from django.http.response import HttpResponse, HttpResponseServerError
|
||||
from django.middleware.csrf import CSRF_SESSION_KEY
|
||||
from django.middleware.csrf import CsrfViewMiddleware as UpstreamCsrfViewMiddleware
|
||||
from django.utils.cache import patch_vary_headers
|
||||
@ -99,7 +100,7 @@ class SessionMiddleware(UpstreamSessionMiddleware):
|
||||
expires = http_date(expires_time)
|
||||
# Save the session data and refresh the client cookie.
|
||||
# Skip session save for 500 responses, refs #3881.
|
||||
if response.status_code != 500:
|
||||
if response.status_code != HttpResponseServerError.status_code:
|
||||
try:
|
||||
request.session.save()
|
||||
except UpdateError:
|
||||
@ -107,7 +108,7 @@ class SessionMiddleware(UpstreamSessionMiddleware):
|
||||
"The request's session was deleted before the "
|
||||
"request completed. The user may have logged "
|
||||
"out in a concurrent request, for example."
|
||||
)
|
||||
) from None
|
||||
payload = {
|
||||
"sid": request.session.session_key,
|
||||
"iss": "authentik",
|
||||
@ -191,7 +192,7 @@ class ClientIPMiddleware:
|
||||
|
||||
# FIXME: this should probably not be in `root` but rather in a middleware in `outposts`
|
||||
# but for now it's fine
|
||||
def _get_outpost_override_ip(self, request: HttpRequest) -> Optional[str]:
|
||||
def _get_outpost_override_ip(self, request: HttpRequest) -> str | None:
|
||||
"""Get the actual remote IP when set by an outpost. Only
|
||||
allowed when the request is authenticated, by an outpost internal service account"""
|
||||
if (
|
||||
@ -228,7 +229,7 @@ class ClientIPMiddleware:
|
||||
setattr(request, self.request_attr_outpost_user, user)
|
||||
return delegated_ip
|
||||
|
||||
def _get_client_ip(self, request: Optional[HttpRequest]) -> str:
|
||||
def _get_client_ip(self, request: HttpRequest | None) -> str:
|
||||
"""Attempt to get the client's IP by checking common HTTP Headers.
|
||||
Returns none if no IP Could be found"""
|
||||
if not request:
|
||||
@ -239,7 +240,7 @@ class ClientIPMiddleware:
|
||||
return self._get_client_ip_from_meta(request.META)
|
||||
|
||||
@staticmethod
|
||||
def get_outpost_user(request: HttpRequest) -> Optional[User]:
|
||||
def get_outpost_user(request: HttpRequest) -> User | None:
|
||||
"""Get outpost user that authenticated this request"""
|
||||
return getattr(request, ClientIPMiddleware.request_attr_outpost_user, None)
|
||||
|
||||
|
||||
@ -15,19 +15,16 @@ from authentik.lib.config import CONFIG
|
||||
class FileStorage(FileSystemStorage):
|
||||
"""File storage backend"""
|
||||
|
||||
# pylint: disable=invalid-overridden-method
|
||||
@property
|
||||
def base_location(self):
|
||||
return os.path.join(
|
||||
self._value_or_setting(self._location, settings.MEDIA_ROOT), connection.schema_name
|
||||
)
|
||||
|
||||
# pylint: disable=invalid-overridden-method
|
||||
@property
|
||||
def location(self):
|
||||
return os.path.abspath(self.base_location)
|
||||
|
||||
# pylint: disable=invalid-overridden-method
|
||||
@property
|
||||
def base_url(self):
|
||||
if self._base_url is not None and not self._base_url.endswith("/"):
|
||||
@ -35,7 +32,6 @@ class FileStorage(FileSystemStorage):
|
||||
return f"{self._base_url}/{connection.schema_name}/"
|
||||
|
||||
|
||||
# pylint: disable=abstract-method
|
||||
class S3Storage(BaseS3Storage):
|
||||
"""S3 storage backend"""
|
||||
|
||||
@ -77,13 +73,12 @@ class S3Storage(BaseS3Storage):
|
||||
|
||||
def _normalize_name(self, name):
|
||||
try:
|
||||
# pylint: disable=no-member
|
||||
|
||||
return safe_join(self.location, connection.schema_name, name)
|
||||
except ValueError:
|
||||
raise SuspiciousOperation("Attempted access to '%s' denied." % name)
|
||||
raise SuspiciousOperation("Attempted access to '%s' denied." % name) from None
|
||||
|
||||
# This is a fix for https://github.com/jschneier/django-storages/pull/839
|
||||
# pylint: disable=arguments-differ,no-member
|
||||
def url(self, name, parameters=None, expire=None, http_method=None):
|
||||
# Preserve the trailing slash after normalizing the path.
|
||||
name = self._normalize_name(clean_name(name))
|
||||
@ -109,7 +104,7 @@ class S3Storage(BaseS3Storage):
|
||||
# Remove signing parameter and previously added key "/".
|
||||
root_url = self._strip_signing_parameters(root_url_signed)[:-1]
|
||||
# Replace bucket domain with custom domain.
|
||||
custom_url = "{}//{}/".format(self.url_protocol, self.custom_domain)
|
||||
custom_url = f"{self.url_protocol}//{self.custom_domain}/"
|
||||
url = url.replace(root_url, custom_url)
|
||||
|
||||
if self.querystring_auth:
|
||||
|
||||
@ -77,23 +77,21 @@ class PytestTestRunner(DiscoverRunner): # pragma: no cover
|
||||
if os.path.exists(label_as_path):
|
||||
self.args.append(label_as_path)
|
||||
valid_label_found = True
|
||||
elif "::" in label:
|
||||
self.args.append(label)
|
||||
valid_label_found = True
|
||||
# Convert dotted module path to file_path::class::method
|
||||
else:
|
||||
# Already correctly formatted test found (file_path::class::method)
|
||||
if "::" in label:
|
||||
self.args.append(label)
|
||||
valid_label_found = True
|
||||
# Convert dotted module path to file_path::class::method
|
||||
else:
|
||||
path_pieces = label.split(".")
|
||||
# Check whether only class or class and method are specified
|
||||
for i in range(-1, -3, -1):
|
||||
path = os.path.join(*path_pieces[:i]) + ".py"
|
||||
label_as_path = os.path.abspath(path)
|
||||
if os.path.exists(label_as_path):
|
||||
path_method = label_as_path + "::" + "::".join(path_pieces[i:])
|
||||
self.args.append(path_method)
|
||||
valid_label_found = True
|
||||
break
|
||||
path_pieces = label.split(".")
|
||||
# Check whether only class or class and method are specified
|
||||
for i in range(-1, -3, -1):
|
||||
path = os.path.join(*path_pieces[:i]) + ".py"
|
||||
label_as_path = os.path.abspath(path)
|
||||
if os.path.exists(label_as_path):
|
||||
path_method = label_as_path + "::" + "::".join(path_pieces[i:])
|
||||
self.args.append(path_method)
|
||||
valid_label_found = True
|
||||
break
|
||||
|
||||
if not valid_label_found:
|
||||
raise RuntimeError(
|
||||
|
||||
@ -20,10 +20,10 @@ for _authentik_app in get_apps():
|
||||
mountpoints = None
|
||||
base_url_module = _authentik_app.name + ".urls"
|
||||
if hasattr(_authentik_app, "mountpoint"):
|
||||
mountpoint = getattr(_authentik_app, "mountpoint")
|
||||
mountpoint = _authentik_app.mountpoint
|
||||
mountpoints = {base_url_module: mountpoint}
|
||||
if hasattr(_authentik_app, "mountpoints"):
|
||||
mountpoints = getattr(_authentik_app, "mountpoints")
|
||||
mountpoints = _authentik_app.mountpoints
|
||||
if not mountpoints:
|
||||
continue
|
||||
for module, mountpoint in mountpoints.items():
|
||||
|
||||
@ -16,7 +16,7 @@ for _authentik_app in get_apps():
|
||||
continue
|
||||
if not hasattr(api_urls, "websocket_urlpatterns"):
|
||||
continue
|
||||
urls: list = getattr(api_urls, "websocket_urlpatterns")
|
||||
urls: list = api_urls.websocket_urlpatterns
|
||||
websocket_urlpatterns.extend(urls)
|
||||
LOGGER.debug(
|
||||
"Mounted Websocket URLs",
|
||||
|
||||
Reference in New Issue
Block a user