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