Skip to content

Commit

Permalink
Merge pull request #27 from bento-platform/chore/update-bento-lib
Browse files Browse the repository at this point in the history
chore: update bento_lib to 11.6
  • Loading branch information
davidlougheed authored Apr 29, 2024
2 parents 0e81bb8 + 130d7d3 commit bded95e
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 61 deletions.
1 change: 1 addition & 0 deletions bento_notification_service/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ def _get_from_environ_or_fail(var: str, logger: logging.Logger = logger_) -> str

class Config:
BENTO_DEBUG = os.environ.get("BENTO_DEBUG", "false").strip().lower() in TRUTH_VALUES
BENTO_CONTAINER_LOCAL = os.environ.get("BENTO_CONTAINER_LOCAL", "false").strip().lower() in TRUTH_VALUES

SQLALCHEMY_DATABASE_URI = "sqlite:///" + os.path.join(BASEDIR, "db.sqlite3")
SQLALCHEMY_TRACK_MODIFICATIONS = False
Expand Down
2 changes: 1 addition & 1 deletion bento_notification_service/constants.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import os

from bento_lib.types import GA4GHServiceType, GA4GHServiceOrganization
from bento_lib.service_info.types import GA4GHServiceType, GA4GHServiceOrganization
from pathlib import Path

from . import __version__
Expand Down
37 changes: 8 additions & 29 deletions bento_notification_service/routes.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
import subprocess
import uuid

from asgiref.sync import async_to_sync
from bento_lib.auth.permissions import P_VIEW_NOTIFICATIONS
from bento_lib.auth.resources import RESOURCE_EVERYTHING
from bento_lib.responses.flask_errors import flask_not_found_error
from bento_lib.service_info.helpers import build_service_info
from flask import Blueprint, current_app, jsonify

from . import __version__
from .authz import authz_middleware
from .db import db
from .constants import BENTO_SERVICE_KIND, SERVICE_NAME, SERVICE_TYPE, ORG_C3G
from .logger import logger
from .models import Notification


PERMISSION_SET_VIEW = frozenset({P_VIEW_NOTIFICATIONS})

notification_service = Blueprint("notification_service", __name__)

build_service_info_sync = async_to_sync(build_service_info)


@notification_service.route("/notifications", methods=["GET"])
@authz_middleware.deco_require_permissions_on_resource(PERMISSION_SET_VIEW, RESOURCE_EVERYTHING)
Expand Down Expand Up @@ -63,41 +67,16 @@ def notification_read(n_id: uuid.UUID):
@notification_service.route("/service-info", methods=["GET"])
@authz_middleware.deco_public_endpoint
def service_info():
bento_debug = current_app.config["BENTO_DEBUG"]

# Spec: https://github.com/ga4gh-discovery/ga4gh-service-info
info = {
return build_service_info_sync({
"id": current_app.config["SERVICE_ID"],
"name": SERVICE_NAME,
"type": SERVICE_TYPE,
"description": "Notification service for a Bento platform node.",
"organization": ORG_C3G,
"contactUrl": "mailto:info@c3g.ca",
"version": __version__,
"environment": "dev" if bento_debug else "prod",
"bento": {
"serviceKind": BENTO_SERVICE_KIND,
"gitRepository": "https://github.com/bento-platform/bento_notification_service",
},
}

if not bento_debug:
return jsonify(info)

try:
if res_tag := subprocess.check_output(["git", "describe", "--tags", "--abbrev=0"]):
res_tag_str = res_tag.decode().rstrip()
# noinspection PyTypeChecker
info["bento"]["gitTag"] = res_tag_str
if res_branch := subprocess.check_output(["git", "branch", "--show-current"]):
res_branch_str = res_branch.decode().rstrip()
# noinspection PyTypeChecker
info["bento"]["gitBranch"] = res_branch_str
if res_commit := subprocess.check_output(["git", "rev-parse", "HEAD"]):
res_commit_str = res_commit.decode().rstrip()
# noinspection PyTypeChecker
info["bento"]["gitCommit"] = res_commit_str
except Exception as e:
except_name = type(e).__name__
current_app.logger.info(f"Could not retrieve git information: {str(except_name)}: {e}")

return jsonify(info)
}, debug=current_app.config["BENTO_DEBUG"], local=current_app.config["BENTO_CONTAINER_LOCAL"], logger=logger)
3 changes: 3 additions & 0 deletions dev.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ COPY run.dev.bash .
RUN poetry config virtualenvs.create false && \
poetry install --no-root

# Tell the service that we're running a local development container
ENV BENTO_CONTAINER_LOCAL=true

# Don't include actual code in the development image - will be mounted in using a volume.

# Run
Expand Down
122 changes: 93 additions & 29 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,14 @@ classifiers = [

[tool.poetry.dependencies]
python = "^3.10.0"
bento-lib = {version = "^9.1.0", extras = ["flask"]}
bento-lib = {version = "^11.6.0", extras = ["flask"]}
Flask-Migrate = "^4.0.5"
Flask = "~2.2.5"
flask-sqlalchemy = "^3.0.5"
flask-sqlalchemy = "~3.0.5"
SQLAlchemy = "^1.4.49"
werkzeug = "~2.2.3"
flask-cors = "^4.0.0"
asgiref = "^3.8.1"

[tool.poetry.group.dev.dependencies]
tox = "^4.11.3"
Expand Down

0 comments on commit bded95e

Please sign in to comment.