Skip to content

Commit

Permalink
Remove middleware, prevent display of AWS sync command when S3 URI is…
Browse files Browse the repository at this point in the history
… unavailable,and skip DUA signature check for open projects.
  • Loading branch information
Chrystinne committed Jan 14, 2025
1 parent 8f06abe commit 1721f8a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 39 deletions.
1 change: 0 additions & 1 deletion physionet-django/physionet/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@
# RedirectFallbackMiddleware should go at end of list, according
# to the docs: https://docs.djangoproject.com/en/4.1/ref/contrib/redirects/
'django.contrib.redirects.middleware.RedirectFallbackMiddleware',
'project.modelcomponents.middleware.CurrentRequestMiddleware',
]

REST_FRAMEWORK = {
Expand Down
19 changes: 0 additions & 19 deletions physionet-django/project/modelcomponents/middleware.py

This file was deleted.

18 changes: 7 additions & 11 deletions physionet-django/project/modelcomponents/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from django.db import models
from django.conf import settings
from project.modelcomponents.generic import BaseInvitation
from project.modelcomponents.middleware import get_current_request


class StorageRequest(BaseInvitation):
"""
Expand Down Expand Up @@ -64,22 +62,20 @@ class AWS(models.Model):
class Meta:
default_permissions = ()

def s3_uri(self):
def s3_uri(self, user=None):
"""
Construct the S3 URI for the project.
Parameters:
user (User): The user requesting the S3 URI
"""
from project.cloud.s3 import get_access_point_name_for_user_and_project
if self.is_private:
# Retrieve the current request
request = get_current_request()
if not request or not hasattr(request, 'user') or not request.user.is_authenticated:
print("Error: No valid user in the current request.")
if not user or not user.is_authenticated:
print("Error: No valid user provided")
return None

# Get the current user from the request
current_user = request.user

# Fetch access point name
access_point_name = get_access_point_name_for_user_and_project(current_user, self)
access_point_name = get_access_point_name_for_user_and_project(user, self)
if access_point_name and "No " not in access_point_name:
return (
f's3://arn:aws:s3:us-east-1:{settings.AWS_ACCOUNT_ID}:accesspoint/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,11 +430,13 @@ <h5>Access the files</h5>
<pre class="shell-command">wget -r -N -c -np{% if project.access_policy %} --user {{ user }} --ask-password{% endif %} {{ bulk_url_prefix }}{% url 'serve_published_project_file' project.slug project.version '' %}</pre>
</li>
{% endif %}
{% if has_s3_credentials and project.aws.sent_files and has_signed_dua and s3_uri%}
<li>
Download the files using AWS command line tools:
<pre class="shell-command">aws s3 sync {{ s3_uri }} DESTINATION</pre>
</li>
{% if has_s3_credentials and project.aws.sent_files and s3_uri != None %}
{% if not project.aws.is_private or has_signed_dua %}
<li>
Download the files using AWS command line tools:
<pre class="shell-command">aws s3 sync {{ s3_uri }} DESTINATION</pre>
</li>
{% endif %}
{% endif %}

</ul>
Expand Down
7 changes: 4 additions & 3 deletions physionet-django/project/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1934,11 +1934,12 @@ def published_project(request, project_slug, version, subdir=''):

# Check if AWS instance exists for the project
s3_uri = None
if has_signed_dua and hasattr(project, 'aws'):
if hasattr(project, 'aws'):
if project.aws.is_private:
s3_uri = project.aws.s3_uri()
if has_signed_dua:
s3_uri = project.aws.s3_uri(user=request.user)
else:
s3_uri = '--no-sign-request ' + project.aws.s3_uri()
s3_uri = '--no-sign-request ' + project.aws.s3_uri(user=None)

context = {
'project': project,
Expand Down

0 comments on commit 1721f8a

Please sign in to comment.