diff --git a/entrypoint.sh b/entrypoint.sh index 88861655..4ad7af6a 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -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 $@ diff --git a/htsget_server/drs_operations.py b/htsget_server/drs_operations.py index 919fb02a..293a6263 100644 --- a/htsget_server/drs_operations.py +++ b/htsget_server/drs_operations.py @@ -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: diff --git a/htsget_server/operations.py b/htsget_server/operations.py index d6842118..124aa55e 100644 --- a/htsget_server/operations.py +++ b/htsget_server/operations.py @@ -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) @@ -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"}] @@ -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"]) diff --git a/htsget_server/server.py b/htsget_server/server.py index 3d972ee9..407d7555 100644 --- a/htsget_server/server.py +++ b/htsget_server/server.py @@ -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) diff --git a/renew_token.sh b/renew_token.sh index 515d16ec..134c691f 100644 --- a/renew_token.sh +++ b/renew_token.sh @@ -1,3 +1,4 @@ +echo "renewing S3 token" curl -X "POST" "http://docker.localhost:8200/v1/auth/token/renew-self" \ -H 'X-Vault-Token: ' \ -H 'Content-Type: application/json; charset=utf-8' \