-
Notifications
You must be signed in to change notification settings - Fork 965
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
128 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
from rest_framework import serializers | ||
|
||
from apps.proxy.models import ProxyNode | ||
|
||
|
||
class ProxyNodeSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = ProxyNode | ||
fields = "__all__" | ||
|
||
multi_user_port = serializers.SerializerMethodField() | ||
|
||
def get_multi_user_port(self, node: ProxyNode): | ||
return node.get_user_port() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
from django.urls import path | ||
from rest_framework import routers | ||
|
||
from . import views | ||
from apps.openapi import views | ||
|
||
app_name = "openapi" | ||
urlpatterns = [ | ||
path("proxy_nodes/search/", views.ProxyNodeSearchView.as_view()), | ||
path("proxy_nodes/<int:node_id>/", views.ProxyNodeDetailView.as_view()), | ||
] | ||
|
||
router = routers.DefaultRouter() | ||
router.register(r"proxy_nodes", views.ProxyNodeViewSet, basename="proxy_nodes") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,19 @@ | ||
from functools import wraps | ||
|
||
from django.http import JsonResponse | ||
from rest_framework import authentication, exceptions | ||
|
||
from apps.openapi.models import UserOpenAPIKey | ||
|
||
|
||
def gen_common_error_response(msg: str, status=400) -> JsonResponse: | ||
return JsonResponse({"error_msg": msg}, status=status) | ||
|
||
|
||
def openapi_authorized(view_func): | ||
@wraps(view_func) | ||
def wrapper(request, *args, **kwargs): | ||
class OpenAPIAuthentication(authentication.TokenAuthentication): | ||
def authenticate(self, request): | ||
key = request.META.get("HTTP_X_API_KEY", "") | ||
if not key: | ||
return gen_common_error_response( | ||
"x-api-key in header not found", status=401 | ||
) | ||
raise exceptions.NotAuthenticated("api key is required") | ||
user_key = UserOpenAPIKey.get_by_key(key) | ||
if not user_key: | ||
return gen_common_error_response("x-api-key is invalid", status=401) | ||
request.user = user_key.user | ||
return view_func(request, *args, **kwargs) | ||
raise exceptions.AuthenticationFailed("api key is wrong", code=401) | ||
return (user_key.user, None) | ||
|
||
|
||
return wrapper | ||
def gen_common_error_response(msg: str, status=400) -> JsonResponse: | ||
return JsonResponse({"error_msg": msg}, status=status) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters