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

fix service-info #70

Merged
merged 3 commits into from
Feb 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 52 additions & 26 deletions bento_beacon/endpoints/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,14 @@ def service_info():
@info.route("/")
@authz_middleware.deco_public_endpoint
def beacon_info():
return beacon_info_response(current_app.config.get("SERVICE_INFO", build_service_info()))
return beacon_info_response(current_app.config.get("SERVICE_DETAILS", build_service_details()))


# as above but with beacon overview details
@info.route("/info")
@authz_middleware.deco_public_endpoint
def beacon_info_with_overview():
service_info = current_app.config.get("SERVICE_INFO", build_service_info())
service_info = current_app.config.get("SERVICE_DETAILS", build_service_details())
return beacon_info_response({**service_info, "overview": overview()})


Expand Down Expand Up @@ -88,7 +88,7 @@ def beacon_map():
@info.route("/overview")
@authz_middleware.deco_public_endpoint
def beacon_overview():
service_info = current_app.config.get("SERVICE_INFO", build_service_info())
service_info = current_app.config.get("SERVICE_DETAILS", build_service_details())
return beacon_info_response({**service_info, "overview": overview()})


Expand All @@ -114,48 +114,74 @@ def get_experiment_schema():
# -------------------------------------------------------
# these return the appropriate response but also save as a side effect

def build_service_info():
service_info = deepcopy(current_app.config["BEACON_CONFIG"].get("serviceInfo"))
service_info["environment"] = "dev" if current_app.config["DEBUG"] else "prod"
service_info["id"] = current_app.config["BEACON_ID"]
service_info["name"] = current_app.config["BEACON_NAME"]

def build_service_details():
# build info response in beacon format
info = current_app.config["BEACON_CONFIG"].get("serviceInfo")
s = {
"id": current_app.config["BEACON_ID"],
"name": current_app.config["BEACON_NAME"],
"apiVersion": current_app.config["BEACON_SPEC_VERSION"],
"environment": "dev" if current_app.config["DEBUG"] else "prod",
"organization": info["organization"],
"version": current_app.config["BENTO_BEACON_VERSION"]
}

# url for beacon ui
if current_app.config["BEACON_UI_ENABLED"]:
s["welcomeUrl"] = current_app.config["BEACON_UI_URL"]

# retrieve dataset description from DATS
# may be multiple datasets, so collect all descriptions into one string
# for custom description, add a "description" field to service info in beacon_config.json
k_datasets = katsu_datasets()
dats_array = list(map(lambda d: json.loads(d.get("datsFile", "{}")), k_datasets))
description = " ".join([d.get("description") for d in dats_array if "description" in d])
if description and service_info.get("description") is None:
service_info["description"] = description
if description and info.get("description") is None:
s["description"] = description

# url for beacon ui
if current_app.config["BEACON_UI_ENABLED"]:
service_info["welcomeUrl"] = current_app.config["BEACON_UI_URL"]

current_app.config["SERVICE_INFO"] = service_info
return service_info
current_app.config["SERVICE_DETAILS"] = s
return s


def build_ga4gh_service_info():
service_info = current_app.config.get("SERVICE_INFO", build_service_info())
service_info["type"] = {
"artifact": "Beacon v2",
"group": "org.ga4gh",
"version": current_app.config["BEACON_SPEC_VERSION"]
# construct from beacon-format info
info = current_app.config.get("SERVICE_DETAILS", build_service_details())

s = {
"id": info["id"],
"name": info["name"],
"type": {
"artifact": "Beacon v2",
"group": "org.ga4gh",
"version": info["apiVersion"]
},
"environment": info["environment"],
"organization": {
"name": info["organization"]["name"],
"url": info["organization"]["welcomeUrl"]
},
"contactUrl": info["organization"]["contactUrl"],
"version": info["version"],
"bento": {
"serviceKind": "beacon"
}
}
service_info["version"] = current_app.config["BENTO_BEACON_VERSION"]
service_info["bento"] = {"serviceKind": "beacon"}
current_app.config["BEACON_GA4GH_SERVICE_INFO"] = service_info
return service_info

description = info.get("description")
if description:
s["description"] = description

current_app.config["BEACON_GA4GH_SERVICE_INFO"] = s
return s


def build_configuration_endpoint_response():
entry_types_details = current_app.config.get("ENTRY_TYPES", build_entry_types())

# production status is one of "DEV", "PROD", "TEST"
# while environment is one of "dev", "prod", "test", "staging".. generally only use "dev" or "prod"
production_status = current_app.config.get("SERVICE_INFO", build_service_info()).get("environment", "error").upper()
production_status = current_app.config.get("SERVICE_DETAILS", build_service_details()).get("environment", "error").upper()

response = {
"$schema": JSON_SCHEMA,
Expand Down