Skip to content

Commit

Permalink
don't deal with non-absolute local file paths
Browse files Browse the repository at this point in the history
  • Loading branch information
daisieh committed Apr 18, 2023
1 parent af02da6 commit 07ca8d6
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion htsget_server/drs_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import database
from flask import request, Flask
import os
import os.path
import re
import authz
from markupsafe import escape
Expand Down Expand Up @@ -231,9 +232,13 @@ def _get_file_path(drs_file_obj_id):
url_pieces = urlparse(method["access_url"]["url"])
if url_pieces.scheme == "file":
if url_pieces.netloc == "" or url_pieces.netloc == "localhost":
result["path"] = url_pieces.path.lstrip("/")
result["path"] = os.path.abspath(url_pieces.path)
if not os.path.exists(result["path"]):
result['message'] = f"No file exists at {result['path']} on the server."
result['status_code'] = 404
if result['path'] is None:
result['message'] = f"No file was found for drs_obj {drs_file_obj_id}: {url}"
result['status_code'] = 404
result.pop('path')
return result

2 changes: 1 addition & 1 deletion htsget_server/htsget_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def _get_data(id_, reference_name=None, start=None, end=None, class_=None, forma
gen_obj = drs_operations._get_genomic_obj(id_)
if gen_obj is not None:
if "message" in gen_obj:
return gen_obj['message'], gen_obj['status_code']
return {"message": gen_obj['message']}, gen_obj['status_code']
file_in = gen_obj["file"]
ntf = tempfile.NamedTemporaryFile(prefix='htsget', suffix=format_,
mode='wb', delete=False)
Expand Down
2 changes: 1 addition & 1 deletion tests/test_htsget_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ def test_post_update():
obj = response.json()

url = f"{HOST}/ga4gh/drs/v1/objects"
access_url = f"file:///./data/files/NA18537.vcf.gz" # this is local within the htsget server container, not from where we're running pytest
access_url = f"file:////app/htsget_server/data/files/NA18537.vcf.gz" # this is local within the htsget server container, not from where we're running pytest
obj["access_methods"] = [
{
"type": "file",
Expand Down

0 comments on commit 07ca8d6

Please sign in to comment.