authentik.events.apps
authentik events app
1"""authentik events app""" 2 3from authentik.blueprints.apps import ManagedAppConfig 4from authentik.lib.config import CONFIG, ENV_PREFIX 5from authentik.lib.utils.time import fqdn_rand 6from authentik.tasks.schedules.common import ScheduleSpec 7 8 9class AuthentikEventsConfig(ManagedAppConfig): 10 """authentik events app""" 11 12 name = "authentik.events" 13 label = "authentik_events" 14 verbose_name = "authentik Events" 15 default = True 16 17 @property 18 def schedule_specs(self) -> list[ScheduleSpec]: 19 from authentik.events.tasks import notification_cleanup 20 21 return [ 22 ScheduleSpec( 23 actor=notification_cleanup, 24 crontab=f"{fqdn_rand('notification_cleanup')} */8 * * *", 25 ), 26 ] 27 28 @ManagedAppConfig.reconcile 29 def check_deprecations(self): 30 """Check for config deprecations""" 31 from authentik.events.models import Event, EventAction 32 33 for key_replace, msg in CONFIG.deprecations.items(): 34 key, replace = key_replace 35 key_env = f"{ENV_PREFIX}_{key.replace('.', '__')}".upper() 36 replace_env = f"{ENV_PREFIX}_{replace.replace('.', '__')}".upper() 37 if Event.objects.filter( 38 action=EventAction.CONFIGURATION_ERROR, context__deprecated_option=key 39 ).exists(): 40 continue 41 Event.new( 42 EventAction.CONFIGURATION_ERROR, 43 deprecated_option=key, 44 deprecated_env=key_env, 45 replacement_option=replace, 46 replacement_env=replace_env, 47 message=msg, 48 ).save() 49 50 @ManagedAppConfig.reconcile 51 def check_db_encoding(self): 52 """Check for deprecated database encoding""" 53 from django.db import connection 54 55 from authentik.events.models import Event 56 57 for message in connection.validation.check(): 58 if message.id != "ak.db.W002": 59 continue 60 Event.log_deprecation( 61 "authentik.db.encoding", f"{message.msg} {message.hint}", cause=message.msg 62 )
10class AuthentikEventsConfig(ManagedAppConfig): 11 """authentik events app""" 12 13 name = "authentik.events" 14 label = "authentik_events" 15 verbose_name = "authentik Events" 16 default = True 17 18 @property 19 def schedule_specs(self) -> list[ScheduleSpec]: 20 from authentik.events.tasks import notification_cleanup 21 22 return [ 23 ScheduleSpec( 24 actor=notification_cleanup, 25 crontab=f"{fqdn_rand('notification_cleanup')} */8 * * *", 26 ), 27 ] 28 29 @ManagedAppConfig.reconcile 30 def check_deprecations(self): 31 """Check for config deprecations""" 32 from authentik.events.models import Event, EventAction 33 34 for key_replace, msg in CONFIG.deprecations.items(): 35 key, replace = key_replace 36 key_env = f"{ENV_PREFIX}_{key.replace('.', '__')}".upper() 37 replace_env = f"{ENV_PREFIX}_{replace.replace('.', '__')}".upper() 38 if Event.objects.filter( 39 action=EventAction.CONFIGURATION_ERROR, context__deprecated_option=key 40 ).exists(): 41 continue 42 Event.new( 43 EventAction.CONFIGURATION_ERROR, 44 deprecated_option=key, 45 deprecated_env=key_env, 46 replacement_option=replace, 47 replacement_env=replace_env, 48 message=msg, 49 ).save() 50 51 @ManagedAppConfig.reconcile 52 def check_db_encoding(self): 53 """Check for deprecated database encoding""" 54 from django.db import connection 55 56 from authentik.events.models import Event 57 58 for message in connection.validation.check(): 59 if message.id != "ak.db.W002": 60 continue 61 Event.log_deprecation( 62 "authentik.db.encoding", f"{message.msg} {message.hint}", cause=message.msg 63 )
authentik events app
name =
'authentik.events'
schedule_specs: list[authentik.tasks.schedules.common.ScheduleSpec]
18 @property 19 def schedule_specs(self) -> list[ScheduleSpec]: 20 from authentik.events.tasks import notification_cleanup 21 22 return [ 23 ScheduleSpec( 24 actor=notification_cleanup, 25 crontab=f"{fqdn_rand('notification_cleanup')} */8 * * *", 26 ), 27 ]
Get a list of schedule specs that must exist
@ManagedAppConfig.reconcile
def
check_deprecations(self):
29 @ManagedAppConfig.reconcile 30 def check_deprecations(self): 31 """Check for config deprecations""" 32 from authentik.events.models import Event, EventAction 33 34 for key_replace, msg in CONFIG.deprecations.items(): 35 key, replace = key_replace 36 key_env = f"{ENV_PREFIX}_{key.replace('.', '__')}".upper() 37 replace_env = f"{ENV_PREFIX}_{replace.replace('.', '__')}".upper() 38 if Event.objects.filter( 39 action=EventAction.CONFIGURATION_ERROR, context__deprecated_option=key 40 ).exists(): 41 continue 42 Event.new( 43 EventAction.CONFIGURATION_ERROR, 44 deprecated_option=key, 45 deprecated_env=key_env, 46 replacement_option=replace, 47 replacement_env=replace_env, 48 message=msg, 49 ).save()
Check for config deprecations
@ManagedAppConfig.reconcile
def
check_db_encoding(self):
51 @ManagedAppConfig.reconcile 52 def check_db_encoding(self): 53 """Check for deprecated database encoding""" 54 from django.db import connection 55 56 from authentik.events.models import Event 57 58 for message in connection.validation.check(): 59 if message.id != "ak.db.W002": 60 continue 61 Event.log_deprecation( 62 "authentik.db.encoding", f"{message.msg} {message.hint}", cause=message.msg 63 )
Check for deprecated database encoding