admin: migrate WorkerViewSet to APIView

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-05-16 18:06:46 +02:00
parent a7d7b46747
commit ab07113530
3 changed files with 26 additions and 39 deletions

View File

@ -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))}
)

View File

@ -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/<slug:flow_slug>/",

View File

@ -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