authentik.core.apps
authentik core app config
1"""authentik core app config""" 2 3import os 4 5from django.utils.translation import gettext_lazy as _ 6 7from authentik.admin.flags import Flag 8from authentik.blueprints.apps import ManagedAppConfig 9from authentik.lib.config import CONFIG 10from authentik.lib.tracing import TRACER_DEFER_POSTFORK_ENV_VAR, setup_post_fork, setup_pre_fork 11from authentik.tasks.schedules.common import ScheduleSpec 12 13 14class Setup(Flag[bool], key="setup"): 15 16 default = False 17 visibility = "system" 18 19 20class AppAccessWithoutBindings(Flag[bool], key="core_default_app_access"): 21 22 default = True 23 visibility = "none" 24 description = _("Applications with no policies bound can be accessed by any user.") 25 26 27class AuthentikCoreConfig(ManagedAppConfig): 28 """authentik core app config""" 29 30 name = "authentik.core" 31 label = "authentik_core" 32 verbose_name = "authentik Core" 33 mountpoint = "" 34 default = True 35 36 def ready(self) -> None: 37 if CONFIG.get_bool("error_reporting.enabled", False): 38 setup_pre_fork() 39 # Under gunicorn's preload_app, some backends must finish initializing after 40 # the fork instead (see lifecycle/gunicorn.conf.py's post_fork hook) 41 if not os.environ.get(TRACER_DEFER_POSTFORK_ENV_VAR): 42 setup_post_fork() 43 return super().ready() 44 45 def import_related(self): 46 super().import_related() 47 self.import_module("authentik.core.setup.signals") 48 49 @ManagedAppConfig.reconcile 50 def source_inbuilt(self): 51 """Reconcile inbuilt source""" 52 from authentik.core.models import Source 53 54 Source.objects.update_or_create( 55 defaults={ 56 "name": "authentik Built-in", 57 "slug": "authentik-built-in", 58 }, 59 managed=Source.MANAGED_INBUILT, 60 ) 61 62 @property 63 def schedule_specs(self) -> list[ScheduleSpec]: 64 from authentik.core.tasks import clean_expired_models, clean_temporary_users 65 66 return [ 67 ScheduleSpec( 68 actor=clean_expired_models, 69 crontab="2-59/5 * * * *", 70 ), 71 ScheduleSpec( 72 actor=clean_temporary_users, 73 crontab="9-59/5 * * * *", 74 ), 75 ]
Abstract base class for generic types.
On Python 3.12 and newer, generic classes implicitly inherit from Generic when they declare a parameter list after the class's name::
class Mapping[KT, VT]:
def __getitem__(self, key: KT) -> VT:
...
# Etc.
On older versions of Python, however, generic classes have to explicitly inherit from Generic.
After a class has been declared to be generic, it can then be used as follows::
def lookup_name[KT, VT](mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
try:
return mapping[key]
except KeyError:
return default
Inherited Members
21class AppAccessWithoutBindings(Flag[bool], key="core_default_app_access"): 22 23 default = True 24 visibility = "none" 25 description = _("Applications with no policies bound can be accessed by any user.")
Abstract base class for generic types.
On Python 3.12 and newer, generic classes implicitly inherit from Generic when they declare a parameter list after the class's name::
class Mapping[KT, VT]:
def __getitem__(self, key: KT) -> VT:
...
# Etc.
On older versions of Python, however, generic classes have to explicitly inherit from Generic.
After a class has been declared to be generic, it can then be used as follows::
def lookup_name[KT, VT](mapping: Mapping[KT, VT], key: KT, default: VT) -> VT:
try:
return mapping[key]
except KeyError:
return default
Inherited Members
28class AuthentikCoreConfig(ManagedAppConfig): 29 """authentik core app config""" 30 31 name = "authentik.core" 32 label = "authentik_core" 33 verbose_name = "authentik Core" 34 mountpoint = "" 35 default = True 36 37 def ready(self) -> None: 38 if CONFIG.get_bool("error_reporting.enabled", False): 39 setup_pre_fork() 40 # Under gunicorn's preload_app, some backends must finish initializing after 41 # the fork instead (see lifecycle/gunicorn.conf.py's post_fork hook) 42 if not os.environ.get(TRACER_DEFER_POSTFORK_ENV_VAR): 43 setup_post_fork() 44 return super().ready() 45 46 def import_related(self): 47 super().import_related() 48 self.import_module("authentik.core.setup.signals") 49 50 @ManagedAppConfig.reconcile 51 def source_inbuilt(self): 52 """Reconcile inbuilt source""" 53 from authentik.core.models import Source 54 55 Source.objects.update_or_create( 56 defaults={ 57 "name": "authentik Built-in", 58 "slug": "authentik-built-in", 59 }, 60 managed=Source.MANAGED_INBUILT, 61 ) 62 63 @property 64 def schedule_specs(self) -> list[ScheduleSpec]: 65 from authentik.core.tasks import clean_expired_models, clean_temporary_users 66 67 return [ 68 ScheduleSpec( 69 actor=clean_expired_models, 70 crontab="2-59/5 * * * *", 71 ), 72 ScheduleSpec( 73 actor=clean_temporary_users, 74 crontab="9-59/5 * * * *", 75 ), 76 ]
authentik core app config
37 def ready(self) -> None: 38 if CONFIG.get_bool("error_reporting.enabled", False): 39 setup_pre_fork() 40 # Under gunicorn's preload_app, some backends must finish initializing after 41 # the fork instead (see lifecycle/gunicorn.conf.py's post_fork hook) 42 if not os.environ.get(TRACER_DEFER_POSTFORK_ENV_VAR): 43 setup_post_fork() 44 return super().ready()
Override this method in subclasses to run code when Django starts.
50 @ManagedAppConfig.reconcile 51 def source_inbuilt(self): 52 """Reconcile inbuilt source""" 53 from authentik.core.models import Source 54 55 Source.objects.update_or_create( 56 defaults={ 57 "name": "authentik Built-in", 58 "slug": "authentik-built-in", 59 }, 60 managed=Source.MANAGED_INBUILT, 61 )
Reconcile inbuilt source
63 @property 64 def schedule_specs(self) -> list[ScheduleSpec]: 65 from authentik.core.tasks import clean_expired_models, clean_temporary_users 66 67 return [ 68 ScheduleSpec( 69 actor=clean_expired_models, 70 crontab="2-59/5 * * * *", 71 ), 72 ScheduleSpec( 73 actor=clean_temporary_users, 74 crontab="9-59/5 * * * *", 75 ), 76 ]
Get a list of schedule specs that must exist