From 3294e70b3f6167db5ae939d7591dd892ff21ff24 Mon Sep 17 00:00:00 2001 From: "pierre.geeraert" Date: Tue, 22 Sep 2026 10:01:09 +0100 Subject: [PATCH] add rest framework authentication --- django_code/apps/cloudmanager/views.py | 11 +++++++++-- .../apps/import_aggregator/import_rest_framework.py | 6 ++++++ django_code/core/settings.py | 3 +++ requirements.txt | 1 + 4 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 django_code/apps/import_aggregator/import_rest_framework.py diff --git a/django_code/apps/cloudmanager/views.py b/django_code/apps/cloudmanager/views.py index 3c1d218..3679bc2 100644 --- a/django_code/apps/cloudmanager/views.py +++ b/django_code/apps/cloudmanager/views.py @@ -5,6 +5,8 @@ from django.utils import timezone from django.views.decorators.csrf import csrf_exempt from django.http import JsonResponse +from apps.import_aggregator.import_rest_framework import api_view, authentication_classes, permission_classes,TokenAuthentication,IsAuthenticated,Response,status + from .utils import import_namespace,retrieve_and_apply from apps.kubernetes_connection.utils import scale_up,scale_down from .models import Deployment_Data,Ingress_Data @@ -35,7 +37,10 @@ def scale_down_gui(request,namespace_name,deploy_name): return render(request, 'dashboard/shutdown.html', {'namespace': namespace_name, 'deployment': deploy_name, 'url': 'https://namespace.com'}) -@csrf_exempt + +@api_view(['POST']) +@authentication_classes([TokenAuthentication]) +@permission_classes([IsAuthenticated]) def add_ingress(request): url = request.POST.get('url') namespace = request.POST.get('namespace') @@ -49,7 +54,9 @@ def add_ingress(request): return JsonResponse({"status": "added","url":str(url),"namespace":str(namespace)}) -@csrf_exempt +@api_view(['POST']) +@authentication_classes([TokenAuthentication]) +@permission_classes([IsAuthenticated]) def delete_ingress(request): url = request.POST.get('url') namespace = request.POST.get('namespace') diff --git a/django_code/apps/import_aggregator/import_rest_framework.py b/django_code/apps/import_aggregator/import_rest_framework.py new file mode 100644 index 0000000..07a7e31 --- /dev/null +++ b/django_code/apps/import_aggregator/import_rest_framework.py @@ -0,0 +1,6 @@ +from rest_framework.decorators import api_view, authentication_classes, permission_classes +from rest_framework.authentication import TokenAuthentication +from rest_framework.permissions import IsAuthenticated +from rest_framework.response import Response +from rest_framework import status + diff --git a/django_code/core/settings.py b/django_code/core/settings.py index 2759104..e7f1410 100644 --- a/django_code/core/settings.py +++ b/django_code/core/settings.py @@ -54,6 +54,9 @@ INSTALLED_APPS = [ 'import_export', 'djangoql', 'admin_extra_buttons', + 'rest_framework', + 'rest_framework.authtoken', + ] MIDDLEWARE = [ diff --git a/requirements.txt b/requirements.txt index e10497c..15881fa 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,3 +17,4 @@ xmltodict whitenoise djangoql django-admin-extra-buttons +djangorestframework