outposts: fix error when validating kubeconfig

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2021-06-02 10:25:59 +02:00
parent 05d45383be
commit 644ff4a90c
1 changed files with 3 additions and 7 deletions

View File

@ -8,7 +8,7 @@ from kubernetes.config.config_exception import ConfigException
from kubernetes.config.kube_config import load_kube_config_from_dict from kubernetes.config.kube_config import load_kube_config_from_dict
from rest_framework import mixins, serializers from rest_framework import mixins, serializers
from rest_framework.decorators import action from rest_framework.decorators import action
from rest_framework.fields import BooleanField, CharField, SerializerMethodField from rest_framework.fields import BooleanField, CharField, ReadOnlyField
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.serializers import ModelSerializer from rest_framework.serializers import ModelSerializer
@ -30,11 +30,7 @@ from authentik.outposts.models import (
class ServiceConnectionSerializer(ModelSerializer, MetaNameSerializer): class ServiceConnectionSerializer(ModelSerializer, MetaNameSerializer):
"""ServiceConnection Serializer""" """ServiceConnection Serializer"""
component = SerializerMethodField() component = ReadOnlyField()
def get_component(self, obj: OutpostServiceConnection) -> str:
"""Get object component so that we know how to edit the object"""
return obj.component
class Meta: class Meta:
@ -122,7 +118,7 @@ class KubernetesServiceConnectionSerializer(ServiceConnectionSerializer):
def validate_kubeconfig(self, kubeconfig): def validate_kubeconfig(self, kubeconfig):
"""Validate kubeconfig by attempting to load it""" """Validate kubeconfig by attempting to load it"""
if kubeconfig == {}: if kubeconfig == {}:
if not self.validated_data["local"]: if not self.initial_data["local"]:
raise serializers.ValidationError( raise serializers.ValidationError(
_( _(
"You can only use an empty kubeconfig when connecting to a local cluster." "You can only use an empty kubeconfig when connecting to a local cluster."