Skip to content

Commit

Permalink
Add check of the mangled list to the s3-resource/<path> endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
Tehsurfer committed Aug 18, 2023
1 parent bf47b39 commit 1c0948f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 5 deletions.
10 changes: 6 additions & 4 deletions app/main.py
Expand Up @@ -44,7 +44,7 @@
from app.scicrunch_process_results import process_results, process_get_first_scaffold_info, reform_aggregation_results, \
reform_curies_results, reform_dataset_results, reform_related_terms, reform_anatomy_results
from app.serializer import ContactRequestSchema
from app.utilities import img_to_base64_str
from app.utilities import img_to_base64_str, check_path_in_mangled_list
from app.osparc.osparc import start_simulation as do_start_simulation
from app.osparc.osparc import check_simulation as do_check_simulation
from app.biolucida_process_results import process_results as process_biolucida_results
Expand Down Expand Up @@ -379,11 +379,12 @@ def url_exists(path, bucket_name=Config.DEFAULT_S3_BUCKET_NAME):

query_args = request.args
s3BucketName = query_args.get("s3BucketName", bucket_name)
s3_path = check_path_in_mangled_list(path)

try:
head_response = s3.head_object(
Bucket=s3BucketName,
Key=path,
Key=s3_path,
RequestPayer="requester"
)
except ClientError:
Expand Down Expand Up @@ -426,11 +427,12 @@ def direct_download_url(path, bucket_name=Config.DEFAULT_S3_BUCKET_NAME):

query_args = request.args
s3BucketName = query_args.get("s3BucketName", bucket_name)
s3_path = check_path_in_mangled_list(path)

try:
head_response = s3.head_object(
Bucket=s3BucketName,
Key=path,
Key=s3_path,
RequestPayer="requester"
)
content_length = head_response.get('ContentLength', Config.DIRECT_DOWNLOAD_LIMIT)
Expand All @@ -443,7 +445,7 @@ def direct_download_url(path, bucket_name=Config.DEFAULT_S3_BUCKET_NAME):

response = s3.get_object(
Bucket=s3BucketName,
Key=path,
Key=s3_path,
RequestPayer="requester"
)

Expand Down
4 changes: 3 additions & 1 deletion app/manifest_name_to_discover_name.py
Expand Up @@ -5008,5 +5008,7 @@
'files/primary/sub-Cadaver-Subject-2/Ultrasound_raw_Cadaver_Subject 2.mp4': 'files/primary/sub-Cadaver-Subject-2/Ultrasound_raw_Cadaver_Subject_2.mp4',
'files/primary/sub-Cadaver-Subject-3/Ultrasound_raw_Cadaver_Subject 3.mp4': 'files/primary/sub-Cadaver-Subject-3/Ultrasound_raw_Cadaver_Subject_3.mp4',
'files/derivative/sam-P21 BAT/ses-Pgp9.5/P21-3_Pgp9.5.jpx': 'files/derivative/sam-P21 BAT/ses-Pgp9.5/P21-3 Pgp9.5.jpx',
'files/derivative/sam-P21 BAT/ses-Pgp9.5/P21-4_Pgp9.5.jpx': 'files/derivative/sam-P21 BAT/ses-Pgp9.5/P21-4 Pgp9.5.jpx'
'files/derivative/sam-P21 BAT/ses-Pgp9.5/P21-4_Pgp9.5.jpx': 'files/derivative/sam-P21 BAT/ses-Pgp9.5/P21-4 Pgp9.5.jpx',
'files/derivative/mapped_Pig 7_thumbnail.jpeg': 'files/derivative/mapped_Pig_7_thumbnail.jpeg',
'files/derivative/mapped_Pig 16_thumbnail.jpeg': 'files/derivative/mapped_Pig_16_thumbnail.jpeg'
}
12 changes: 12 additions & 0 deletions app/utilities.py
@@ -1,6 +1,18 @@
import base64
from io import BytesIO
from app.manifest_name_to_discover_name import name_map

def check_path_in_mangled_list(s3_path):

# Split out the file part of the path
s3_paths = s3_path.split('files/')
s3_paths[1] = 'files/' + s3_paths[1] # Add the part we split on back

# Switch the path to the mapped one if it is listed
if s3_paths[1] in name_map:
s3_paths[1] = name_map[s3_paths[1]]

return s3_paths[0] + s3_paths[1] # Return the path with dataset info at the front

def img_to_base64_str(img):
"""
Expand Down
6 changes: 6 additions & 0 deletions tests/test_dataset_info.py
Expand Up @@ -273,3 +273,9 @@ def test_pennsieve_identifier_dataset_search(client):
print(first_result)
for r in result[BIOLUCIDA_3D]:
print(r['dataset']['path'])

def test_name_mangling_for_s3_resource(client):
# This test uses a file on dataset 328 which has a file where space is converted to underscore
# to check the name mangling code is working
r = client.get('/s3-resource/328/1/files/derivative/mapped_Pig%207_thumbnail.jpeg?s3BucketName=prd-sparc-discover-use1')
assert r.status_code == 200

0 comments on commit 1c0948f

Please sign in to comment.