admin: migrate metrics viewset to APIView
Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
parent
b351ae12c5
commit
9a44088d2b
|
@ -12,7 +12,7 @@ from rest_framework.fields import IntegerField, SerializerMethodField
|
|||
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 rest_framework.views import APIView
|
||||
|
||||
from authentik.core.api.utils import PassiveSerializer
|
||||
from authentik.events.models import Event, EventAction
|
||||
|
@ -69,13 +69,13 @@ class LoginMetricsSerializer(PassiveSerializer):
|
|||
return get_events_per_1h(action=EventAction.LOGIN_FAILED)
|
||||
|
||||
|
||||
class AdministrationMetricsViewSet(ViewSet):
|
||||
class AdministrationMetricsViewSet(APIView):
|
||||
"""Login Metrics per 1h"""
|
||||
|
||||
permission_classes = [IsAdminUser]
|
||||
|
||||
@extend_schema(responses={200: LoginMetricsSerializer(many=False)})
|
||||
def list(self, request: Request) -> Response:
|
||||
def get(self, request: Request) -> Response:
|
||||
"""Login Metrics per 1h"""
|
||||
serializer = LoginMetricsSerializer(True)
|
||||
return Response(serializer.data)
|
||||
|
|
|
@ -100,7 +100,6 @@ router = routers.DefaultRouter()
|
|||
|
||||
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")
|
||||
|
||||
|
@ -198,6 +197,7 @@ urlpatterns = (
|
|||
]
|
||||
+ router.urls
|
||||
+ [
|
||||
path("admin/metrics/", AdministrationMetricsViewSet.as_view(), name="admin_metrics"),
|
||||
path("root/config/", ConfigView.as_view(), name="config"),
|
||||
path(
|
||||
"flows/executor/<slug:flow_slug>/",
|
||||
|
|
|
@ -29,7 +29,7 @@ paths:
|
|||
description: ''
|
||||
/api/v2beta/admin/metrics/:
|
||||
get:
|
||||
operationId: admin_metrics_list
|
||||
operationId: admin_metrics_retrieve
|
||||
description: Login Metrics per 1h
|
||||
tags:
|
||||
- admin
|
||||
|
@ -41,9 +41,7 @@ paths:
|
|||
content:
|
||||
application/json:
|
||||
schema:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/LoginMetrics'
|
||||
$ref: '#/components/schemas/LoginMetrics'
|
||||
description: ''
|
||||
/api/v2beta/admin/system_tasks/:
|
||||
get:
|
||||
|
|
|
@ -15,7 +15,7 @@ export class LoggingMiddleware implements Middleware {
|
|||
let globalConfigPromise: Promise<Config>;
|
||||
export function config(): Promise<Config> {
|
||||
if (!globalConfigPromise) {
|
||||
globalConfigPromise = new RootApi(DEFAULT_CONFIG).rootConfigList();
|
||||
globalConfigPromise = new RootApi(DEFAULT_CONFIG).rootConfigRetrieve();
|
||||
}
|
||||
return globalConfigPromise;
|
||||
}
|
||||
|
|
|
@ -4,9 +4,14 @@ import { DEFAULT_CONFIG } from "./Config";
|
|||
let globalMePromise: Promise<SessionUser>;
|
||||
export function me(): Promise<SessionUser> {
|
||||
if (!globalMePromise) {
|
||||
globalMePromise = new CoreApi(DEFAULT_CONFIG).coreUsersMe().catch((ex) => {
|
||||
globalMePromise = new CoreApi(DEFAULT_CONFIG).coreUsersMeRetrieve().catch((ex) => {
|
||||
const defaultUser: SessionUser = {
|
||||
user: {
|
||||
pk: -1,
|
||||
isSuperuser: false,
|
||||
groups: [],
|
||||
avatar: "",
|
||||
uid: "",
|
||||
username: "",
|
||||
name: ""
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@ export class TokenCopyButton extends ActionButton {
|
|||
if (!this.identifier) {
|
||||
return Promise.reject();
|
||||
}
|
||||
return new CoreApi(DEFAULT_CONFIG).coreTokensViewKey({
|
||||
return new CoreApi(DEFAULT_CONFIG).coreTokensViewKeyRetrieve({
|
||||
identifier: this.identifier
|
||||
}).then((token) => {
|
||||
if (!token.key) {
|
||||
|
|
|
@ -8,7 +8,7 @@ import { DEFAULT_CONFIG } from "../../api/Config";
|
|||
export class AdminLoginsChart extends AKChart<LoginMetrics> {
|
||||
|
||||
apiRequest(): Promise<LoginMetrics> {
|
||||
return new AdminApi(DEFAULT_CONFIG).adminMetricsList();
|
||||
return new AdminApi(DEFAULT_CONFIG).adminMetricsRetrieve();
|
||||
}
|
||||
|
||||
getChartData(data: LoginMetrics): ChartData {
|
||||
|
|
Reference in New Issue