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

HSClient handling #253

Merged
merged 12 commits into from
Nov 22, 2019
8 changes: 6 additions & 2 deletions indexd/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from indexclient.client import IndexClient
from doiclient.client import DOIClient
from dosclient.client import DOSClient
from hsclient.client import HSClient

from indexd.utils import hint_match

Expand Down Expand Up @@ -76,12 +77,15 @@ def dist_get_record(record):

for indexd in sorted_dist:
try:
if indexd["type"] == "doi":
if indexd["type"] == "doi": # Digital Object Identifier
fetcher_client = DOIClient(baseurl=indexd["host"])
res = fetcher_client.get(record)
elif indexd["type"] == "dos":
elif indexd["type"] == "dos": # Data Object Service
fetcher_client = DOSClient(baseurl=indexd["host"])
res = fetcher_client.get(record)
elif indexd["type"] == "hs": # HydroShare and CommonsShare
fetcher_client = HSClient(baseurl=indexd["host"])
res = fetcher_client.get(record)
else:
fetcher_client = IndexClient(baseurl=indexd["host"])
res = fetcher_client.global_get(record, no_dist=True)
Expand Down
43 changes: 27 additions & 16 deletions indexd/dos/blueprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,25 @@ def list_dos_records():


def indexd_to_dos(record):
data_object = {
"id": record["did"],
"name": record["file_name"],
"created": record["created_date"],
"updated": record["updated_date"],
"size": record["size"],
"version": record["rev"],
"description": "",
"mime_type": "",
}

data_object["aliases"] = record["alias"]
data_object = {"id": record["did"], "description": "", "mime_type": ""}

if "file_name" in record:
data_object["name"] = record["file_name"]

if "created_date" in record:
data_object["created"] = record["created_date"]

if "updated_date" in record:
data_object["updated"] = record["updated_date"]

if "rev" in record:
data_object["version"] = record["rev"]

if "size" in record:
data_object["size"] = record["size"]

if "alias" in record:
data_object["aliases"] = record["alias"]

# parse out checksums
data_object["checksums"] = []
Expand All @@ -120,22 +127,26 @@ def indexd_to_dos(record):

@blueprint.errorhandler(UserError)
def handle_user_error(err):
return flask.jsonify(error=str(err)), 400
ret = {"msg": str(err), "status_code": 400}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you need to return the status code also in the response data?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i don't know why it was done this way, but a production website is using a branch with this change so i'd rather not change the contents of the response

return flask.jsonify(ret), 400


@blueprint.errorhandler(AuthError)
def handle_auth_error(err):
return flask.jsonify(error=str(err)), 403
ret = {"msg": str(err), "status_code": 403}
return flask.jsonify(ret), 403


@blueprint.errorhandler(AliasNoRecordFound)
def handle_no_alias_record_error(err):
return flask.jsonify(error=str(err)), 404
ret = {"msg": str(err), "status_code": 404}
return flask.jsonify(ret), 404


@blueprint.errorhandler(IndexNoRecordFound)
def handle_no_index_record_error(err):
return flask.jsonify(error=str(err)), 404
ret = {"msg": str(err), "status_code": 404}
return flask.jsonify(ret), 404


@blueprint.record
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ psycopg2>=2.7
git+https://github.com/uc-cdis/cdislogging.git@0.0.2#egg=cdislogging
git+https://github.com/uc-cdis/indexclient.git@1.6.0#egg=indexclient
git+https://github.com/uc-cdis/doiclient.git@1.0.0#egg=doiclient
git+https://github.com/uc-cdis/dosclient.git@1.0.0#egg=dosclient
git+https://github.com/uc-cdis/dosclient.git@1.1.0#egg=dosclient
git+https://github.com/uc-cdis/hsclient.git@1.0.0#egg=hsclient
authutils==4.0.0
gen3rbac==0.1.2
4 changes: 3 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,15 @@
"indexclient",
"doiclient",
"dosclient",
"hsclient",
"authutils",
"gen3rbac",
],
dependency_links=[
"git+https://github.com/uc-cdis/cdislogging.git@0.0.2#egg=cdislogging",
"git+https://github.com/uc-cdis/indexclient.git@1.6.0#egg=indexclient",
"git+https://github.com/uc-cdis/doiclient.git@1.0.0#egg=doiclient",
"git+https://github.com/uc-cdis/dosclient.git@1.0.0#egg=dosclient",
"git+https://github.com/uc-cdis/dosclient.git@1.1.0#egg=dosclient",
"git+https://github.com/uc-cdis/hsclient.git@1.0.0#egg=hsclient",
],
)