Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Drs endpoints #261

Merged
merged 18 commits into from
Mar 17, 2020
2 changes: 1 addition & 1 deletion indexd/drs/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def list_drs_records():
@blueprint.route(
"/ga4gh/drs/v1/objects/<path:object_id>/access/<path:access_id>", methods=["GET"]
)
def get_signed_url(object_id, access_id):
def get_signed_url(object_id, access_id=None):
res = flask.current_app.fence_client.get_signed_url_for_object(
object_id=object_id, access_id=access_id
)
Expand Down
10 changes: 8 additions & 2 deletions indexd/fence_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@
from indexd.default_settings import settings

from indexd.index.errors import NoRecordFound as IndexNoRecordFound
from indexd.errors import UserError, UnexpectedError
from indexd.auth.errors import AuthError
from indexd.errors import UnexpectedError


logger = get_logger(__name__)

SUPPORTED_PROTOCOLS = ["s3", "http", "ftp", "https", "gs"]


class FenceClient(object):
def __init__(self, url):
Expand All @@ -28,7 +30,11 @@ def get_signed_url_for_object(self, object_id, access_id):
fence_server = self.url
api_url = fence_server.rstrip("/") + "/data/download/"
url = api_url + object_id
if access_id:
if access_id is not None and access_id != "":
if access_id not in SUPPORTED_PROTOCOLS:
raise UserError(
"The specified protocol {} is not supported".format(access_id)
)
paulineribeyre marked this conversation as resolved.
Show resolved Hide resolved
url += "?protocol=" + access_id
headers = flask.request.headers
if "AUTHORIZATION" not in headers:
Expand Down
6 changes: 3 additions & 3 deletions tests/test_drs.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ def test_get_presigned_url(client, user):
res_1 = client.post("/index/", json=data, headers=user)
assert res_1.status_code == 200
rec_1 = res_1.json
access_id_list = ["s3", "gs", "sftp", "ftp"]
access_id_list = ["s3", "gs", "ftp"]
for access_id in access_id_list:
presigned = generate_presigned_url_response(rec_1["did"], access_id)
res_2 = client.get(
Expand Down Expand Up @@ -179,10 +179,10 @@ def test_get_presigned_url_wrong_access_id(client, user):
rec_1 = res_1.json
presigned = generate_presigned_url_response(rec_1["did"], "s3", status=404)
res_2 = client.get(
"/ga4gh/drs/v1/objects/" + rec_1["did"] + "/access/s3",
"/ga4gh/drs/v1/objects/" + rec_1["did"] + "/access/s2",
headers={"AUTHORIZATION": "12345"},
)
assert res_2.status_code == 404
assert res_2.status_code == 400
paulineribeyre marked this conversation as resolved.
Show resolved Hide resolved


@responses.activate
Expand Down