-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed event loop closed error, removed file download endpoint, implem…
…ented nginx subrequest support
- Loading branch information
1 parent
f21cbce
commit 9520908
Showing
15 changed files
with
106 additions
and
132 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
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 was deleted.
Oops, something went wrong.
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
""" | ||
Authentication package init. | ||
""" |
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,16 @@ | ||
""" | ||
Authentication app config. | ||
This file defines the authentication app configuration. For more information see | ||
https://docs.djangoproject.com/en/3.0/ref/applications/#configuring-applications | ||
""" | ||
from django.apps import AppConfig | ||
|
||
|
||
class AuthenticationAppConfig(AppConfig): | ||
""" | ||
Authentication app config. | ||
""" | ||
|
||
name = "src.authentication" | ||
verbose_name = "Authentication" |
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,11 @@ | ||
""" | ||
Authentication urls. | ||
This file contains url definitions for authentication endpoints. | ||
""" | ||
from django.urls import path | ||
from .views import VerifyFileAccessView | ||
|
||
urlpatterns = [ | ||
path("verify/file", VerifyFileAccessView.as_view()), | ||
] |
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,51 @@ | ||
""" | ||
Authentication views. | ||
This file contains the views for the custom authentication endpoints. | ||
""" | ||
import json | ||
|
||
from asgiref.sync import async_to_sync | ||
from channels.layers import get_channel_layer | ||
from rest_framework.response import Response | ||
from rest_framework.views import APIView | ||
|
||
from src.authentication.authentication import CookieTokenAuthentication | ||
from src.download.utils import list_files, prepare_path, validate_for_request, validate_for_archive, log_file_access | ||
|
||
|
||
class VerifyFileAccessView(APIView): | ||
""" | ||
An API view for checking file access. | ||
""" | ||
authentication_classes = [CookieTokenAuthentication] | ||
|
||
def get(self, request): | ||
""" | ||
Validate a nginx subrequest cookie auth token and subsequent file access for the given auth token user. | ||
:param request: Request | ||
:return: Response | ||
""" | ||
user, _ = self.get_authenticators()[0].get_user_by_cookie_auth_token(request) | ||
path = prepare_path(request.headers.get('X-Original-Uri')[1:]) | ||
|
||
is_valid_for_request = validate_for_request(path, user) | ||
is_valid_for_archive = validate_for_archive(path, user) | ||
|
||
if is_valid_for_request or is_valid_for_archive: | ||
if is_valid_for_request: | ||
file_log = log_file_access(path) | ||
async_to_sync(get_channel_layer().group_send)( | ||
f"requests.group.{user.id}", | ||
{ | ||
"type": "websocket.send", | ||
"data": { | ||
"type": "requests.files.retrieved", | ||
"message": json.dumps(list_files(file_log.request.path), default=str), | ||
}, | ||
}, | ||
) | ||
return Response(status=200) | ||
|
||
return Response(status=403, data="You're not authorized to access this resource or the resource doesn't exist.") |
This file was deleted.
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