Skip to content

Commit

Permalink
Merge pull request #210 from CanDIG/daisieh/error-handling
Browse files Browse the repository at this point in the history
error handling, misc fixes
  • Loading branch information
daisieh authored Jun 15, 2022
2 parents c1993bb + c926a41 commit 3c3d18f
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 13 deletions.
1 change: 1 addition & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,5 @@ if [[ -f "initial_setup" ]]; then
rm initial_setup
fi

bash /app/htsget_server/renew_token.sh
python3 htsget_server/server.py $@
2 changes: 1 addition & 1 deletion htsget_server/drs_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ def get_access_url(object_id, access_id):
bucket = "testhtsget"
else:
response = requests.get(
AUTHZ['CANDIG_VAULT_URL'] + f"/v1/aws/{endpoint}/{bucket}",
AUTHZ['CANDIG_VAULT_URL'] + f"/v1/aws/{endpoint}-{bucket}",
headers={"Authorization": f"Bearer {VAULT_S3_TOKEN}"}
)
if response.status_code == 200:
Expand Down
29 changes: 18 additions & 11 deletions htsget_server/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ def _get_data(id_, reference_name=None, start=None, end=None, class_="body", for
# get a file and index from drs, based on the id_
gen_obj = _get_genomic_obj(request, id_)
if gen_obj is not None:
if "error" in gen_obj:
return gen_obj, 500
file_in = gen_obj["file"]
ntf = tempfile.NamedTemporaryFile(prefix='htsget', suffix=format_,
mode='wb', delete=False)
Expand Down Expand Up @@ -228,6 +230,8 @@ def _get_urls(file_type, id, reference_name=None, start=None, end=None, _class=N

gen_obj = _get_genomic_obj(request, id)
if gen_obj is not None:
if "error" in gen_obj:
return gen_obj, 500
if _class == "header":
urls = [{"url": f"{request.url_root}/htsget/v1/{file_type}s/data/{id}?class=header",
"class": "header"}]
Expand Down Expand Up @@ -318,17 +322,20 @@ def _get_genomic_obj(request, object_id):
if "access_id" in method and method["access_id"] != "":
# we need to go to the access endpoint to get the url and file
(url, status_code) = drs_operations.get_access_url(sub_obj["name"], method["access_id"])
f_path = os.path.join(tempdir, sub_obj["name"])
with open(f_path, mode='wb') as f:
with requests.get(url["url"], stream=True) as r:
with r.raw as content:
f.write(content.data)
if index_match is not None:
index_file = f_path
elif read_match is not None:
read_file = f_path
elif variant_match is not None:
variant_file = f_path
if status_code < 300:
f_path = os.path.join(tempdir, sub_obj["name"])
with open(f_path, mode='wb') as f:
with requests.get(url["url"], stream=True) as r:
with r.raw as content:
f.write(content.data)
if index_match is not None:
index_file = f_path
elif read_match is not None:
read_file = f_path
elif variant_match is not None:
variant_file = f_path
else:
return {"error": url}
else:
# the access_url has all the info we need
url_pieces = urlparse(method["access_url"]["url"])
Expand Down
2 changes: 1 addition & 1 deletion htsget_server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,4 @@ def index():

if __name__ == '__main__':
logging.basicConfig(filename='record.log', level=logging.DEBUG, format=f'%(asctime)s %(levelname)s %(name)s %(threadName)s : %(message)s')
app.run(port = PORT, debug=False)
app.run(port = PORT, debug=True)
1 change: 1 addition & 0 deletions renew_token.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
echo "renewing S3 token"
curl -X "POST" "http://docker.localhost:8200/v1/auth/token/renew-self" \
-H 'X-Vault-Token: <VAULT_S3_TOKEN>' \
-H 'Content-Type: application/json; charset=utf-8' \
Expand Down

0 comments on commit 3c3d18f

Please sign in to comment.