From ab07113530cb6f59ff7a0fc023bfc6b841071fd2 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 16 May 2021 18:06:46 +0200 Subject: [PATCH] admin: migrate WorkerViewSet to APIView Signed-off-by: Jens Langhammer --- authentik/admin/api/workers.py | 21 +++++++++--------- authentik/api/v2/urls.py | 4 ++-- schema.yml | 40 +++++++++++----------------------- 3 files changed, 26 insertions(+), 39 deletions(-) diff --git a/authentik/admin/api/workers.py b/authentik/admin/api/workers.py index 6b400b44d..7563b8f9a 100644 --- a/authentik/admin/api/workers.py +++ b/authentik/admin/api/workers.py @@ -1,25 +1,26 @@ """authentik administration overview""" -from rest_framework.mixins import ListModelMixin +from drf_spectacular.utils import extend_schema, inline_serializer from rest_framework.permissions import IsAdminUser from rest_framework.request import Request from rest_framework.response import Response -from rest_framework.serializers import Serializer -from rest_framework.viewsets import GenericViewSet +from rest_framework.fields import IntegerField +from rest_framework.views import APIView from authentik.root.celery import CELERY_APP -class WorkerViewSet(ListModelMixin, GenericViewSet): +class WorkerView(APIView): """Get currently connected worker count.""" - serializer_class = Serializer permission_classes = [IsAdminUser] - def get_queryset(self): # pragma: no cover - return None - - def list(self, request: Request) -> Response: + @extend_schema( + responses=inline_serializer("Workers", fields={ + "count": IntegerField() + }) + ) + def get(self, request: Request) -> Response: """Get currently connected worker count.""" return Response( - {"pagination": {"count": len(CELERY_APP.control.ping(timeout=0.5))}} + {"count": len(CELERY_APP.control.ping(timeout=0.5))} ) diff --git a/authentik/api/v2/urls.py b/authentik/api/v2/urls.py index cf8a70b29..b9a43be1e 100644 --- a/authentik/api/v2/urls.py +++ b/authentik/api/v2/urls.py @@ -7,7 +7,7 @@ from authentik.admin.api.meta import AppsViewSet from authentik.admin.api.metrics import AdministrationMetricsViewSet from authentik.admin.api.tasks import TaskViewSet from authentik.admin.api.version import VersionView -from authentik.admin.api.workers import WorkerViewSet +from authentik.admin.api.workers import WorkerView from authentik.api.v2.config import ConfigView from authentik.api.views import APIBrowserView from authentik.core.api.applications import ApplicationViewSet @@ -98,7 +98,6 @@ from authentik.stages.user_write.api import UserWriteStageViewSet router = routers.DefaultRouter() -router.register("admin/workers", WorkerViewSet, basename="admin_workers") router.register("admin/system_tasks", TaskViewSet, basename="admin_system_tasks") router.register("admin/apps", AppsViewSet, basename="apps") @@ -198,6 +197,7 @@ urlpatterns = ( + [ path("admin/metrics/", AdministrationMetricsViewSet.as_view(), name="admin_metrics"), path("admin/version/", VersionView.as_view(), name="admin_version"), + path("admin/workers/", WorkerView.as_view(), name="admin_workers"), path("root/config/", ConfigView.as_view(), name="config"), path( "flows/executor//", diff --git a/schema.yml b/schema.yml index 9432c2bd6..071ade43d 100644 --- a/schema.yml +++ b/schema.yml @@ -137,33 +137,8 @@ paths: description: '' /api/v2beta/admin/workers/: get: - operationId: admin_workers_list + operationId: admin_workers_retrieve description: Get currently connected worker count. - parameters: - - name: ordering - required: false - in: query - description: Which field to use when ordering the results. - schema: - type: string - - name: page - required: false - in: query - description: A page number within the paginated result set. - schema: - type: integer - - name: page_size - required: false - in: query - description: Number of results to return per page. - schema: - type: integer - - name: search - required: false - in: query - description: A search term. - schema: - type: string tags: - admin security: @@ -171,7 +146,11 @@ paths: - cookieAuth: [] responses: '200': - description: No response body + content: + application/json: + schema: + $ref: '#/components/schemas/Workers' + description: '' /api/v2beta/authenticators/admin/static/: get: operationId: authenticators_admin_static_list @@ -22595,6 +22574,13 @@ components: maxLength: 200 required: - name + Workers: + type: object + properties: + count: + type: integer + required: + - count securitySchemes: authentik: type: apiKey