From c249b55ff5e458f2ebf6d7752146cbf7fedc853b Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Thu, 30 Dec 2021 14:59:01 +0100 Subject: [PATCH] *: use py3.10 syntax for unions, remove old Type[] import when possible Signed-off-by: Jens Langhammer --- authentik/api/authentication.py | 4 ++-- ...o_20210330_1345_squashed_0028_alter_token_intent.py | 1 - authentik/core/migrations/0022_authenticatedsession.py | 1 - authentik/core/models.py | 6 +++--- authentik/core/signals.py | 4 ++-- authentik/core/sources/flow_manager.py | 4 ++-- authentik/core/tests/test_models.py | 6 +++--- authentik/crypto/models.py | 10 +++++----- ...hed_0019_alter_notificationtransport_webhook_url.py | 2 +- authentik/events/migrations/0003_auto_20200917_1155.py | 2 +- authentik/events/models.py | 6 +++--- authentik/flows/models.py | 6 +++--- authentik/flows/tests/test_stage_model.py | 4 ++-- authentik/flows/tests/test_stage_views.py | 4 ++-- authentik/flows/transfer/importer.py | 4 ++-- authentik/lib/tests/test_serializer_model.py | 4 ++-- authentik/lib/utils/reflection.py | 3 +-- authentik/managed/manager.py | 8 ++++---- authentik/outposts/controllers/kubernetes.py | 3 +-- authentik/outposts/models.py | 10 +++++----- authentik/providers/ldap/models.py | 6 +++--- authentik/providers/oauth2/models.py | 6 +++--- authentik/providers/proxy/models.py | 6 +++--- authentik/providers/saml/models.py | 6 +++--- authentik/providers/saml/processors/request_parser.py | 6 ++---- authentik/sources/ldap/models.py | 5 ++--- authentik/sources/oauth/models.py | 3 ++- authentik/sources/oauth/types/manager.py | 2 +- authentik/sources/oauth/views/base.py | 4 ++-- authentik/sources/saml/models.py | 3 +-- authentik/stages/authenticator_duo/models.py | 4 ++-- authentik/stages/authenticator_sms/models.py | 4 ++-- authentik/stages/authenticator_static/models.py | 4 ++-- authentik/stages/authenticator_totp/models.py | 4 ++-- authentik/stages/authenticator_validate/models.py | 3 +-- authentik/stages/authenticator_webauthn/models.py | 4 ++-- authentik/stages/captcha/models.py | 3 +-- authentik/stages/consent/models.py | 3 +-- authentik/stages/deny/models.py | 3 +-- authentik/stages/dummy/models.py | 3 +-- authentik/stages/email/models.py | 2 +- authentik/stages/identification/models.py | 3 +-- authentik/stages/invitation/models.py | 3 +-- authentik/stages/password/models.py | 4 ++-- authentik/stages/prompt/models.py | 4 ++-- authentik/stages/user_delete/models.py | 3 +-- authentik/stages/user_login/models.py | 3 +-- authentik/stages/user_logout/models.py | 3 +-- authentik/stages/user_write/models.py | 3 +-- 49 files changed, 92 insertions(+), 110 deletions(-) diff --git a/authentik/api/authentication.py b/authentik/api/authentication.py index 0b8fbe738..9566c3d50 100644 --- a/authentik/api/authentication.py +++ b/authentik/api/authentication.py @@ -1,7 +1,7 @@ """API Authentication""" from base64 import b64decode from binascii import Error -from typing import Any, Optional, Union +from typing import Any, Optional from django.conf import settings from rest_framework.authentication import BaseAuthentication, get_authorization_header @@ -69,7 +69,7 @@ def token_secret_key(value: str) -> Optional[User]: class TokenAuthentication(BaseAuthentication): """Token-based authentication using HTTP Bearer authentication""" - def authenticate(self, request: Request) -> Union[tuple[User, Any], None]: + def authenticate(self, request: Request) -> tuple[User, Any] | None: """Token-based authentication using HTTP Bearer authentication""" auth = get_authorization_header(request) diff --git a/authentik/core/migrations/0018_auto_20210330_1345_squashed_0028_alter_token_intent.py b/authentik/core/migrations/0018_auto_20210330_1345_squashed_0028_alter_token_intent.py index 2d934c9bd..f4246b534 100644 --- a/authentik/core/migrations/0018_auto_20210330_1345_squashed_0028_alter_token_intent.py +++ b/authentik/core/migrations/0018_auto_20210330_1345_squashed_0028_alter_token_intent.py @@ -15,7 +15,6 @@ import authentik.lib.models def migrate_sessions(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): - db_alias = schema_editor.connection.alias from django.contrib.sessions.backends.cache import KEY_PREFIX from django.core.cache import cache diff --git a/authentik/core/migrations/0022_authenticatedsession.py b/authentik/core/migrations/0022_authenticatedsession.py index df859a1a2..63e3aa817 100644 --- a/authentik/core/migrations/0022_authenticatedsession.py +++ b/authentik/core/migrations/0022_authenticatedsession.py @@ -12,7 +12,6 @@ import authentik.core.models def migrate_sessions(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): - db_alias = schema_editor.connection.alias from django.contrib.sessions.backends.cache import KEY_PREFIX from django.core.cache import cache diff --git a/authentik/core/models.py b/authentik/core/models.py index 796b809ae..a987ca3ad 100644 --- a/authentik/core/models.py +++ b/authentik/core/models.py @@ -1,7 +1,7 @@ """authentik core models""" from datetime import timedelta from hashlib import md5, sha256 -from typing import Any, Optional, Type +from typing import Any, Optional from urllib.parse import urlencode from uuid import uuid4 @@ -224,7 +224,7 @@ class Provider(SerializerModel): raise NotImplementedError @property - def serializer(self) -> Type[Serializer]: + def serializer(self) -> type[Serializer]: """Get serializer for this model""" raise NotImplementedError @@ -505,7 +505,7 @@ class PropertyMapping(SerializerModel, ManagedModel): raise NotImplementedError @property - def serializer(self) -> Type[Serializer]: + def serializer(self) -> type[Serializer]: """Get serializer for this model""" raise NotImplementedError diff --git a/authentik/core/signals.py b/authentik/core/signals.py index c114ffa65..018d80c85 100644 --- a/authentik/core/signals.py +++ b/authentik/core/signals.py @@ -1,5 +1,5 @@ """authentik core signals""" -from typing import TYPE_CHECKING, Type +from typing import TYPE_CHECKING from django.contrib.auth.signals import user_logged_in, user_logged_out from django.contrib.sessions.backends.cache import KEY_PREFIX @@ -62,7 +62,7 @@ def user_logged_out_session(sender, request: HttpRequest, user: "User", **_): @receiver(pre_delete) -def authenticated_session_delete(sender: Type[Model], instance: "AuthenticatedSession", **_): +def authenticated_session_delete(sender: type[Model], instance: "AuthenticatedSession", **_): """Delete session when authenticated session is deleted""" from authentik.core.models import AuthenticatedSession diff --git a/authentik/core/sources/flow_manager.py b/authentik/core/sources/flow_manager.py index 71e4366ed..490c25550 100644 --- a/authentik/core/sources/flow_manager.py +++ b/authentik/core/sources/flow_manager.py @@ -1,6 +1,6 @@ """Source decision helper""" from enum import Enum -from typing import Any, Optional, Type +from typing import Any, Optional from django.contrib import messages from django.db import IntegrityError @@ -50,7 +50,7 @@ class SourceFlowManager: identifier: str - connection_type: Type[UserSourceConnection] = UserSourceConnection + connection_type: type[UserSourceConnection] = UserSourceConnection def __init__( self, diff --git a/authentik/core/tests/test_models.py b/authentik/core/tests/test_models.py index 1fa924f7b..89cf30765 100644 --- a/authentik/core/tests/test_models.py +++ b/authentik/core/tests/test_models.py @@ -1,6 +1,6 @@ """authentik core models tests""" from time import sleep -from typing import Callable, Type +from typing import Callable from django.test import RequestFactory, TestCase from django.utils.timezone import now @@ -27,7 +27,7 @@ class TestModels(TestCase): self.assertFalse(token.is_expired) -def source_tester_factory(test_model: Type[Stage]) -> Callable: +def source_tester_factory(test_model: type[Stage]) -> Callable: """Test source""" factory = RequestFactory() @@ -47,7 +47,7 @@ def source_tester_factory(test_model: Type[Stage]) -> Callable: return tester -def provider_tester_factory(test_model: Type[Stage]) -> Callable: +def provider_tester_factory(test_model: type[Stage]) -> Callable: """Test provider""" def tester(self: TestModels): diff --git a/authentik/crypto/models.py b/authentik/crypto/models.py index 9c41020de..2f881a2f4 100644 --- a/authentik/crypto/models.py +++ b/authentik/crypto/models.py @@ -1,7 +1,7 @@ """authentik crypto models""" from binascii import hexlify from hashlib import md5 -from typing import Optional, Union +from typing import Optional from uuid import uuid4 from cryptography.hazmat.backends import default_backend @@ -41,8 +41,8 @@ class CertificateKeyPair(ManagedModel, CreatedUpdatedModel): ) _cert: Optional[Certificate] = None - _private_key: Optional[Union[RSAPrivateKey, EllipticCurvePrivateKey, Ed25519PrivateKey]] = None - _public_key: Optional[Union[RSAPublicKey, EllipticCurvePublicKey, Ed25519PublicKey]] = None + _private_key: Optional[RSAPrivateKey | EllipticCurvePrivateKey | Ed25519PrivateKey] = None + _public_key: Optional[RSAPublicKey | EllipticCurvePublicKey | Ed25519PublicKey] = None @property def certificate(self) -> Certificate: @@ -54,7 +54,7 @@ class CertificateKeyPair(ManagedModel, CreatedUpdatedModel): return self._cert @property - def public_key(self) -> Optional[Union[RSAPublicKey, EllipticCurvePublicKey, Ed25519PublicKey]]: + def public_key(self) -> Optional[RSAPublicKey | EllipticCurvePublicKey | Ed25519PublicKey]: """Get public key of the private key""" if not self._public_key: self._public_key = self.private_key.public_key() @@ -63,7 +63,7 @@ class CertificateKeyPair(ManagedModel, CreatedUpdatedModel): @property def private_key( self, - ) -> Optional[Union[RSAPrivateKey, EllipticCurvePrivateKey, Ed25519PrivateKey]]: + ) -> Optional[RSAPrivateKey | EllipticCurvePrivateKey | Ed25519PrivateKey]: """Get python cryptography PrivateKey instance""" if not self._private_key and self.key_data != "": try: diff --git a/authentik/events/migrations/0001_squashed_0019_alter_notificationtransport_webhook_url.py b/authentik/events/migrations/0001_squashed_0019_alter_notificationtransport_webhook_url.py index 57996d3bc..874939c48 100644 --- a/authentik/events/migrations/0001_squashed_0019_alter_notificationtransport_webhook_url.py +++ b/authentik/events/migrations/0001_squashed_0019_alter_notificationtransport_webhook_url.py @@ -19,7 +19,7 @@ def convert_user_to_json(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): Event = apps.get_model("authentik_events", "Event") db_alias = schema_editor.connection.alias - for event in Event.objects.all(): + for event in Event.objects.using(db_alias).all(): event.delete() # Because event objects cannot be updated, we have to re-create them event.pk = None diff --git a/authentik/events/migrations/0003_auto_20200917_1155.py b/authentik/events/migrations/0003_auto_20200917_1155.py index f33dabb08..83d68ce8c 100644 --- a/authentik/events/migrations/0003_auto_20200917_1155.py +++ b/authentik/events/migrations/0003_auto_20200917_1155.py @@ -10,7 +10,7 @@ def convert_user_to_json(apps: Apps, schema_editor: BaseDatabaseSchemaEditor): Event = apps.get_model("authentik_events", "Event") db_alias = schema_editor.connection.alias - for event in Event.objects.all(): + for event in Event.objects.using(db_alias).all(): event.delete() # Because event objects cannot be updated, we have to re-create them event.pk = None diff --git a/authentik/events/models.py b/authentik/events/models.py index c10403488..f0aec86a4 100644 --- a/authentik/events/models.py +++ b/authentik/events/models.py @@ -4,7 +4,7 @@ from collections import Counter from datetime import timedelta from inspect import currentframe from smtplib import SMTPException -from typing import TYPE_CHECKING, Optional, Type, Union +from typing import TYPE_CHECKING, Optional from uuid import uuid4 from django.conf import settings @@ -190,7 +190,7 @@ class Event(ExpiringModel): @staticmethod def new( - action: Union[str, EventAction], + action: str | EventAction, app: Optional[str] = None, **kwargs, ) -> "Event": @@ -517,7 +517,7 @@ class NotificationWebhookMapping(PropertyMapping): return "ak-property-mapping-notification-form" @property - def serializer(self) -> Type["Serializer"]: + def serializer(self) -> type["Serializer"]: from authentik.events.api.notification_mapping import NotificationWebhookMappingSerializer return NotificationWebhookMappingSerializer diff --git a/authentik/flows/models.py b/authentik/flows/models.py index fa466fb36..8eb7d62dd 100644 --- a/authentik/flows/models.py +++ b/authentik/flows/models.py @@ -1,7 +1,7 @@ """Flow models""" from base64 import b64decode, b64encode from pickle import dumps, loads # nosec -from typing import TYPE_CHECKING, Optional, Type +from typing import TYPE_CHECKING, Optional from uuid import uuid4 from django.db import models @@ -63,7 +63,7 @@ class Stage(SerializerModel): objects = InheritanceManager() @property - def type(self) -> Type["StageView"]: + def type(self) -> type["StageView"]: """Return StageView class that implements logic for this stage""" # This is a bit of a workaround, since we can't set class methods with setattr if hasattr(self, "__in_memory_type"): @@ -86,7 +86,7 @@ class Stage(SerializerModel): return f"Stage {self.name}" -def in_memory_stage(view: Type["StageView"]) -> Stage: +def in_memory_stage(view: type["StageView"]) -> Stage: """Creates an in-memory stage instance, based on a `view` as view.""" stage = Stage() # Because we can't pickle a locally generated function, diff --git a/authentik/flows/tests/test_stage_model.py b/authentik/flows/tests/test_stage_model.py index 807442de3..2e1edd54b 100644 --- a/authentik/flows/tests/test_stage_model.py +++ b/authentik/flows/tests/test_stage_model.py @@ -1,5 +1,5 @@ """base model tests""" -from typing import Callable, Type +from typing import Callable from django.test import TestCase @@ -12,7 +12,7 @@ class TestModels(TestCase): """Generic model properties tests""" -def model_tester_factory(test_model: Type[Stage]) -> Callable: +def model_tester_factory(test_model: type[Stage]) -> Callable: """Test a form""" def tester(self: TestModels): diff --git a/authentik/flows/tests/test_stage_views.py b/authentik/flows/tests/test_stage_views.py index 5ebbe2fc2..e5599d540 100644 --- a/authentik/flows/tests/test_stage_views.py +++ b/authentik/flows/tests/test_stage_views.py @@ -1,5 +1,5 @@ """stage view tests""" -from typing import Callable, Type +from typing import Callable from django.test import RequestFactory, TestCase @@ -16,7 +16,7 @@ class TestViews(TestCase): self.exec = FlowExecutorView(request=self.factory.get("/")) -def view_tester_factory(view_class: Type[StageView]) -> Callable: +def view_tester_factory(view_class: type[StageView]) -> Callable: """Test a form""" def tester(self: TestViews): diff --git a/authentik/flows/transfer/importer.py b/authentik/flows/transfer/importer.py index 62b0382ba..f0e7f2298 100644 --- a/authentik/flows/transfer/importer.py +++ b/authentik/flows/transfer/importer.py @@ -2,7 +2,7 @@ from contextlib import contextmanager from copy import deepcopy from json import loads -from typing import Any, Type +from typing import Any from dacite import from_dict from dacite.exceptions import DaciteError @@ -87,7 +87,7 @@ class FlowImporter: def _validate_single(self, entry: FlowBundleEntry) -> BaseSerializer: """Validate a single entry""" model_app_label, model_name = entry.model.split(".") - model: Type[SerializerModel] = apps.get_model(model_app_label, model_name) + model: type[SerializerModel] = apps.get_model(model_app_label, model_name) if not isinstance(model(), ALLOWED_MODELS): raise EntryInvalidError(f"Model {model} not allowed") diff --git a/authentik/lib/tests/test_serializer_model.py b/authentik/lib/tests/test_serializer_model.py index d47787745..ba5cd1ec0 100644 --- a/authentik/lib/tests/test_serializer_model.py +++ b/authentik/lib/tests/test_serializer_model.py @@ -1,5 +1,5 @@ """base model tests""" -from typing import Callable, Type +from typing import Callable from django.test import TestCase from rest_framework.serializers import BaseSerializer @@ -13,7 +13,7 @@ class TestModels(TestCase): """Generic model properties tests""" -def model_tester_factory(test_model: Type[Stage]) -> Callable: +def model_tester_factory(test_model: type[Stage]) -> Callable: """Test a form""" def tester(self: TestModels): diff --git a/authentik/lib/utils/reflection.py b/authentik/lib/utils/reflection.py index a2b175ae8..3a1a88d54 100644 --- a/authentik/lib/utils/reflection.py +++ b/authentik/lib/utils/reflection.py @@ -2,7 +2,6 @@ import os from importlib import import_module from pathlib import Path -from typing import Union from django.conf import settings from kubernetes.config.incluster_config import SERVICE_HOST_ENV_NAME @@ -30,7 +29,7 @@ def class_to_path(cls: type) -> str: return f"{cls.__module__}.{cls.__name__}" -def path_to_class(path: Union[str, None]) -> Union[type, None]: +def path_to_class(path: str | None) -> type | None: """Import module and return class""" if not path: return None diff --git a/authentik/managed/manager.py b/authentik/managed/manager.py index 71dc96e18..20f18fb25 100644 --- a/authentik/managed/manager.py +++ b/authentik/managed/manager.py @@ -1,5 +1,5 @@ """Managed objects manager""" -from typing import Callable, Optional, Type +from typing import Callable, Optional from structlog.stdlib import get_logger @@ -11,11 +11,11 @@ LOGGER = get_logger() class EnsureOp: """Ensure operation, executed as part of an ObjectManager run""" - _obj: Type[ManagedModel] + _obj: type[ManagedModel] _managed_uid: str _kwargs: dict - def __init__(self, obj: Type[ManagedModel], managed_uid: str, **kwargs) -> None: + def __init__(self, obj: type[ManagedModel], managed_uid: str, **kwargs) -> None: self._obj = obj self._managed_uid = managed_uid self._kwargs = kwargs @@ -32,7 +32,7 @@ class EnsureExists(EnsureOp): def __init__( self, - obj: Type[ManagedModel], + obj: type[ManagedModel], managed_uid: str, created_callback: Optional[Callable] = None, **kwargs, diff --git a/authentik/outposts/controllers/kubernetes.py b/authentik/outposts/controllers/kubernetes.py index 45c966b2e..21fe95c83 100644 --- a/authentik/outposts/controllers/kubernetes.py +++ b/authentik/outposts/controllers/kubernetes.py @@ -1,6 +1,5 @@ """Kubernetes deployment controller""" from io import StringIO -from typing import Type from kubernetes.client import VersionApi, VersionInfo from kubernetes.client.api_client import ApiClient @@ -54,7 +53,7 @@ class KubernetesClient(ApiClient, BaseClient): class KubernetesController(BaseController): """Manage deployment of outpost in kubernetes""" - reconcilers: dict[str, Type[KubernetesObjectReconciler]] + reconcilers: dict[str, type[KubernetesObjectReconciler]] reconcile_order: list[str] client: KubernetesClient diff --git a/authentik/outposts/models.py b/authentik/outposts/models.py index 0b0afe63d..f0fe98497 100644 --- a/authentik/outposts/models.py +++ b/authentik/outposts/models.py @@ -2,7 +2,7 @@ from dataclasses import asdict, dataclass, field from datetime import datetime from os import environ -from typing import Iterable, Optional, Union +from typing import Iterable, Optional from uuid import uuid4 from dacite import from_dict @@ -76,7 +76,7 @@ class OutpostConfig: class OutpostModel(Model): """Base model for providers that need more objects than just themselves""" - def get_required_objects(self) -> Iterable[Union[models.Model, str]]: + def get_required_objects(self) -> Iterable[models.Model | str]: """Return a list of all required objects""" return [self] @@ -375,9 +375,9 @@ class Outpost(ManagedModel): Token.objects.filter(identifier=self.token_identifier).delete() return self.token - def get_required_objects(self) -> Iterable[Union[models.Model, str]]: + def get_required_objects(self) -> Iterable[models.Model | str]: """Get an iterator of all objects the user needs read access to""" - objects: list[Union[models.Model, str]] = [ + objects: list[models.Model | str] = [ self, "authentik_events.add_event", ] @@ -404,7 +404,7 @@ class OutpostState: channel_ids: list[str] = field(default_factory=list) last_seen: Optional[datetime] = field(default=None) version: Optional[str] = field(default=None) - version_should: Union[Version, LegacyVersion] = field(default=OUR_VERSION) + version_should: Version | LegacyVersion = field(default=OUR_VERSION) build_hash: str = field(default="") _outpost: Optional[Outpost] = field(default=None) diff --git a/authentik/providers/ldap/models.py b/authentik/providers/ldap/models.py index 83930e428..da540b27e 100644 --- a/authentik/providers/ldap/models.py +++ b/authentik/providers/ldap/models.py @@ -1,5 +1,5 @@ """LDAP Provider""" -from typing import Iterable, Optional, Type, Union +from typing import Iterable, Optional from django.db import models from django.utils.translation import gettext_lazy as _ @@ -78,7 +78,7 @@ class LDAPProvider(OutpostModel, Provider): return "ak-provider-ldap-form" @property - def serializer(self) -> Type[Serializer]: + def serializer(self) -> type[Serializer]: from authentik.providers.ldap.api import LDAPProviderSerializer return LDAPProviderSerializer @@ -86,7 +86,7 @@ class LDAPProvider(OutpostModel, Provider): def __str__(self): return f"LDAP Provider {self.name}" - def get_required_objects(self) -> Iterable[Union[models.Model, str]]: + def get_required_objects(self) -> Iterable[models.Model | str]: required_models = [self, "authentik_core.view_user", "authentik_core.view_group"] if self.certificate is not None: required_models.append(self.certificate) diff --git a/authentik/providers/oauth2/models.py b/authentik/providers/oauth2/models.py index 6162e4ded..18617d1eb 100644 --- a/authentik/providers/oauth2/models.py +++ b/authentik/providers/oauth2/models.py @@ -6,7 +6,7 @@ import time from dataclasses import asdict, dataclass, field from datetime import datetime from hashlib import sha256 -from typing import Any, Optional, Type +from typing import Any, Optional from urllib.parse import urlparse from cryptography.hazmat.primitives.asymmetric.ec import EllipticCurvePrivateKey @@ -112,7 +112,7 @@ class ScopeMapping(PropertyMapping): return "ak-property-mapping-scope-form" @property - def serializer(self) -> Type[Serializer]: + def serializer(self) -> type[Serializer]: from authentik.providers.oauth2.api.scope import ScopeMappingSerializer return ScopeMappingSerializer @@ -267,7 +267,7 @@ class OAuth2Provider(Provider): return "ak-provider-oauth2-form" @property - def serializer(self) -> Type[Serializer]: + def serializer(self) -> type[Serializer]: from authentik.providers.oauth2.api.provider import OAuth2ProviderSerializer return OAuth2ProviderSerializer diff --git a/authentik/providers/proxy/models.py b/authentik/providers/proxy/models.py index 5e26b47c4..d7f9ceebc 100644 --- a/authentik/providers/proxy/models.py +++ b/authentik/providers/proxy/models.py @@ -1,7 +1,7 @@ """authentik proxy models""" import string from random import SystemRandom -from typing import Iterable, Optional, Type, Union +from typing import Iterable, Optional from urllib.parse import urljoin from django.db import models @@ -110,7 +110,7 @@ class ProxyProvider(OutpostModel, OAuth2Provider): return "ak-provider-proxy-form" @property - def serializer(self) -> Type[Serializer]: + def serializer(self) -> type[Serializer]: from authentik.providers.proxy.api import ProxyProviderSerializer return ProxyProviderSerializer @@ -138,7 +138,7 @@ class ProxyProvider(OutpostModel, OAuth2Provider): def __str__(self): return f"Proxy Provider {self.name}" - def get_required_objects(self) -> Iterable[Union[models.Model, str]]: + def get_required_objects(self) -> Iterable[models.Model | str]: required_models = [self] if self.certificate is not None: required_models.append(self.certificate) diff --git a/authentik/providers/saml/models.py b/authentik/providers/saml/models.py index 27f2337bf..18f274a34 100644 --- a/authentik/providers/saml/models.py +++ b/authentik/providers/saml/models.py @@ -1,5 +1,5 @@ """authentik saml_idp Models""" -from typing import Optional, Type +from typing import Optional from django.db import models from django.urls import reverse @@ -163,7 +163,7 @@ class SAMLProvider(Provider): return None @property - def serializer(self) -> Type[Serializer]: + def serializer(self) -> type[Serializer]: from authentik.providers.saml.api import SAMLProviderSerializer return SAMLProviderSerializer @@ -192,7 +192,7 @@ class SAMLPropertyMapping(PropertyMapping): return "ak-property-mapping-saml-form" @property - def serializer(self) -> Type[Serializer]: + def serializer(self) -> type[Serializer]: from authentik.providers.saml.api import SAMLPropertyMappingSerializer return SAMLPropertyMappingSerializer diff --git a/authentik/providers/saml/processors/request_parser.py b/authentik/providers/saml/processors/request_parser.py index 6965766cf..6fbd14ed9 100644 --- a/authentik/providers/saml/processors/request_parser.py +++ b/authentik/providers/saml/processors/request_parser.py @@ -1,7 +1,7 @@ """SAML AuthNRequest Parser and dataclass""" from base64 import b64decode from dataclasses import dataclass -from typing import Optional, Union +from typing import Optional from urllib.parse import quote_plus import xmlsec @@ -54,9 +54,7 @@ class AuthNRequestParser: def __init__(self, provider: SAMLProvider): self.provider = provider - def _parse_xml( - self, decoded_xml: Union[str, bytes], relay_state: Optional[str] - ) -> AuthNRequest: + def _parse_xml(self, decoded_xml: str | bytes, relay_state: Optional[str]) -> AuthNRequest: root = ElementTree.fromstring(decoded_xml) # http://docs.oasis-open.org/security/saml/v2.0/saml-core-2.0-os.pdf diff --git a/authentik/sources/ldap/models.py b/authentik/sources/ldap/models.py index ade91978e..99540da05 100644 --- a/authentik/sources/ldap/models.py +++ b/authentik/sources/ldap/models.py @@ -1,6 +1,5 @@ """authentik LDAP Models""" from ssl import CERT_REQUIRED -from typing import Type from django.db import models from django.utils.translation import gettext_lazy as _ @@ -101,7 +100,7 @@ class LDAPSource(Source): return "ak-source-ldap-form" @property - def serializer(self) -> Type[Serializer]: + def serializer(self) -> type[Serializer]: from authentik.sources.ldap.api import LDAPSourceSerializer return LDAPSourceSerializer @@ -157,7 +156,7 @@ class LDAPPropertyMapping(PropertyMapping): return "ak-property-mapping-ldap-form" @property - def serializer(self) -> Type[Serializer]: + def serializer(self) -> type[Serializer]: from authentik.sources.ldap.api import LDAPPropertyMappingSerializer return LDAPPropertyMappingSerializer diff --git a/authentik/sources/oauth/models.py b/authentik/sources/oauth/models.py index 3d44f9e5e..dfbb8f5a0 100644 --- a/authentik/sources/oauth/models.py +++ b/authentik/sources/oauth/models.py @@ -48,7 +48,7 @@ class OAuthSource(Source): consumer_secret = models.TextField() @property - def type(self) -> Type["SourceType"]: + def type(self) -> type["SourceType"]: """Return the provider instance for this source""" from authentik.sources.oauth.types.manager import MANAGER @@ -58,6 +58,7 @@ class OAuthSource(Source): def component(self) -> str: return "ak-source-oauth-form" + # we're using Type[] instead of type[] here since type[] interferes with the property above @property def serializer(self) -> Type[Serializer]: from authentik.sources.oauth.api.source import OAuthSourceSerializer diff --git a/authentik/sources/oauth/types/manager.py b/authentik/sources/oauth/types/manager.py index d88215dca..a87013190 100644 --- a/authentik/sources/oauth/types/manager.py +++ b/authentik/sources/oauth/types/manager.py @@ -59,7 +59,7 @@ class SourceTypeManager: """Manager to hold all Source types.""" def __init__(self) -> None: - self.__sources: list[Type[SourceType]] = [] + self.__sources: list[type[SourceType]] = [] def type(self): """Class decorator to register classes inline.""" diff --git a/authentik/sources/oauth/views/base.py b/authentik/sources/oauth/views/base.py index 0ab379301..4055df3d6 100644 --- a/authentik/sources/oauth/views/base.py +++ b/authentik/sources/oauth/views/base.py @@ -1,5 +1,5 @@ """OAuth Base views""" -from typing import Optional, Type +from typing import Optional from django.http.request import HttpRequest from structlog.stdlib import get_logger @@ -18,7 +18,7 @@ class OAuthClientMixin: request: HttpRequest # Set by View class - client_class: Optional[Type[BaseOAuthClient]] = None + client_class: Optional[type[BaseOAuthClient]] = None def get_client(self, source: OAuthSource, **kwargs) -> BaseOAuthClient: "Get instance of the OAuth client for this source." diff --git a/authentik/sources/saml/models.py b/authentik/sources/saml/models.py index 882050fc3..b25f05e6b 100644 --- a/authentik/sources/saml/models.py +++ b/authentik/sources/saml/models.py @@ -1,5 +1,4 @@ """saml sp models""" -from typing import Type from django.db import models from django.http import HttpRequest @@ -150,7 +149,7 @@ class SAMLSource(Source): return "ak-source-saml-form" @property - def serializer(self) -> Type[Serializer]: + def serializer(self) -> type[Serializer]: from authentik.sources.saml.api import SAMLSourceSerializer return SAMLSourceSerializer diff --git a/authentik/stages/authenticator_duo/models.py b/authentik/stages/authenticator_duo/models.py index e69e7366b..1bbdc632b 100644 --- a/authentik/stages/authenticator_duo/models.py +++ b/authentik/stages/authenticator_duo/models.py @@ -1,5 +1,5 @@ """Duo stage""" -from typing import Optional, Type +from typing import Optional from django.contrib.auth import get_user_model from django.db import models @@ -28,7 +28,7 @@ class AuthenticatorDuoStage(ConfigurableStage, Stage): return AuthenticatorDuoStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.authenticator_duo.stage import AuthenticatorDuoStageView return AuthenticatorDuoStageView diff --git a/authentik/stages/authenticator_sms/models.py b/authentik/stages/authenticator_sms/models.py index 1deaa89da..40e329490 100644 --- a/authentik/stages/authenticator_sms/models.py +++ b/authentik/stages/authenticator_sms/models.py @@ -1,5 +1,5 @@ """OTP Time-based models""" -from typing import Optional, Type +from typing import Optional from django.contrib.auth import get_user_model from django.db import models @@ -132,7 +132,7 @@ class AuthenticatorSMSStage(ConfigurableStage, Stage): return AuthenticatorSMSStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.authenticator_sms.stage import AuthenticatorSMSStageView return AuthenticatorSMSStageView diff --git a/authentik/stages/authenticator_static/models.py b/authentik/stages/authenticator_static/models.py index ad7f0f65e..dfd97cd40 100644 --- a/authentik/stages/authenticator_static/models.py +++ b/authentik/stages/authenticator_static/models.py @@ -1,5 +1,5 @@ """Static Authenticator models""" -from typing import Optional, Type +from typing import Optional from django.db import models from django.utils.translation import gettext_lazy as _ @@ -22,7 +22,7 @@ class AuthenticatorStaticStage(ConfigurableStage, Stage): return AuthenticatorStaticStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.authenticator_static.stage import AuthenticatorStaticStageView return AuthenticatorStaticStageView diff --git a/authentik/stages/authenticator_totp/models.py b/authentik/stages/authenticator_totp/models.py index 139a66f0b..5018c7a6f 100644 --- a/authentik/stages/authenticator_totp/models.py +++ b/authentik/stages/authenticator_totp/models.py @@ -1,5 +1,5 @@ """OTP Time-based models""" -from typing import Optional, Type +from typing import Optional from django.db import models from django.utils.translation import gettext_lazy as _ @@ -29,7 +29,7 @@ class AuthenticatorTOTPStage(ConfigurableStage, Stage): return AuthenticatorTOTPStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.authenticator_totp.stage import AuthenticatorTOTPStageView return AuthenticatorTOTPStageView diff --git a/authentik/stages/authenticator_validate/models.py b/authentik/stages/authenticator_validate/models.py index fb4b8a86a..c9f9cd382 100644 --- a/authentik/stages/authenticator_validate/models.py +++ b/authentik/stages/authenticator_validate/models.py @@ -1,5 +1,4 @@ """Authenticator Validation Stage""" -from typing import Type from django.contrib.postgres.fields.array import ArrayField from django.db import models @@ -67,7 +66,7 @@ class AuthenticatorValidateStage(Stage): return AuthenticatorValidateStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.authenticator_validate.stage import AuthenticatorValidateStageView return AuthenticatorValidateStageView diff --git a/authentik/stages/authenticator_webauthn/models.py b/authentik/stages/authenticator_webauthn/models.py index cfcba9906..6ba52e850 100644 --- a/authentik/stages/authenticator_webauthn/models.py +++ b/authentik/stages/authenticator_webauthn/models.py @@ -1,5 +1,5 @@ """WebAuthn stage""" -from typing import Optional, Type +from typing import Optional from django.contrib.auth import get_user_model from django.db import models @@ -46,7 +46,7 @@ class AuthenticateWebAuthnStage(ConfigurableStage, Stage): return AuthenticateWebAuthnStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.authenticator_webauthn.stage import AuthenticatorWebAuthnStageView return AuthenticatorWebAuthnStageView diff --git a/authentik/stages/captcha/models.py b/authentik/stages/captcha/models.py index ac15752f3..8ca556a88 100644 --- a/authentik/stages/captcha/models.py +++ b/authentik/stages/captcha/models.py @@ -1,5 +1,4 @@ """authentik captcha stage""" -from typing import Type from django.db import models from django.utils.translation import gettext_lazy as _ @@ -26,7 +25,7 @@ class CaptchaStage(Stage): return CaptchaStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.captcha.stage import CaptchaStageView return CaptchaStageView diff --git a/authentik/stages/consent/models.py b/authentik/stages/consent/models.py index 0294a2aa4..3e13cec8f 100644 --- a/authentik/stages/consent/models.py +++ b/authentik/stages/consent/models.py @@ -1,5 +1,4 @@ """authentik consent stage""" -from typing import Type from django.db import models from django.utils.translation import gettext_lazy as _ @@ -39,7 +38,7 @@ class ConsentStage(Stage): return ConsentStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.consent.stage import ConsentStageView return ConsentStageView diff --git a/authentik/stages/deny/models.py b/authentik/stages/deny/models.py index b403679a0..e1d3240ef 100644 --- a/authentik/stages/deny/models.py +++ b/authentik/stages/deny/models.py @@ -1,5 +1,4 @@ """deny stage models""" -from typing import Type from django.utils.translation import gettext_lazy as _ from django.views import View @@ -18,7 +17,7 @@ class DenyStage(Stage): return DenyStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.deny.stage import DenyStageView return DenyStageView diff --git a/authentik/stages/dummy/models.py b/authentik/stages/dummy/models.py index 2e19ec22a..b2e68ea69 100644 --- a/authentik/stages/dummy/models.py +++ b/authentik/stages/dummy/models.py @@ -1,5 +1,4 @@ """dummy stage models""" -from typing import Type from django.utils.translation import gettext as _ from django.views import View @@ -20,7 +19,7 @@ class DummyStage(Stage): return DummyStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.dummy.stage import DummyStageView return DummyStageView diff --git a/authentik/stages/email/models.py b/authentik/stages/email/models.py index 0908a0010..e4c17a7b2 100644 --- a/authentik/stages/email/models.py +++ b/authentik/stages/email/models.py @@ -88,7 +88,7 @@ class EmailStage(Stage): return EmailStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.email.stage import EmailStageView return EmailStageView diff --git a/authentik/stages/identification/models.py b/authentik/stages/identification/models.py index 57417fb9e..c6e589c4e 100644 --- a/authentik/stages/identification/models.py +++ b/authentik/stages/identification/models.py @@ -1,5 +1,4 @@ """identification stage models""" -from typing import Type from django.contrib.postgres.fields import ArrayField from django.db import models @@ -99,7 +98,7 @@ class IdentificationStage(Stage): return IdentificationStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.identification.stage import IdentificationStageView return IdentificationStageView diff --git a/authentik/stages/invitation/models.py b/authentik/stages/invitation/models.py index 8568fd816..4ed9ef0ea 100644 --- a/authentik/stages/invitation/models.py +++ b/authentik/stages/invitation/models.py @@ -1,5 +1,4 @@ """invitation stage models""" -from typing import Type from uuid import uuid4 from django.db import models @@ -33,7 +32,7 @@ class InvitationStage(Stage): return InvitationStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.invitation.stage import InvitationStageView return InvitationStageView diff --git a/authentik/stages/password/models.py b/authentik/stages/password/models.py index 4ee783c91..6f72e5aff 100644 --- a/authentik/stages/password/models.py +++ b/authentik/stages/password/models.py @@ -1,5 +1,5 @@ """password stage models""" -from typing import Optional, Type +from typing import Optional from django.contrib.postgres.fields import ArrayField from django.db import models @@ -54,7 +54,7 @@ class PasswordStage(ConfigurableStage, Stage): return PasswordStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.password.stage import PasswordStageView return PasswordStageView diff --git a/authentik/stages/prompt/models.py b/authentik/stages/prompt/models.py index bd6381d36..0c04aacc9 100644 --- a/authentik/stages/prompt/models.py +++ b/authentik/stages/prompt/models.py @@ -1,5 +1,5 @@ """prompt models""" -from typing import Any, Optional, Type +from typing import Any, Optional from uuid import uuid4 from django.db import models @@ -146,7 +146,7 @@ class PromptStage(Stage): return PromptStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.prompt.stage import PromptStageView return PromptStageView diff --git a/authentik/stages/user_delete/models.py b/authentik/stages/user_delete/models.py index f8a6cf72f..0fa414f9c 100644 --- a/authentik/stages/user_delete/models.py +++ b/authentik/stages/user_delete/models.py @@ -1,5 +1,4 @@ """delete stage models""" -from typing import Type from django.utils.translation import gettext_lazy as _ from django.views import View @@ -19,7 +18,7 @@ class UserDeleteStage(Stage): return UserDeleteStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.user_delete.stage import UserDeleteStageView return UserDeleteStageView diff --git a/authentik/stages/user_login/models.py b/authentik/stages/user_login/models.py index 4d47a449f..cdd895d58 100644 --- a/authentik/stages/user_login/models.py +++ b/authentik/stages/user_login/models.py @@ -1,5 +1,4 @@ """login stage models""" -from typing import Type from django.db import models from django.utils.translation import gettext_lazy as _ @@ -30,7 +29,7 @@ class UserLoginStage(Stage): return UserLoginStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.user_login.stage import UserLoginStageView return UserLoginStageView diff --git a/authentik/stages/user_logout/models.py b/authentik/stages/user_logout/models.py index ff92f545b..f04f2b02c 100644 --- a/authentik/stages/user_logout/models.py +++ b/authentik/stages/user_logout/models.py @@ -1,5 +1,4 @@ """logout stage models""" -from typing import Type from django.utils.translation import gettext_lazy as _ from django.views import View @@ -18,7 +17,7 @@ class UserLogoutStage(Stage): return UserLogoutStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.user_logout.stage import UserLogoutStageView return UserLogoutStageView diff --git a/authentik/stages/user_write/models.py b/authentik/stages/user_write/models.py index 428c2f505..9f0d16af5 100644 --- a/authentik/stages/user_write/models.py +++ b/authentik/stages/user_write/models.py @@ -1,5 +1,4 @@ """write stage models""" -from typing import Type from django.db import models from django.utils.translation import gettext_lazy as _ @@ -34,7 +33,7 @@ class UserWriteStage(Stage): return UserWriteStageSerializer @property - def type(self) -> Type[View]: + def type(self) -> type[View]: from authentik.stages.user_write.stage import UserWriteStageView return UserWriteStageView