mirror of
https://github.com/goauthentik/authentik.git
synced 2026-08-30 18:51:39 -07:00
crypto: don't dispatch discovery if one is queued (#25483)
* cryto: don't dispatch discovery if one is queued * Update tasks.py Co-authored-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> Signed-off-by: Jens L. <jens@beryju.org> * lint Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space> --------- Signed-off-by: Jens L. <jens@beryju.org> 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:
@@ -9,6 +9,7 @@ from cryptography.hazmat.primitives.serialization import load_pem_private_key
|
||||
from cryptography.x509.base import load_pem_x509_certificate
|
||||
from django.conf import settings
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django_dramatiq_postgres.models import TaskState
|
||||
from dramatiq.actor import actor
|
||||
from dramatiq.middleware import Middleware
|
||||
from structlog.stdlib import get_logger
|
||||
@@ -23,6 +24,7 @@ from watchdog.observers import Observer
|
||||
from authentik.crypto.models import CertificateKeyPair
|
||||
from authentik.lib.config import CONFIG
|
||||
from authentik.tasks.middleware import CurrentTask
|
||||
from authentik.tasks.models import Task
|
||||
from authentik.tasks.schedules.models import Schedule
|
||||
from authentik.tenants.models import Tenant
|
||||
|
||||
@@ -85,15 +87,24 @@ class CertificateEventHandler(FileSystemEventHandler):
|
||||
return None
|
||||
return super().dispatch(event)
|
||||
|
||||
def run_tasks(self):
|
||||
for tenant in Tenant.objects.filter(ready=True):
|
||||
with tenant:
|
||||
if Task.objects.filter(
|
||||
tenant=tenant,
|
||||
actor_name=certificate_discovery.actor_name,
|
||||
state=TaskState.QUEUED,
|
||||
).exists():
|
||||
continue
|
||||
Schedule.dispatch_by_actor(certificate_discovery)
|
||||
|
||||
def on_created(self, event: FileSystemEvent):
|
||||
"""Process certificate file creation"""
|
||||
LOGGER.debug(
|
||||
"Certificate file created, triggering discovery",
|
||||
file=event.src_path,
|
||||
)
|
||||
for tenant in Tenant.objects.filter(ready=True):
|
||||
with tenant:
|
||||
Schedule.dispatch_by_actor(certificate_discovery)
|
||||
self.run_tasks()
|
||||
|
||||
def on_modified(self, event: FileSystemEvent):
|
||||
"""Process certificate file modification"""
|
||||
@@ -101,9 +112,7 @@ class CertificateEventHandler(FileSystemEventHandler):
|
||||
"Certificate file modified, triggering discovery",
|
||||
file=event.src_path,
|
||||
)
|
||||
for tenant in Tenant.objects.filter(ready=True):
|
||||
with tenant:
|
||||
Schedule.dispatch_by_actor(certificate_discovery)
|
||||
self.run_tasks()
|
||||
|
||||
|
||||
@actor(description=_("Discover, import and update certificates from the filesystem."))
|
||||
|
||||
Reference in New Issue
Block a user