From b3df75eb04a1a9f941555ff39d955fa8e28c9d9b Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 15 Sep 2022 23:51:09 -0400 Subject: [PATCH 01/13] retrieve git and chord service info in dev mode --- .gitignore | 1 + bento_service_registry/app.py | 49 ++++++++++++++++++++++++++++++++--- 2 files changed, 46 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index 89fcca1..134b661 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ htmlcov/ .idea/workspace.xml .idea/dataSources* /chord_services.json +.vscode diff --git a/bento_service_registry/app.py b/bento_service_registry/app.py index 32c17aa..a5a3960 100644 --- a/bento_service_registry/app.py +++ b/bento_service_registry/app.py @@ -2,6 +2,7 @@ import os import requests import sys +import subprocess from bento_lib.responses.flask_errors import ( flask_error_wrap, @@ -22,6 +23,7 @@ application = Flask(__name__) + application.config.from_mapping( BENTO_DEBUG=os.environ.get("CHORD_DEBUG", os.environ.get("FLASK_ENV", "production")).strip().lower() in ( "true", "1", "development"), @@ -44,6 +46,12 @@ def get_service_url(artifact: str): return urljoin(current_app.config["CHORD_URL"], current_app.config["URL_PATH_FORMAT"].format(artifact=artifact)) +def get_isDebbuging(): + if (current_app.config["BENTO_DEBUG"]==True): + return True # development + else: + return False + with application.app_context(): SERVICE_ID = current_app.config["SERVICE_ID"] SERVICE_INFO = { @@ -61,7 +69,7 @@ def get_service_url(artifact: str): with open(current_app.config["CHORD_SERVICES"], "r") as f: CHORD_SERVICES = [s for s in json.load(f) if not s.get("disabled")] # Skip disabled services - + service_info_cache = { # Pre-populate service-info cache with data for the current service SERVICE_ARTIFACT: {**SERVICE_INFO, "url": get_service_url(SERVICE_ARTIFACT)}, @@ -71,7 +79,7 @@ def get_service_url(artifact: str): def get_service(service_artifact): s_url = get_service_url(service_artifact) - if service_artifact not in service_info_cache: + if service_artifact: service_info_url = urljoin(f"{s_url}/", "service-info") print(f"[{SERVICE_NAME}] Contacting {service_info_url}", flush=True) @@ -113,10 +121,24 @@ def get_service(service_artifact): return service_info_cache[service_artifact] +@application.before_first_request +def before_first_request_func(): + try: + subprocess.run(["git", "config", "--global", "--add", "safe.directory", "/service-registry/bento_service_registry"]) + except: + print("error in git config") + + @application.route("/bento-services") @application.route("/chord-services") def chord_services(): - return jsonify(CHORD_SERVICES) + ### execute this in here allows to update the version of the services from chord-services + try: + with open(current_app.config["CHORD_SERVICES"], "r") as f: + chord_services_local = [s for s in json.load(f) if not s.get("disabled")] # Skip disabled services + except: + print("no chord") + return jsonify(chord_services_local) @application.route("/services") @@ -142,4 +164,23 @@ def service_types(): @application.route("/service-info") def service_info(): # Spec: https://github.com/ga4gh-discovery/ga4gh-service-info - return jsonify(SERVICE_INFO) + production_service_info = {"environment": "production"} + + if get_isDebbuging() == False: + production_service_info.update(SERVICE_INFO) + return jsonify(production_service_info) + + git_info = {"environment": "development"} + try: + res_tag = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]) + if res_tag is not None: + git_tag = res_tag.decode("utf-8").rstrip() + git_info["git_tag"] = git_tag + res_branch= subprocess.check_output(["git", "branch", "--show-current"]) + if res_branch is not None: + git_branch = res_branch.decode("utf-8").rstrip() + git_info["git_branch"] = git_branch + git_info.update(SERVICE_INFO) + return jsonify(git_info) # updated service info with the git info + except: + print("something went wrong at service-info") \ No newline at end of file From 325ddaf6d165ea75ca607868f6c88d7be2d74e16 Mon Sep 17 00:00:00 2001 From: Julian Date: Fri, 16 Sep 2022 12:12:05 -0400 Subject: [PATCH 02/13] git info retrieving in service-info --- bento_service_registry/app.py | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/bento_service_registry/app.py b/bento_service_registry/app.py index a5a3960..eba1d13 100644 --- a/bento_service_registry/app.py +++ b/bento_service_registry/app.py @@ -46,12 +46,6 @@ def get_service_url(artifact: str): return urljoin(current_app.config["CHORD_URL"], current_app.config["URL_PATH_FORMAT"].format(artifact=artifact)) -def get_isDebbuging(): - if (current_app.config["BENTO_DEBUG"]==True): - return True # development - else: - return False - with application.app_context(): SERVICE_ID = current_app.config["SERVICE_ID"] SERVICE_INFO = { @@ -124,9 +118,9 @@ def get_service(service_artifact): @application.before_first_request def before_first_request_func(): try: - subprocess.run(["git", "config", "--global", "--add", "safe.directory", "/service-registry/bento_service_registry"]) + subprocess.run(["git", "config", "--global", "--add", "safe.directory", "./bento_service_registry"]) except: - print("error in git config") + print("Error in dev-mode retrieving git folder configuration") @application.route("/bento-services") @@ -137,7 +131,7 @@ def chord_services(): with open(current_app.config["CHORD_SERVICES"], "r") as f: chord_services_local = [s for s in json.load(f) if not s.get("disabled")] # Skip disabled services except: - print("no chord") + print("Error in dev-mode retrieving chord information") return jsonify(chord_services_local) @@ -164,23 +158,22 @@ def service_types(): @application.route("/service-info") def service_info(): # Spec: https://github.com/ga4gh-discovery/ga4gh-service-info - production_service_info = {"environment": "production"} + production_service_info = {"environment": "prod"} - if get_isDebbuging() == False: + if not current_app.config["BENTO_DEBUG"]: production_service_info.update(SERVICE_INFO) return jsonify(production_service_info) - git_info = {"environment": "development"} + git_info = {"environment": "dev"} try: res_tag = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]) - if res_tag is not None: - git_tag = res_tag.decode("utf-8").rstrip() - git_info["git_tag"] = git_tag + if res_tag: + git_info["git_tag"] = res_tag.decode().rstrip() res_branch= subprocess.check_output(["git", "branch", "--show-current"]) - if res_branch is not None: - git_branch = res_branch.decode("utf-8").rstrip() - git_info["git_branch"] = git_branch + if res_branch: + git_info["git_branch"] = res_branch.decode().rstrip() git_info.update(SERVICE_INFO) return jsonify(git_info) # updated service info with the git info + except: - print("something went wrong at service-info") \ No newline at end of file + print("Error in dev-mode retrieving git information") \ No newline at end of file From af5432352a7639765ac52132d728a41e1c722ca2 Mon Sep 17 00:00:00 2001 From: Julian Date: Tue, 20 Sep 2022 13:32:23 -0400 Subject: [PATCH 03/13] added path to git folder and flake8 rev --- bento_service_registry/app.py | 33 +++++++++++++++++++-------------- setup.py | 2 +- 2 files changed, 20 insertions(+), 15 deletions(-) diff --git a/bento_service_registry/app.py b/bento_service_registry/app.py index eba1d13..785785f 100644 --- a/bento_service_registry/app.py +++ b/bento_service_registry/app.py @@ -34,6 +34,8 @@ URL_PATH_FORMAT=os.environ.get("URL_PATH_FORMAT", "api/{artifact}"), ) +path_for_git = os.path.abspath(os.path.join(os.path.dirname(__file__), "..")) + # Generic catch-all application.register_error_handler(Exception, flask_error_wrap_with_traceback(flask_internal_server_error, sr_compat=True, @@ -63,9 +65,10 @@ def get_service_url(artifact: str): with open(current_app.config["CHORD_SERVICES"], "r") as f: CHORD_SERVICES = [s for s in json.load(f) if not s.get("disabled")] # Skip disabled services - + service_info_cache = { # Pre-populate service-info cache with data for the current service + # TODO: investigate if this is necessary SERVICE_ARTIFACT: {**SERVICE_INFO, "url": get_service_url(SERVICE_ARTIFACT)}, } @@ -118,20 +121,22 @@ def get_service(service_artifact): @application.before_first_request def before_first_request_func(): try: - subprocess.run(["git", "config", "--global", "--add", "safe.directory", "./bento_service_registry"]) - except: - print("Error in dev-mode retrieving git folder configuration") + subprocess.run(["git", "config", "--global", "--add", "safe.directory", str(path_for_git)]) + except Exception as e: + except_name = type(e).__name__ + print("Error in dev-mode retrieving git folder configuration", except_name) @application.route("/bento-services") @application.route("/chord-services") def chord_services(): - ### execute this in here allows to update the version of the services from chord-services + # execute this in here allows to update the version of the services from chord-services try: with open(current_app.config["CHORD_SERVICES"], "r") as f: chord_services_local = [s for s in json.load(f) if not s.get("disabled")] # Skip disabled services - except: - print("Error in dev-mode retrieving chord information") + except Exception as e: + except_name = type(e).__name__ + print("Error in dev-mode retrieving chord information", except_name) return jsonify(chord_services_local) @@ -159,21 +164,21 @@ def service_types(): def service_info(): # Spec: https://github.com/ga4gh-discovery/ga4gh-service-info production_service_info = {"environment": "prod"} - if not current_app.config["BENTO_DEBUG"]: production_service_info.update(SERVICE_INFO) return jsonify(production_service_info) - + git_info = {"environment": "dev"} try: res_tag = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]) if res_tag: git_info["git_tag"] = res_tag.decode().rstrip() - res_branch= subprocess.check_output(["git", "branch", "--show-current"]) + res_branch = subprocess.check_output(["git", "branch", "--show-current"]) if res_branch: git_info["git_branch"] = res_branch.decode().rstrip() git_info.update(SERVICE_INFO) - return jsonify(git_info) # updated service info with the git info - - except: - print("Error in dev-mode retrieving git information") \ No newline at end of file + return jsonify(git_info) # updated service info with the git info + + except Exception as e: + except_name = type(e).__name__ + print("Error in dev-mode retrieving git information", except_name) diff --git a/setup.py b/setup.py index b0d3a0c..e933064 100644 --- a/setup.py +++ b/setup.py @@ -17,7 +17,7 @@ python_requires=">=3.6", install_requires=[ "bento_lib[flask]==2.2.1", - "Flask>=1.1.2,<2.0", + "Flask>=1.1.2,<2.0", "requests>=2.25.1,<3.0", ], From db049335dc444f335ad4684489a2389b712199fd Mon Sep 17 00:00:00 2001 From: Julian Date: Thu, 22 Sep 2022 11:33:51 -0400 Subject: [PATCH 04/13] removed cache from get_service func. --- bento_service_registry/app.py | 67 ++++++++++++++++++----------------- 1 file changed, 34 insertions(+), 33 deletions(-) diff --git a/bento_service_registry/app.py b/bento_service_registry/app.py index 785785f..551b7fb 100644 --- a/bento_service_registry/app.py +++ b/bento_service_registry/app.py @@ -66,7 +66,7 @@ def get_service_url(artifact: str): with open(current_app.config["CHORD_SERVICES"], "r") as f: CHORD_SERVICES = [s for s in json.load(f) if not s.get("disabled")] # Skip disabled services - service_info_cache = { +service_info_cache = { # Pre-populate service-info cache with data for the current service # TODO: investigate if this is necessary SERVICE_ARTIFACT: {**SERVICE_INFO, "url": get_service_url(SERVICE_ARTIFACT)}, @@ -76,46 +76,47 @@ def get_service_url(artifact: str): def get_service(service_artifact): s_url = get_service_url(service_artifact) - if service_artifact: - service_info_url = urljoin(f"{s_url}/", "service-info") + service_info_url = urljoin(f"{s_url}/", "service-info") - print(f"[{SERVICE_NAME}] Contacting {service_info_url}", flush=True) + print(f"[{SERVICE_NAME}] Contacting {service_info_url}", flush=True) - # Optional Authorization HTTP header to forward to nested requests - # TODO: Move X-Auth... constant to bento_lib - auth_header = request.headers.get("X-Authorization", request.headers.get("Authorization")) + # Optional Authorization HTTP header to forward to nested requests + # TODO: Move X-Auth... constant to bento_lib + auth_header = request.headers.get("X-Authorization", request.headers.get("Authorization")) - try: - r = requests.get( - service_info_url, - headers={"Authorization": auth_header} if auth_header else {}, - timeout=current_app.config["CONTACT_TIMEOUT"], - verify=not current_app.config["BENTO_DEBUG"], - ) + service_resp = {} - if r.status_code != 200: - print(f"[{SERVICE_NAME}] Non-200 status code on {service_artifact}: {r.status_code}\n" - f" Content: {r.text}", file=sys.stderr, flush=True) - - # If we have the special case where we got a JWT error from the proxy script, we can safely print out - # headers for debugging, since the JWT leaked isn't valid anyway. - if "invalid jwt" in r.text: - print(f" Encountered auth error, tried to use header: {auth_header}", - file=sys.stderr, flush=True) - - return None + try: + r = requests.get( + service_info_url, + headers={"Authorization": auth_header} if auth_header else {}, + timeout=current_app.config["CONTACT_TIMEOUT"], + verify=not current_app.config["BENTO_DEBUG"], + ) + + if r.status_code != 200: + print(f"[{SERVICE_NAME}] Non-200 status code on {service_artifact}: {r.status_code}\n" + f" Content: {r.text}", file=sys.stderr, flush=True) + + # If we have the special case where we got a JWT error from the proxy script, we can safely print out + # headers for debugging, since the JWT leaked isn't valid anyway. + if "invalid jwt" in r.text: + print(f" Encountered auth error, tried to use header: {auth_header}", + file=sys.stderr, flush=True) - except requests.exceptions.Timeout: - print(f"[{SERVICE_NAME}] Encountered timeout with {service_info_url}", file=sys.stderr, flush=True) return None - try: - service_info_cache[service_artifact] = {**r.json(), "url": s_url} - except JSONDecodeError: - print(f"[{SERVICE_NAME}] Encountered invalid response from {service_info_url}: {r.text}") - return None + except requests.exceptions.Timeout: + print(f"[{SERVICE_NAME}] Encountered timeout with {service_info_url}", file=sys.stderr, flush=True) + return None + + try: + service_resp[service_artifact] = {**r.json(), "url": s_url} + except JSONDecodeError: + print(f"[{SERVICE_NAME}] Encountered invalid response from {service_info_url}: {r.text}") + return None - return service_info_cache[service_artifact] + return service_resp[service_artifact] @application.before_first_request From e74e9cb5735d2da7247597f90718b2d7cf05dabd Mon Sep 17 00:00:00 2001 From: Paul Pillot Date: Mon, 26 Sep 2022 16:46:34 -0400 Subject: [PATCH 05/13] fix: service_registry timeout Avoid requesting service-info for service-registry while gathering info from all services, because of mono-threading both requests can't be processed at the same time --- bento_service_registry/app.py | 38 ++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 14 deletions(-) diff --git a/bento_service_registry/app.py b/bento_service_registry/app.py index 551b7fb..b99ff8d 100644 --- a/bento_service_registry/app.py +++ b/bento_service_registry/app.py @@ -60,13 +60,15 @@ def get_service_url(artifact: str): "url": "http://www.computationalgenomics.ca" }, "contactUrl": "mailto:david.lougheed@mail.mcgill.ca", - "version": bento_service_registry.__version__ + "version": bento_service_registry.__version__, + "url": get_service_url(SERVICE_ARTIFACT), + "environment": "prod" } with open(current_app.config["CHORD_SERVICES"], "r") as f: CHORD_SERVICES = [s for s in json.load(f) if not s.get("disabled")] # Skip disabled services -service_info_cache = { + service_info_cache = { # Pre-populate service-info cache with data for the current service # TODO: investigate if this is necessary SERVICE_ARTIFACT: {**SERVICE_INFO, "url": get_service_url(SERVICE_ARTIFACT)}, @@ -74,8 +76,12 @@ def get_service_url(artifact: str): def get_service(service_artifact): - s_url = get_service_url(service_artifact) + # special case: requesting info about the current service. Avoids request timeout + # when running gunicorn on a single worker + if service_artifact == SERVICE_ARTIFACT: + return _service_info() + s_url = get_service_url(service_artifact) service_info_url = urljoin(f"{s_url}/", "service-info") print(f"[{SERVICE_NAME}] Contacting {service_info_url}", flush=True) @@ -161,25 +167,29 @@ def service_types(): return jsonify(sorted(set(s["type"] for s in service_info_cache.values()))) -@application.route("/service-info") -def service_info(): - # Spec: https://github.com/ga4gh-discovery/ga4gh-service-info - production_service_info = {"environment": "prod"} +def _service_info(): if not current_app.config["BENTO_DEBUG"]: - production_service_info.update(SERVICE_INFO) - return jsonify(production_service_info) + return SERVICE_INFO - git_info = {"environment": "dev"} + info = { + **SERVICE_INFO, + "environment": "dev" + } try: res_tag = subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]) if res_tag: - git_info["git_tag"] = res_tag.decode().rstrip() + info["git_tag"] = res_tag.decode().rstrip() res_branch = subprocess.check_output(["git", "branch", "--show-current"]) if res_branch: - git_info["git_branch"] = res_branch.decode().rstrip() - git_info.update(SERVICE_INFO) - return jsonify(git_info) # updated service info with the git info + info["git_branch"] = res_branch.decode().rstrip() except Exception as e: except_name = type(e).__name__ print("Error in dev-mode retrieving git information", except_name) + + return info # updated service info with the git info + +@application.route("/service-info") +def service_info(): + # Spec: https://github.com/ga4gh-discovery/ga4gh-service-info + return jsonify(_service_info()) From 472fe3ed91ebc40483e1a468639bc703dc528824 Mon Sep 17 00:00:00 2001 From: Paul Pillot Date: Mon, 26 Sep 2022 19:35:33 -0400 Subject: [PATCH 06/13] remove service_info_cache --- bento_service_registry/app.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/bento_service_registry/app.py b/bento_service_registry/app.py index b99ff8d..09c54a6 100644 --- a/bento_service_registry/app.py +++ b/bento_service_registry/app.py @@ -68,12 +68,6 @@ def get_service_url(artifact: str): with open(current_app.config["CHORD_SERVICES"], "r") as f: CHORD_SERVICES = [s for s in json.load(f) if not s.get("disabled")] # Skip disabled services - service_info_cache = { - # Pre-populate service-info cache with data for the current service - # TODO: investigate if this is necessary - SERVICE_ARTIFACT: {**SERVICE_INFO, "url": get_service_url(SERVICE_ARTIFACT)}, - } - def get_service(service_artifact): # special case: requesting info about the current service. Avoids request timeout @@ -147,24 +141,30 @@ def chord_services(): return jsonify(chord_services_local) +def _services(): + return [s for s in ( + get_service(s["type"]["artifact"]) for s in CHORD_SERVICES + ) if s is not None] + + @application.route("/services") def services(): - return jsonify([s for s in (get_service(s["type"]["artifact"]) for s in CHORD_SERVICES) if s is not None]) + return jsonify(_services()) @application.route("/services/") def service_by_id(service_id): - services_by_id = {s["id"]: s for s in service_info_cache.values()} + services_by_id = {s["id"]: s for s in CHORD_SERVICES.values()} if service_id not in services_by_id: return flask_not_found_error(f"Service with ID {service_id} was not found in registry") - service_artifact = services_by_id[service_id]["type"].split(":")[1] + service_artifact = services_by_id[service_id]["type"]["artifact"] return get_service(service_artifact) @application.route("/services/types") def service_types(): - return jsonify(sorted(set(s["type"] for s in service_info_cache.values()))) + return jsonify(sorted(set(s["type"] for s in _services().values()))) def _service_info(): From 77fe8f4cd8046d4dcf9ef12cabdc2d34fe820e8a Mon Sep 17 00:00:00 2001 From: Paul Pillot Date: Tue, 27 Sep 2022 11:45:25 -0400 Subject: [PATCH 07/13] DRY code, avoid constant for CHORD_SERVICES --- bento_service_registry/app.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/bento_service_registry/app.py b/bento_service_registry/app.py index 09c54a6..9bfe4ca 100644 --- a/bento_service_registry/app.py +++ b/bento_service_registry/app.py @@ -48,6 +48,20 @@ def get_service_url(artifact: str): return urljoin(current_app.config["CHORD_URL"], current_app.config["URL_PATH_FORMAT"].format(artifact=artifact)) +def get_chord_services(): + """ + Reads the list of services from the chord_services.json file + """ + services = [] + try: + with open(current_app.config["CHORD_SERVICES"], "r") as f: + services = [s for s in json.load(f) if not s.get("disabled")] # Skip disabled services + except Exception as e: + except_name = type(e).__name__ + print("Error in retrieving services information from json file.", except_name) + return services + + with application.app_context(): SERVICE_ID = current_app.config["SERVICE_ID"] SERVICE_INFO = { @@ -65,8 +79,7 @@ def get_service_url(artifact: str): "environment": "prod" } - with open(current_app.config["CHORD_SERVICES"], "r") as f: - CHORD_SERVICES = [s for s in json.load(f) if not s.get("disabled")] # Skip disabled services + chord_services = get_chord_services() # Not a constant: can change when a service is updated def get_service(service_artifact): @@ -131,19 +144,12 @@ def before_first_request_func(): @application.route("/bento-services") @application.route("/chord-services") def chord_services(): - # execute this in here allows to update the version of the services from chord-services - try: - with open(current_app.config["CHORD_SERVICES"], "r") as f: - chord_services_local = [s for s in json.load(f) if not s.get("disabled")] # Skip disabled services - except Exception as e: - except_name = type(e).__name__ - print("Error in dev-mode retrieving chord information", except_name) - return jsonify(chord_services_local) + jsonify(get_chord_services()) def _services(): return [s for s in ( - get_service(s["type"]["artifact"]) for s in CHORD_SERVICES + get_service(s["type"]["artifact"]) for s in chord_services ) if s is not None] @@ -154,7 +160,7 @@ def services(): @application.route("/services/") def service_by_id(service_id): - services_by_id = {s["id"]: s for s in CHORD_SERVICES.values()} + services_by_id = {s["id"]: s for s in chord_services.values()} if service_id not in services_by_id: return flask_not_found_error(f"Service with ID {service_id} was not found in registry") From 246f08c833fdd836431152907dc1fb84000f3241 Mon Sep 17 00:00:00 2001 From: Paul Pillot Date: Mon, 3 Oct 2022 11:07:53 -0400 Subject: [PATCH 08/13] fix: global var name and function name conflict --- bento_service_registry/app.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/bento_service_registry/app.py b/bento_service_registry/app.py index 9bfe4ca..bab7fd4 100644 --- a/bento_service_registry/app.py +++ b/bento_service_registry/app.py @@ -79,7 +79,8 @@ def get_chord_services(): "environment": "prod" } - chord_services = get_chord_services() # Not a constant: can change when a service is updated + chord_services_content = get_chord_services() # Not a constant: can change when a service is updated + def get_service(service_artifact): @@ -149,7 +150,7 @@ def chord_services(): def _services(): return [s for s in ( - get_service(s["type"]["artifact"]) for s in chord_services + get_service(s["type"]["artifact"]) for s in chord_services_content ) if s is not None] @@ -160,7 +161,7 @@ def services(): @application.route("/services/") def service_by_id(service_id): - services_by_id = {s["id"]: s for s in chord_services.values()} + services_by_id = {s["id"]: s for s in chord_services_content.values()} if service_id not in services_by_id: return flask_not_found_error(f"Service with ID {service_id} was not found in registry") From 3f04daf89f86066c1f3c2886147e1df99cd8ef56 Mon Sep 17 00:00:00 2001 From: Paul Pillot Date: Mon, 3 Oct 2022 17:42:15 -0400 Subject: [PATCH 09/13] Fixes consecutive to cache removal --- bento_service_registry/app.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bento_service_registry/app.py b/bento_service_registry/app.py index bab7fd4..2e24abb 100644 --- a/bento_service_registry/app.py +++ b/bento_service_registry/app.py @@ -145,7 +145,7 @@ def before_first_request_func(): @application.route("/bento-services") @application.route("/chord-services") def chord_services(): - jsonify(get_chord_services()) + return jsonify(get_chord_services()) def _services(): @@ -161,17 +161,17 @@ def services(): @application.route("/services/") def service_by_id(service_id): - services_by_id = {s["id"]: s for s in chord_services_content.values()} + services_by_id = {s["id"]: s for s in _services()} if service_id not in services_by_id: return flask_not_found_error(f"Service with ID {service_id} was not found in registry") - service_artifact = services_by_id[service_id]["type"]["artifact"] + service_artifact = services_by_id[service_id]["type"].split(":")[1] return get_service(service_artifact) @application.route("/services/types") def service_types(): - return jsonify(sorted(set(s["type"] for s in _services().values()))) + return jsonify(sorted(set(s["type"] for s in _services()))) def _service_info(): From e50cac91e3425fb5a5b7a1bd8f993fa00d189afc Mon Sep 17 00:00:00 2001 From: Paul Pillot Date: Mon, 3 Oct 2022 17:42:46 -0400 Subject: [PATCH 10/13] prevent dev mode in testing --- tests/conftest.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/conftest.py b/tests/conftest.py index 57233ca..65b0211 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -5,6 +5,7 @@ def _setup_env(): os.environ["CHORD_SERVICES"] = os.path.join(os.path.dirname(__file__), "chord_services.json") os.environ["URL_PATH_FORMAT"] = "" # Mount off of root URL for testing + os.environ["CHORD_DEBUG"] = "" @pytest.fixture() From 6faf969f0214177070aa5698f0143aa2e5f9df67 Mon Sep 17 00:00:00 2001 From: Paul Pillot Date: Mon, 3 Oct 2022 17:43:43 -0400 Subject: [PATCH 11/13] fix tests The url override was unnecessary and beaking the tests --- tests/test_api.py | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/tests/test_api.py b/tests/test_api.py index dff3ced..56e5a26 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -6,7 +6,7 @@ def test_service_info(client, service_info): d = r.get_json() # TODO: Check against service-info schema assert r.status_code == 200 - assert json.dumps(d, sort_keys=True) == json.dumps(service_info, sort_keys=True) + assert d == service_info def test_chord_service_list(client): @@ -22,20 +22,14 @@ def test_service_list(client, service_info): d = r.get_json() assert r.status_code == 200 assert len(d) == 1 - assert json.dumps(d[0], sort_keys=True) == json.dumps({ - **service_info, - "url": "http://127.0.0.1:5000/" - }, sort_keys=True) + assert d[0] == service_info def test_service_detail(client, service_info): r = client.get(f"/services/{service_info['id']}") d = r.get_json() assert r.status_code == 200 - assert json.dumps(d, sort_keys=True) == json.dumps({ - **service_info, - "url": "http://127.0.0.1:5000/" - }, sort_keys=True) + assert d == service_info r = client.get("/services/does-not-exist") assert r.status_code == 404 From 5ffbef2ea4797222583591e8f947bbf2f2cb7af8 Mon Sep 17 00:00:00 2001 From: Paul Pillot Date: Mon, 3 Oct 2022 17:50:23 -0400 Subject: [PATCH 12/13] linting --- bento_service_registry/app.py | 6 +++--- tests/test_api.py | 3 --- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/bento_service_registry/app.py b/bento_service_registry/app.py index 2e24abb..42a2993 100644 --- a/bento_service_registry/app.py +++ b/bento_service_registry/app.py @@ -82,7 +82,6 @@ def get_chord_services(): chord_services_content = get_chord_services() # Not a constant: can change when a service is updated - def get_service(service_artifact): # special case: requesting info about the current service. Avoids request timeout # when running gunicorn on a single worker @@ -110,13 +109,13 @@ def get_service(service_artifact): if r.status_code != 200: print(f"[{SERVICE_NAME}] Non-200 status code on {service_artifact}: {r.status_code}\n" - f" Content: {r.text}", file=sys.stderr, flush=True) + f" Content: {r.text}", file=sys.stderr, flush=True) # If we have the special case where we got a JWT error from the proxy script, we can safely print out # headers for debugging, since the JWT leaked isn't valid anyway. if "invalid jwt" in r.text: print(f" Encountered auth error, tried to use header: {auth_header}", - file=sys.stderr, flush=True) + file=sys.stderr, flush=True) return None @@ -196,6 +195,7 @@ def _service_info(): return info # updated service info with the git info + @application.route("/service-info") def service_info(): # Spec: https://github.com/ga4gh-discovery/ga4gh-service-info diff --git a/tests/test_api.py b/tests/test_api.py index 56e5a26..318c445 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -1,6 +1,3 @@ -import json - - def test_service_info(client, service_info): r = client.get("/service-info") d = r.get_json() From e9a47892d575f41f76267f605d2931e373135f1c Mon Sep 17 00:00:00 2001 From: noctillion Date: Tue, 4 Oct 2022 16:06:47 -0400 Subject: [PATCH 13/13] Bump version number --- bento_service_registry/package.cfg | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bento_service_registry/package.cfg b/bento_service_registry/package.cfg index 31c82f2..06fd754 100644 --- a/bento_service_registry/package.cfg +++ b/bento_service_registry/package.cfg @@ -1,5 +1,5 @@ [package] name = bento_service_registry -version = 0.5.1 +version = 0.6.0 authors = David Lougheed author_emails = david.lougheed@mail.mcgill.ca