diff --git a/authentik/api/v2/urls.py b/authentik/api/v2/urls.py index aaa1355c6..87c13e86a 100644 --- a/authentik/api/v2/urls.py +++ b/authentik/api/v2/urls.py @@ -23,23 +23,14 @@ from authentik.events.api.event import EventViewSet from authentik.events.api.notification import NotificationViewSet from authentik.events.api.notification_rule import NotificationRuleViewSet from authentik.events.api.notification_transport import NotificationTransportViewSet -from authentik.flows.api import ( - FlowCacheViewSet, - FlowStageBindingViewSet, - FlowViewSet, - StageViewSet, -) +from authentik.flows.api import FlowStageBindingViewSet, FlowViewSet, StageViewSet from authentik.outposts.api.outpost_service_connections import ( DockerServiceConnectionViewSet, KubernetesServiceConnectionViewSet, ServiceConnectionViewSet, ) from authentik.outposts.api.outposts import OutpostViewSet -from authentik.policies.api import ( - PolicyBindingViewSet, - PolicyCacheViewSet, - PolicyViewSet, -) +from authentik.policies.api import PolicyBindingViewSet, PolicyViewSet from authentik.policies.dummy.api import DummyPolicyViewSet from authentik.policies.event_matcher.api import EventMatcherPolicyViewSet from authentik.policies.expiry.api import PasswordExpiryPolicyViewSet @@ -100,7 +91,6 @@ router.register( router.register("outposts/proxy", ProxyOutpostConfigViewSet) router.register("flows/instances", FlowViewSet) -router.register("flows/cached", FlowCacheViewSet, basename="flows_cache") router.register("flows/bindings", FlowStageBindingViewSet) router.register("crypto/certificatekeypairs", CertificateKeyPairViewSet) @@ -116,7 +106,6 @@ router.register("sources/saml", SAMLSourceViewSet) router.register("sources/oauth", OAuthSourceViewSet) router.register("policies/all", PolicyViewSet) -router.register("policies/cached", PolicyCacheViewSet, basename="policies_cache") router.register("policies/bindings", PolicyBindingViewSet) router.register("policies/expression", ExpressionPolicyViewSet) router.register("policies/event_matcher", EventMatcherPolicyViewSet) diff --git a/authentik/core/api/utils.py b/authentik/core/api/utils.py index be583bdcc..b93f75155 100644 --- a/authentik/core/api/utils.py +++ b/authentik/core/api/utils.py @@ -1,6 +1,6 @@ """API Utilities""" from django.db.models import Model -from rest_framework.fields import CharField +from rest_framework.fields import CharField, IntegerField from rest_framework.serializers import Serializer, SerializerMethodField @@ -37,3 +37,15 @@ class TypeCreateSerializer(Serializer): def update(self, instance: Model, validated_data: dict) -> Model: raise NotImplementedError + + +class CacheSerializer(Serializer): + """Generic cache stats for an object""" + + count = IntegerField(read_only=True) + + def create(self, validated_data: dict) -> Model: + raise NotImplementedError + + def update(self, instance: Model, validated_data: dict) -> Model: + raise NotImplementedError diff --git a/authentik/flows/api.py b/authentik/flows/api.py index dc66c5414..03b84ad69 100644 --- a/authentik/flows/api.py +++ b/authentik/flows/api.py @@ -18,7 +18,11 @@ from rest_framework.serializers import ( ) from rest_framework.viewsets import GenericViewSet, ModelViewSet, ReadOnlyModelViewSet -from authentik.core.api.utils import MetaNameSerializer, TypeCreateSerializer +from authentik.core.api.utils import ( + CacheSerializer, + MetaNameSerializer, + TypeCreateSerializer, +) from authentik.flows.models import Flow, FlowStageBinding, Stage from authentik.flows.planner import cache_key from authentik.lib.templatetags.authentik_utils import verbose_name @@ -84,6 +88,12 @@ class FlowViewSet(ModelViewSet): search_fields = ["name", "slug", "designation", "title"] filterset_fields = ["flow_uuid", "name", "slug", "designation"] + @swagger_auto_schema(responses={200: CacheSerializer(many=False)}) + @action(detail=False) + def cached(self, request: Request) -> Response: + """Info about cached flows""" + return Response(data={"count": len(cache.keys("flow_*"))}) + @swagger_auto_schema(responses={200: FlowDiagramSerializer()}) @action(detail=True, methods=["get"]) def diagram(self, request: Request, slug: str) -> Response: @@ -226,14 +236,3 @@ class FlowStageBindingViewSet(ModelViewSet): queryset = FlowStageBinding.objects.all() serializer_class = FlowStageBindingSerializer filterset_fields = "__all__" - - -class FlowCacheViewSet(ListModelMixin, GenericViewSet): - """Info about cached flows""" - - queryset = Flow.objects.none() - serializer_class = Serializer - - def list(self, request: Request) -> Response: - """Info about cached flows""" - return Response(data={"pagination": {"count": len(cache.keys("flow_*"))}})