Skip to content

Commit

Permalink
fix things
Browse files Browse the repository at this point in the history
  • Loading branch information
BinamB committed Apr 13, 2023
1 parent 0836cfa commit e17a9fc
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 42 deletions.
4 changes: 2 additions & 2 deletions .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@
"filename": "tests/default_test_settings.py",
"hashed_secret": "afc848c316af1a89d49826c5ae9d00ed769415f3",
"is_verified": false,
"line_number": 41
"line_number": 40
}
],
"tests/postgres/migrations/test_15f2e9345ade_create_tables.py": [
Expand Down Expand Up @@ -395,5 +395,5 @@
}
]
},
"generated_at": "2023-04-12T20:10:41Z"
"generated_at": "2023-04-13T17:00:13Z"
}
3 changes: 0 additions & 3 deletions indexd/default_settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
from os import environ
from .index.drivers.alchemy import SQLAlchemyIndexDriver
from .alias.drivers.alchemy import SQLAlchemyAliasDriver
from .auth.drivers.alchemy import SQLAlchemyAuthDriver
Expand Down Expand Up @@ -49,8 +48,6 @@

CONFIG["DRS_SERVICE_INFO"] = {
"name": "DRS System",
"host": "https://example.com/api/ga4gh/drs/v1/",
"hints": [],
"type": {
"group": "org.ga4gh",
"artifact": "drs",
Expand Down
50 changes: 19 additions & 31 deletions indexd/drs/blueprint.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import re
import flask
import json
from indexd.errors import AuthError, AuthzError
Expand All @@ -23,41 +24,28 @@ def get_drs_service_info():
reverse_domain_name = reverse_url(url=os.environ["HOSTNAME"])

ret = {
"id": blueprint.service_info.get("id", reverse_domain_name),
"name": blueprint.service_info.get("name", "DRS System"),
"version": blueprint.service_info.get("version", "1.0.3"),
"id": reverse_domain_name,
"name": "DRS System",
"version": "1.0.3",
"type": {
"group": blueprint.service_info.get("group", "org.ga4gh"),
"artifact": blueprint.service_info.get("artifact", "drs"),
"group": "org.ga4gh",
"artifact": "drs",
"version": "1.0.3",
},
"organization": {
"name": "CTDS",
"url": "https://" + os.environ["HOSTNAME"],
},
}

ret["organization"] = {}

if "type" in blueprint.service_info and isinstance(
blueprint.service_info["type"], dict
):
ret["type"]["version"] = blueprint.service_info.get("type").get(
"version", "1.0.3"
)
else:
ret["type"]["version"] = "1.0.3"

if (
"organization" in blueprint.service_info
and "url" in blueprint.service_info["organization"]
):
ret["organization"]["url"] = blueprint.service_info["organization"]["url"]
else:
ret["organization"]["url"] = "https://" + os.environ["HOSTNAME"]

if (
"organization" in blueprint.service_info
and "name" in blueprint.service_info["organization"]
):
ret["organization"]["name"] = blueprint.service_info["organization"]["name"]
else:
ret["organization"]["name"] = "CTDS"
if blueprint.service_info:
for key, value in blueprint.service_info.items():
if key in ret:
if isinstance(value, dict):
for inner_key, inner_value in value.items():
ret[key][inner_key] = inner_value
else:
ret[key] = value

return flask.jsonify(ret), 200

Expand Down
5 changes: 4 additions & 1 deletion indexd/utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import re
from urllib.parse import urlparse


def hint_match(record, hints):
Expand Down Expand Up @@ -202,7 +203,9 @@ def reverse_url(url):
id (str): DRS service-info ID
example: org.example.drs
"""

parsed_url = urlparse(url)
if parsed_url.scheme in ["http", "https"]:
url = parsed_url.hostname
segments = url.split(".")
reversed_segments = reversed(segments)
res = ".".join(reversed_segments)
Expand Down
1 change: 0 additions & 1 deletion tests/default_test_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
"artifact": "drs",
"version": "1.0.3",
},
"host": "https://fictitious-commons.io/",
"version": "1.0.3",
"organization": {
"name": "CTDS",
Expand Down
12 changes: 8 additions & 4 deletions tests/test_drs.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,10 +203,14 @@ def test_drs_service_info_no_information_configured(client):
"url": "https://fictitious-commons.io",
},
}
backup = settings["config"]["DRS_SERVICE_INFO"].copy()

settings["config"]["DRS_SERVICE_INFO"].clear()
try:
settings["config"]["DRS_SERVICE_INFO"].clear()

res = client.get("/ga4gh/drs/v1/service-info")
res = client.get("/ga4gh/drs/v1/service-info")

assert res.status_code == 200
assert res.json == expected_info
assert res.status_code == 200
assert res.json == expected_info
finally:
settings["config"]["DRS_SERVICE_INFO"] = backup

0 comments on commit e17a9fc

Please sign in to comment.