fix api
Signed-off-by: Marc 'risson' Schmitt <marc.schmitt@risson.space>
This commit is contained in:
@ -7,11 +7,6 @@ from authentik.tasks.models import TaskStatus
|
||||
class SyncStatusSerializer(PassiveSerializer):
|
||||
"""Provider/source sync status"""
|
||||
|
||||
is_running = BooleanField(read_only=True, default=False)
|
||||
last_successful_sync = DateTimeField(read_only=True, required=False, default=None)
|
||||
last_sync_status = ChoiceField(
|
||||
read_only=True,
|
||||
required=False,
|
||||
default=None,
|
||||
choices=TaskStatus.choices,
|
||||
)
|
||||
is_running = BooleanField()
|
||||
last_successful_sync = DateTimeField(required=False)
|
||||
last_sync_status = ChoiceField(required=False, choices=TaskStatus.choices)
|
||||
|
||||
@ -52,15 +52,19 @@ class OutgoingSyncProviderStatusMixin:
|
||||
"""Get provider's sync status"""
|
||||
provider: OutgoingSyncProvider = self.get_object()
|
||||
|
||||
status = {}
|
||||
|
||||
with provider.sync_lock as lock_acquired:
|
||||
# If we could not acquire the lock, it means a task is using it, and thus is running
|
||||
status["is_running"] = not lock_acquired
|
||||
|
||||
sync_schedule = None
|
||||
for schedule in provider.schedules.all():
|
||||
if schedule.actor_name == self.sync_task.actor_name:
|
||||
sync_schedule = schedule
|
||||
|
||||
if not sync_schedule:
|
||||
return Response(SyncStatusSerializer({}).data)
|
||||
|
||||
status = {}
|
||||
return Response(SyncStatusSerializer(status).data)
|
||||
|
||||
last_task: Task = (
|
||||
sync_schedule.tasks.exclude(
|
||||
@ -80,10 +84,6 @@ class OutgoingSyncProviderStatusMixin:
|
||||
if last_successful_task:
|
||||
status["last_successful_sync"] = last_successful_task.mtime
|
||||
|
||||
with provider.sync_lock as lock_acquired:
|
||||
# If we could not acquire the lock, it means a task is using it, and thus is running
|
||||
status["is_running"] = not lock_acquired
|
||||
|
||||
return Response(SyncStatusSerializer(status).data)
|
||||
|
||||
@extend_schema(
|
||||
|
||||
@ -93,15 +93,19 @@ class KerberosSourceViewSet(UsedByMixin, ModelViewSet):
|
||||
"""Get provider's sync status"""
|
||||
source: KerberosSource = self.get_object()
|
||||
|
||||
status = {}
|
||||
|
||||
with source.sync_lock as lock_acquired:
|
||||
# If we could not acquire the lock, it means a task is using it, and thus is running
|
||||
status["is_running"] = not lock_acquired
|
||||
|
||||
sync_schedule = None
|
||||
for schedule in source.schedules.all():
|
||||
if schedule.actor_name == kerberos_sync.actor_name:
|
||||
sync_schedule = schedule
|
||||
|
||||
if not sync_schedule:
|
||||
return Response(SyncStatusSerializer({}).data)
|
||||
|
||||
status = {}
|
||||
return Response(SyncStatusSerializer(status).data)
|
||||
|
||||
last_task: Task = (
|
||||
sync_schedule.tasks.exclude(
|
||||
@ -121,8 +125,4 @@ class KerberosSourceViewSet(UsedByMixin, ModelViewSet):
|
||||
if last_successful_task:
|
||||
status["last_successful_sync"] = last_successful_task.mtime
|
||||
|
||||
with source.sync_lock as lock_acquired:
|
||||
# If we could not acquire the lock, it means a task is using it, and thus is running
|
||||
status["is_running"] = not lock_acquired
|
||||
|
||||
return Response(SyncStatusSerializer(status).data)
|
||||
|
||||
@ -168,15 +168,19 @@ class LDAPSourceViewSet(UsedByMixin, ModelViewSet):
|
||||
"""Get provider's sync status"""
|
||||
source: LDAPSource = self.get_object()
|
||||
|
||||
status = {}
|
||||
|
||||
with source.sync_lock as lock_acquired:
|
||||
# If we could not acquire the lock, it means a task is using it, and thus is running
|
||||
status["is_running"] = not lock_acquired
|
||||
|
||||
sync_schedule = None
|
||||
for schedule in source.schedules.all():
|
||||
if schedule.actor_name == ldap_sync.actor_name:
|
||||
sync_schedule = schedule
|
||||
|
||||
if not sync_schedule:
|
||||
return Response(SyncStatusSerializer({}).data)
|
||||
|
||||
status = {}
|
||||
return Response(SyncStatusSerializer(status).data)
|
||||
|
||||
last_task: Task = (
|
||||
sync_schedule.tasks.exclude(
|
||||
@ -196,10 +200,6 @@ class LDAPSourceViewSet(UsedByMixin, ModelViewSet):
|
||||
if last_successful_task:
|
||||
status["last_successful_sync"] = last_successful_task.mtime
|
||||
|
||||
with source.sync_lock as lock_acquired:
|
||||
# If we could not acquire the lock, it means a task is using it, and thus is running
|
||||
status["is_running"] = not lock_acquired
|
||||
|
||||
return Response(SyncStatusSerializer(status).data)
|
||||
|
||||
@extend_schema(
|
||||
|
||||
@ -60390,20 +60390,13 @@ components:
|
||||
properties:
|
||||
is_running:
|
||||
type: boolean
|
||||
readOnly: true
|
||||
default: false
|
||||
last_successful_sync:
|
||||
type: string
|
||||
format: date-time
|
||||
readOnly: true
|
||||
last_sync_status:
|
||||
allOf:
|
||||
- $ref: '#/components/schemas/TaskAggregatedStatusEnum'
|
||||
readOnly: true
|
||||
$ref: '#/components/schemas/TaskAggregatedStatusEnum'
|
||||
required:
|
||||
- is_running
|
||||
- last_successful_sync
|
||||
- last_sync_status
|
||||
SystemInfo:
|
||||
type: object
|
||||
description: Get system information.
|
||||
|
||||
Reference in New Issue
Block a user