From 5a6b6c369ece4d0d77b1e395259468dde4fb2c2a Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Fri, 2 Apr 2021 16:03:16 +0200 Subject: [PATCH] admin: add API to get all installed apps Signed-off-by: Jens Langhammer --- authentik/admin/api/meta.py | 31 +++++++++++++++++++++++++++++++ authentik/api/v2/urls.py | 2 ++ swagger.yaml | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+) create mode 100644 authentik/admin/api/meta.py diff --git a/authentik/admin/api/meta.py b/authentik/admin/api/meta.py new file mode 100644 index 000000000..5b89ab898 --- /dev/null +++ b/authentik/admin/api/meta.py @@ -0,0 +1,31 @@ +"""Meta API""" +from drf_yasg.utils import swagger_auto_schema +from rest_framework.fields import CharField +from rest_framework.permissions import IsAdminUser +from rest_framework.request import Request +from rest_framework.response import Response +from rest_framework.viewsets import ViewSet + +from authentik.core.api.utils import PassiveSerializer +from authentik.lib.utils.reflection import get_apps + + +class AppSerializer(PassiveSerializer): + """Serialize Application info""" + + name = CharField() + label = CharField() + + +class AppsViewSet(ViewSet): + """Read-only view set list all installed apps""" + + permission_classes = [IsAdminUser] + + @swagger_auto_schema(responses={200: AppSerializer(many=True)}) + def list(self, request: Request) -> Response: + """List current messages and pass into Serializer""" + data = [] + for app in get_apps(): + data.append({"name": app.name, "label": app.verbose_name}) + return Response(AppSerializer(data, many=True).data) diff --git a/authentik/api/v2/urls.py b/authentik/api/v2/urls.py index 9ee25b019..dce5ee9e6 100644 --- a/authentik/api/v2/urls.py +++ b/authentik/api/v2/urls.py @@ -5,6 +5,7 @@ from drf_yasg.views import get_schema_view from rest_framework import routers from rest_framework.permissions import AllowAny +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 VersionViewSet @@ -103,6 +104,7 @@ router.register("admin/version", VersionViewSet, basename="admin_version") router.register("admin/workers", WorkerViewSet, basename="admin_workers") router.register("admin/metrics", AdministrationMetricsViewSet, basename="admin_metrics") router.register("admin/system_tasks", TaskViewSet, basename="admin_system_tasks") +router.register("admin/apps", AppsViewSet, basename="apps") router.register("core/applications", ApplicationViewSet) router.register("core/groups", GroupViewSet) diff --git a/swagger.yaml b/swagger.yaml index df4f6e513..99576ee87 100755 --- a/swagger.yaml +++ b/swagger.yaml @@ -20,6 +20,25 @@ securityDefinitions: security: - token: [] paths: + /admin/apps/: + get: + operationId: admin_apps_list + description: List current messages and pass into Serializer + parameters: [] + responses: + '200': + description: '' + schema: + type: array + items: + $ref: '#/definitions/App' + '403': + description: Authentication credentials were invalid, absent or insufficient. + schema: + $ref: '#/definitions/GenericError' + tags: + - admin + parameters: [] /admin/metrics/: get: operationId: admin_metrics_list @@ -14206,6 +14225,20 @@ definitions: code: description: Error code type: string + App: + required: + - name + - label + type: object + properties: + name: + title: Name + type: string + minLength: 1 + label: + title: Label + type: string + minLength: 1 Coordinate: type: object properties: