outposts: remove unused views

This commit is contained in:
Jens Langhammer 2020-12-13 20:51:17 +01:00
parent 9e4f840d2d
commit 426cb33fab
6 changed files with 9 additions and 105 deletions

View File

@ -1,5 +1,10 @@
all: lint-fix lint coverage gen all: lint-fix lint coverage gen
test-full:
coverage run manage.py test --failfast -v 3 .
coverage html
coverage report
test-integration: test-integration:
k3d cluster create || exit 0 k3d cluster create || exit 0
k3d kubeconfig write -o ~/.kube/config --overwrite k3d kubeconfig write -o ~/.kube/config --overwrite

View File

@ -1,11 +1,11 @@
"""test admin api""" """test admin api"""
from json import loads from json import loads
from django.shortcuts import reverse
from authentik import __version__ from django.shortcuts import reverse
from django.test import TestCase 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): class TestAdminAPI(TestCase):

View File

@ -22,7 +22,6 @@ class AuthentikOutpostConfig(AppConfig):
name = "authentik.outposts" name = "authentik.outposts"
label = "authentik_outposts" label = "authentik_outposts"
mountpoint = "outposts/"
verbose_name = "authentik Outpost" verbose_name = "authentik Outpost"
def ready(self): def ready(self):

View File

@ -1,11 +0,0 @@
"""authentik outposts urls"""
from django.urls import path
from authentik.outposts.views import KubernetesManifestView, SetupView
urlpatterns = [
path(
"<uuid:outpost_pk>/k8s/", KubernetesManifestView.as_view(), name="k8s-manifest"
),
path("<uuid:outpost_pk>/", SetupView.as_view(), name="setup"),
]

View File

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

View File

@ -87,7 +87,7 @@ class TestUserWriteStage(TestCase):
"username": "test-user-new", "username": "test-user-new",
"password": new_password, "password": new_password,
"attribute_some-custom-attribute": "test", "attribute_some-custom-attribute": "test",
"some_ignored_attribute": "bar" "some_ignored_attribute": "bar",
} }
session = self.client.session session = self.client.session
session[SESSION_KEY_PLAN] = plan session[SESSION_KEY_PLAN] = plan