admin: add API to get all installed apps

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-04-02 16:03:16 +02:00
parent 66d342880c
commit 5a6b6c369e
3 changed files with 66 additions and 0 deletions

View File

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

View File

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

View File

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