You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2021/05/24 19:44:21 UTC
[airavata-django-portal-sdk] branch mft-integration updated:
AIRAVATA-3420 Add token based auth for downloads
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch mft-integration
in repository https://gitbox.apache.org/repos/asf/airavata-django-portal-sdk.git
The following commit(s) were added to refs/heads/mft-integration by this push:
new 6672f54 AIRAVATA-3420 Add token based auth for downloads
6672f54 is described below
commit 6672f541cb2decdcab183a895608e68ec806167a
Author: Marcus Christie <ma...@apache.org>
AuthorDate: Mon May 24 15:41:59 2021 -0400
AIRAVATA-3420 Add token based auth for downloads
---
airavata_django_portal_sdk/user_storage/api.py | 10 ++++++++--
airavata_django_portal_sdk/views.py | 7 +++----
requirements.txt | 1 +
setup.py | 3 ++-
4 files changed, 14 insertions(+), 7 deletions(-)
diff --git a/airavata_django_portal_sdk/user_storage/api.py b/airavata_django_portal_sdk/user_storage/api.py
index bfdd9c0..eaae583 100644
--- a/airavata_django_portal_sdk/user_storage/api.py
+++ b/airavata_django_portal_sdk/user_storage/api.py
@@ -222,7 +222,8 @@ def open_file(request, data_product=None, data_product_uri=None):
resp = _call_remote_api(
request,
"/download",
- params={'data-product-uri': data_product.productUri})
+ params={'data-product-uri': data_product.productUri},
+ base_url="/sdk")
file = io.BytesIO(resp.content)
disposition = resp.headers['Content-Disposition']
disp_value, disp_params = cgi.parse_header(disposition)
@@ -846,6 +847,7 @@ def _call_remote_api(
path_params=None,
method="get",
raise_for_status=True,
+ base_url="/api",
**kwargs):
headers = {
@@ -856,9 +858,13 @@ def _call_remote_api(
encoded_path_params[pk] = quote(pv)
encoded_path = path.format(**encoded_path_params)
logger.debug(f"encoded_path={encoded_path}")
+ remote_api_url = settings.GATEWAY_DATA_STORE_REMOTE_API
+ if remote_api_url.endswith("/api"):
+ warnings.warn(f"Set GATEWAY_DATA_STORE_REMOTE_API to \"{remote_api_url}\". /api is no longer needed.", DeprecationWarning)
+ remote_api_url = remote_api_url[0:remote_api_url.rfind("/api")]
r = requests.request(
method,
- f'{settings.GATEWAY_DATA_STORE_REMOTE_API}{encoded_path}',
+ f'{remote_api_url}{base_url}{encoded_path}',
headers=headers,
**kwargs,
)
diff --git a/airavata_django_portal_sdk/views.py b/airavata_django_portal_sdk/views.py
index b083db9..cd08dff 100644
--- a/airavata_django_portal_sdk/views.py
+++ b/airavata_django_portal_sdk/views.py
@@ -1,27 +1,26 @@
import logging
import os
-from django.contrib.auth.decorators import login_required
from django.core.exceptions import ObjectDoesNotExist
from django.http import FileResponse, Http404
from django.shortcuts import redirect
from django.views.decorators.gzip import gzip_page
+from rest_framework.decorators import api_view
from airavata_django_portal_sdk import user_storage
logger = logging.getLogger(__name__)
-@login_required
+@api_view()
def download(request):
data_product_uri = request.GET.get('data-product-uri', '')
download_url = user_storage.get_download_url(request, data_product_uri=data_product_uri)
return redirect(download_url)
-# TODO: moving this view out of REST API means losing access token based authentication
@gzip_page
-@login_required
+@api_view()
def download_file(request):
data_product_uri = request.GET.get('data-product-uri', '')
force_download = 'download' in request.GET
diff --git a/requirements.txt b/requirements.txt
index 62b1685..20c045c 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -2,6 +2,7 @@ bcrypt==3.1.7
cffi==1.14.1
cryptography==3.0
Django==2.2.17
+djangorestframework==3.10.3
google-api-python-client==1.12.8
grpcio-tools==1.34.1
grpcio==1.34.1
diff --git a/setup.py b/setup.py
index c99e431..7b36200 100644
--- a/setup.py
+++ b/setup.py
@@ -23,8 +23,9 @@ setup(
packages=find_packages(),
install_requires=[
"django",
+ "django-rest-framework",
# Installed from git repo; see requirements.txt for details
- "airavata-python-sdk"
+ "airavata-python-sdk",
],
classifiers=[
"Development Status :: 4 - Beta",