Commit bc67b379 authored by John Red Medrano's avatar John Red Medrano

Merge pull request #25 in RMS/api-main-service from red-develop to dev

* commit '4ac6ad22':
  remove unused codes
parents 3136232e 4ac6ad22
from api.viewsets.applications import ApplicationViewSet, GroupDependentViewSet from django.urls import path, include
from rest_framework.routers import DefaultRouter
from api.viewsets.services import APIServiceViewSet from api.viewsets.services import APIServiceViewSet
from api.viewsets.endpoints import APIEndpointViewSet from api.viewsets.endpoints import APIEndpointViewSet
from django.urls import path, include from api.viewsets.applications import ApplicationViewSet, GroupDependentViewSet
from rest_framework.routers import DefaultRouter, SimpleRouter
from api.views import ( from api.views import (
APIGatewayList, APIGatewaySlugDetail, APIGatewaySlugModelDetail APIGatewayList, APIGatewaySlugDetail, APIGatewaySlugModelDetail
) )
......
...@@ -9,6 +9,7 @@ from .models import APIEndpoint ...@@ -9,6 +9,7 @@ from .models import APIEndpoint
from rest_framework.pagination import PageNumberPagination from rest_framework.pagination import PageNumberPagination
from rest_framework.response import Response from rest_framework.response import Response
import datetime import datetime
from functools import wraps
VALIDATE_TOKEN_URL = settings.VALIDATE_TOKEN_URL VALIDATE_TOKEN_URL = settings.VALIDATE_TOKEN_URL
...@@ -90,18 +91,22 @@ class Helper: ...@@ -90,18 +91,22 @@ class Helper:
service__name=service, service__name=service,
endpoint_url=endpoint_url, endpoint_url=endpoint_url,
) )
if endpoint.is_active is True: if endpoint.is_active is True:
base_url = endpoint.service.base_url base_url = endpoint.service.base_url
full_path = request.get_full_path() full_path = request.get_full_path()
final_endpoint = f"{base_url}{full_path}" final_endpoint = f"{base_url}{full_path}"
if endpoint.is_need_auth is True: if endpoint.is_need_auth is True:
# redirect to authenticator service # redirect to authenticator service
self._headers = { self._headers = {
'Authorization': request.META['HTTP_AUTHORIZATION'], 'Authorization': request.META['HTTP_AUTHORIZATION'],
"endpoint": endpoint.endpoint_url 'Content-Type': 'application/json',
"endpoint": str(endpoint.id)
} }
req = requests.post(VALIDATE_TOKEN_URL, req = requests.post(VALIDATE_TOKEN_URL,
headers=self._headers) headers=self._headers)
print(req)
all_headers = {**req.headers, **self._headers} all_headers = {**req.headers, **self._headers}
if req.status_code == 200: if req.status_code == 200:
...@@ -156,7 +161,6 @@ def number_generator(prefix, id): ...@@ -156,7 +161,6 @@ def number_generator(prefix, id):
# status message # status message
def status_message_response(code, status, message, results): def status_message_response(code, status, message, results):
print('ddd')
message = { message = {
'code': code, 'code': code,
'status': status, 'status': status,
......
from rest_framework import viewsets, status
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework.decorators import action
from rest_framework.response import Response from rest_framework.response import Response
from django_filters.rest_framework import DjangoFilterBackend from .utils import Helper
from .models import APIService, APIEndpoint, Application
from .utils import (APIEndpointFilter, Helper)
class APIGatewayList(APIView): class APIGatewayList(APIView):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment