From 426cb33fab7be19d543332220221094b62fe3f41 Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Sun, 13 Dec 2020 20:51:17 +0100 Subject: [PATCH] outposts: remove unused views --- Makefile | 5 ++ authentik/admin/tests/test_api.py | 6 +- authentik/outposts/apps.py | 1 - authentik/outposts/urls.py | 11 ---- authentik/outposts/views.py | 89 ---------------------------- authentik/stages/user_write/tests.py | 2 +- 6 files changed, 9 insertions(+), 105 deletions(-) delete mode 100644 authentik/outposts/urls.py delete mode 100644 authentik/outposts/views.py diff --git a/Makefile b/Makefile index 0d5abc4a5..47eed18b7 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,10 @@ all: lint-fix lint coverage gen +test-full: + coverage run manage.py test --failfast -v 3 . + coverage html + coverage report + test-integration: k3d cluster create || exit 0 k3d kubeconfig write -o ~/.kube/config --overwrite diff --git a/authentik/admin/tests/test_api.py b/authentik/admin/tests/test_api.py index 91891f528..ae0f0ab68 100644 --- a/authentik/admin/tests/test_api.py +++ b/authentik/admin/tests/test_api.py @@ -1,11 +1,11 @@ """test admin api""" from json import loads -from django.shortcuts import reverse -from authentik import __version__ +from django.shortcuts import reverse from django.test import TestCase -from authentik.core.models import User, Group +from authentik import __version__ +from authentik.core.models import Group, User class TestAdminAPI(TestCase): diff --git a/authentik/outposts/apps.py b/authentik/outposts/apps.py index 982955693..ad51ce07b 100644 --- a/authentik/outposts/apps.py +++ b/authentik/outposts/apps.py @@ -22,7 +22,6 @@ class AuthentikOutpostConfig(AppConfig): name = "authentik.outposts" label = "authentik_outposts" - mountpoint = "outposts/" verbose_name = "authentik Outpost" def ready(self): diff --git a/authentik/outposts/urls.py b/authentik/outposts/urls.py deleted file mode 100644 index f6830ee50..000000000 --- a/authentik/outposts/urls.py +++ /dev/null @@ -1,11 +0,0 @@ -"""authentik outposts urls""" -from django.urls import path - -from authentik.outposts.views import KubernetesManifestView, SetupView - -urlpatterns = [ - path( - "/k8s/", KubernetesManifestView.as_view(), name="k8s-manifest" - ), - path("/", SetupView.as_view(), name="setup"), -] diff --git a/authentik/outposts/views.py b/authentik/outposts/views.py deleted file mode 100644 index f86062530..000000000 --- a/authentik/outposts/views.py +++ /dev/null @@ -1,89 +0,0 @@ -"""authentik outpost views""" -from typing import Any, Dict, List - -from django.contrib.auth.mixins import LoginRequiredMixin -from django.db.models import Model -from django.http import HttpRequest, HttpResponse -from django.shortcuts import get_object_or_404 -from django.views import View -from django.views.generic import TemplateView -from guardian.shortcuts import get_objects_for_user -from structlog import get_logger - -from authentik.core.models import User -from authentik.outposts.controllers.docker import DockerController -from authentik.outposts.models import ( - DockerServiceConnection, - KubernetesServiceConnection, - Outpost, - OutpostType, -) -from authentik.providers.proxy.controllers.kubernetes import ProxyKubernetesController - -LOGGER = get_logger() - - -def get_object_for_user_or_404(user: User, perm: str, **filters) -> Model: - """Wrapper that combines get_objects_for_user and get_object_or_404""" - return get_object_or_404(get_objects_for_user(user, perm), **filters) - - -class DockerComposeView(LoginRequiredMixin, View): - """Generate docker-compose yaml""" - - def get(self, request: HttpRequest, outpost_pk: str) -> HttpResponse: - """Render docker-compose file""" - outpost: Outpost = get_object_for_user_or_404( - request.user, - "authentik_outposts.view_outpost", - pk=outpost_pk, - ) - manifest = "" - if outpost.type == OutpostType.PROXY: - controller = DockerController(outpost, DockerServiceConnection()) - manifest = controller.get_static_deployment() - - return HttpResponse(manifest, content_type="text/vnd.yaml") - - -class KubernetesManifestView(LoginRequiredMixin, View): - """Generate Kubernetes Deployment and SVC for proxy""" - - def get(self, request: HttpRequest, outpost_pk: str) -> HttpResponse: - """Render deployment template""" - outpost: Outpost = get_object_for_user_or_404( - request.user, - "authentik_outposts.view_outpost", - pk=outpost_pk, - ) - manifest = "" - if outpost.type == OutpostType.PROXY: - controller = ProxyKubernetesController( - outpost, KubernetesServiceConnection() - ) - manifest = controller.get_static_deployment() - - return HttpResponse(manifest, content_type="text/vnd.yaml") - - -class SetupView(LoginRequiredMixin, TemplateView): - """Setup view""" - - def get_template_names(self) -> List[str]: - allowed = ["dc", "custom", "k8s_manual", "k8s_integration"] - setup_type = self.request.GET.get("type", "dc") - if setup_type not in allowed: - setup_type = allowed[0] - return [f"outposts/setup_{setup_type}.html"] - - def get_context_data(self, **kwargs: Any) -> Dict[str, Any]: - kwargs = super().get_context_data(**kwargs) - outpost: Outpost = get_object_for_user_or_404( - self.request.user, - "authentik_outposts.view_outpost", - pk=self.kwargs["outpost_pk"], - ) - kwargs.update( - {"host": self.request.build_absolute_uri("/"), "outpost": outpost} - ) - return kwargs diff --git a/authentik/stages/user_write/tests.py b/authentik/stages/user_write/tests.py index 65eb01b9a..214c693c7 100644 --- a/authentik/stages/user_write/tests.py +++ b/authentik/stages/user_write/tests.py @@ -87,7 +87,7 @@ class TestUserWriteStage(TestCase): "username": "test-user-new", "password": new_password, "attribute_some-custom-attribute": "test", - "some_ignored_attribute": "bar" + "some_ignored_attribute": "bar", } session = self.client.session session[SESSION_KEY_PLAN] = plan