Skip to content

Commit

Permalink
Merge pull request #44 from bento-platform/develop
Browse files Browse the repository at this point in the history
Version 0.10.0
  • Loading branch information
davidlougheed authored Jun 11, 2020
2 parents affdb66 + 3a358dc commit 44649e6
Show file tree
Hide file tree
Showing 44 changed files with 178 additions and 164 deletions.
4 changes: 2 additions & 2 deletions .idea/chord_lib.iml → .idea/bento_lib.iml

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

4 changes: 2 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
include chord_lib/schemas/*.json
include chord_lib/package.cfg
include bento_lib/schemas/*.json
include bento_lib/package.cfg
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# CHORD Library (for Python CHORD microservices)
# Bento Library (for Python Bento microservices)

![Build Status](https://api.travis-ci.org/c3g/chord_lib.svg?branch=master)
[![codecov](https://codecov.io/gh/c3g/chord_lib/branch/master/graph/badge.svg)](https://codecov.io/gh/c3g/chord_lib)
[![PyPI version](https://badge.fury.io/py/chord-lib.svg)](https://badge.fury.io/py/chord-lib)
![Build Status](https://api.travis-ci.org/bento-platform/bento_lib.svg?branch=master)
[![codecov](https://codecov.io/gh/bento-platform/bento_lib/branch/master/graph/badge.svg)](https://codecov.io/gh/bento-platform/bento_lib)
[![PyPI version](https://badge.fury.io/py/bento-lib.svg)](https://badge.fury.io/py/bento-lib)

Common utilities and helpers for CHORD services.
Common utilities and helpers for Bento platform services.


## Running Tests
Expand All @@ -22,7 +22,7 @@ python3 -m tox
* [ ] All tests pass and test coverage has not been reduced

* [ ] Package version has been updated (following semver) in
`chord_lib/package.cfg`
`bento_lib/package.cfg`

* [ ] The latest changes have been merged from the `develop` branch into the
`master` branch
Expand All @@ -46,7 +46,7 @@ git pull
source env/bin/activate

# Remove existing build files
rm -rf build/ dist/ chord_lib.egg-info/
rm -rf build/ dist/ bento_lib.egg-info/

# Build the new package
python3 setup.py sdist bdist_wheel
Expand All @@ -64,58 +64,58 @@ twine upload dist/*
### `auth`

`auth` provides Python service decorators and Django / DRF backends for dealing
with the CHORD container authentication headers (derived from
with the Bento container authentication headers (derived from
`lua-resty-openidc`, set by the internal container NGINX instance.)

### `events`

`events` facilitates JSON-serialized message-passing between CHORD
`events` facilitates JSON-serialized message-passing between Bento
microservices. Serialized objects can be at most 512 MB.

Events should have a lower-case type which is type-insensitively unique and
adequately describes the associated data.

All CHORD channels are prefixed with `chord.`.
All Bento channels are prefixed with `bento.`.

### `ingestion`

`ingestion` contains common code used for handling ingestion routines in
different CHORD data services.
different Bento data services.

### `schemas`

`schemas` contains common JSON schemas which may be useful to a variety of
different CHORD services.
different Bento services.

`schemas.chord` contains CHORD-specific schemas, and `schemas.ga4gh` contains
`schemas.bento` contains Bento-specific schemas, and `schemas.ga4gh` contains
GA4GH-standardized schemas (possibly not exactly to spec.)

### `search`

`search` contains definitions, validators, and transformations for the query
syntax for CHORD, as well as a transpiler to the `psycopg2` PostgreSQL IR.
syntax for Bento, as well as a transpiler to the `psycopg2` PostgreSQL IR.

The query syntax for CHORD takes advantage of JSON schemas augmented with
The query syntax for Bento takes advantage of JSON schemas augmented with
additional properties about the field's accessibility and, in the case of
Postgres, how the field maps to a table column (or JSON column sub-field.)

`search.data_structure` contains code for evaluating a CHORD query against a
`search.data_structure` contains code for evaluating a Bento query against a
Python data structure.

`search.operations` contains constants representing valid search operations one
can allow against particular fields from within an augmented JSON schema.

`search.postgres` contains a "transpiler" from the CHORD query syntax to the
`search.postgres` contains a "transpiler" from the Bento query syntax to the
`psycopg2`-provided
[intermediate representation (IR)](https://www.psycopg.org/docs/sql.html) for
PostgreSQL, allowing safe queries against a Postgres database.

`search.queries` provides definitions for the CHORD query AST and some helper
`search.queries` provides definitions for the Bento query AST and some helper
methods for creating and processing ASTs.

### `utils`

`utils` contains miscellaneous utilities commonly required by CHORD services.
`utils` contains miscellaneous utilities commonly required by Bento services.

### `workflows`

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,26 @@
from django.contrib.auth.middleware import RemoteUserMiddleware
from rest_framework.authentication import RemoteUserAuthentication

from chord_lib.auth.headers import DJANGO_USER_HEADER, DJANGO_USER_ROLE_HEADER
from chord_lib.auth.roles import ROLE_OWNER, ROLE_USER
from bento_lib.auth.headers import DJANGO_USER_HEADER, DJANGO_USER_ROLE_HEADER
from bento_lib.auth.roles import ROLE_OWNER, ROLE_USER


__all__ = [
"CHORDRemoteUserAuthentication",
"CHORDRemoteUserBackend",
"CHORDRemoteUserMiddleware",
"BentoRemoteUserAuthentication",
"BentoRemoteUserBackend",
"BentoRemoteUserMiddleware",
]


class CHORDRemoteUserAuthentication(RemoteUserAuthentication):
class BentoRemoteUserAuthentication(RemoteUserAuthentication):
header = DJANGO_USER_HEADER


class CHORDRemoteUserMiddleware(RemoteUserMiddleware):
class BentoRemoteUserMiddleware(RemoteUserMiddleware):
header = DJANGO_USER_HEADER


class CHORDRemoteUserBackend(RemoteUserBackend):
class BentoRemoteUserBackend(RemoteUserBackend):
# noinspection PyMethodMayBeStatic
def configure_user(self, request, user):
is_owner = request.META.get(DJANGO_USER_ROLE_HEADER, ROLE_USER) == ROLE_OWNER
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
from functools import wraps
from typing import Union

from chord_lib.auth.headers import CHORD_USER_HEADER, CHORD_USER_ROLE_HEADER
from chord_lib.auth.roles import ROLE_OWNER, ROLE_USER
from chord_lib.responses.flask_errors import flask_forbidden_error
from bento_lib.auth.headers import BENTO_USER_HEADER, BENTO_USER_ROLE_HEADER
from bento_lib.auth.roles import ROLE_OWNER, ROLE_USER
from bento_lib.responses.flask_errors import flask_forbidden_error


__all__ = [
Expand All @@ -17,16 +17,16 @@


# TODO: Centralize this
CHORD_DEBUG = os.environ.get("CHORD_DEBUG", "true").lower() == "true"
CHORD_PERMISSIONS = os.environ.get("CHORD_PERMISSIONS", str(not CHORD_DEBUG)).lower() == "true"
BENTO_DEBUG = os.environ.get("CHORD_DEBUG", "true").lower() == "true"
BENTO_PERMISSIONS = os.environ.get("CHORD_PERMISSIONS", str(not BENTO_DEBUG)).lower() == "true"


def _check_roles(headers, roles: Union[set, dict]):
method_roles = roles if not isinstance(roles, dict) else roles.get(request.method, set())
return (
not CHORD_PERMISSIONS or
not BENTO_PERMISSIONS or
len(method_roles) == 0 or
(CHORD_USER_HEADER in headers and headers.get(CHORD_USER_ROLE_HEADER, "") in method_roles)
(BENTO_USER_HEADER in headers and headers.get(BENTO_USER_ROLE_HEADER, "") in method_roles)
)


Expand Down
18 changes: 18 additions & 0 deletions bento_lib/auth/headers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
__all__ = [
"BENTO_USER_HEADER",
"BENTO_USER_ROLE_HEADER",

"DJANGO_USER_HEADER",
"DJANGO_USER_ROLE_HEADER",
]


def _to_django_header(header: str):
return f"HTTP_{header.replace('-', '_').upper()}"


BENTO_USER_HEADER = "X-User"
BENTO_USER_ROLE_HEADER = "X-User-Role"

DJANGO_USER_HEADER = _to_django_header(BENTO_USER_HEADER)
DJANGO_USER_ROLE_HEADER = _to_django_header(BENTO_USER_ROLE_HEADER)
File renamed without changes.
8 changes: 4 additions & 4 deletions chord_lib/events/__init__.py → bento_lib/events/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
]


ALL_SERVICE_EVENTS = "chord.service.*"
ALL_DATA_TYPE_EVENTS = "chord.data_type.*"
ALL_SERVICE_EVENTS = "bento.service.*"
ALL_DATA_TYPE_EVENTS = "bento.data_type.*"

_SERVICE_CHANNEL_TPL = "chord.service.{}"
_DATA_TYPE_CHANNEL_TPL = "chord.data_type.{}"
_SERVICE_CHANNEL_TPL = "bento.service.{}"
_DATA_TYPE_CHANNEL_TPL = "bento.data_type.{}"


# Types
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions chord_lib/package.cfg → bento_lib/package.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[package]
name = chord_lib
version = 0.9.0
name = bento_lib
version = 0.10.0
authors = David Lougheed
author_emails = [email protected]
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ def _error_message(message):

def http_error(code: int, *errors):
if code not in HTTP_STATUS_CODES:
print(f"[CHORD Lib] Error: Could not find code {code} in valid HTTP status codes.")
print(f"[Bento Lib] Error: Could not find code {code} in valid HTTP status codes.")
code = 500
errors = (*errors, f"An invalid status code of {code} was specified by the service.")

if code < 400:
print(f"[CHORD Lib] Error: Code {code} is not an HTTP error code.")
print(f"[Bento Lib] Error: Code {code} is not an HTTP error code.")
code = 500
errors = (*errors, f"A non-error status code of {code} was specified by the service.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from functools import partial
from typing import Callable

from chord_lib.responses import errors
from bento_lib.responses import errors


__all__ = [
Expand All @@ -24,7 +24,7 @@
]


def flask_error_wrap_with_traceback(fn: Callable, service_name="CHORD Service") -> Callable:
def flask_error_wrap_with_traceback(fn: Callable, service_name="Bento Service") -> Callable:
"""
Function to wrap flask_* error creators with something that supports the application.register_error_handler method,
while also printing a traceback.
Expand Down
4 changes: 4 additions & 0 deletions bento_lib/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from . import bento
from . import ga4gh

__all__ = ["bento", "ga4gh"]
File renamed without changes.
13 changes: 13 additions & 0 deletions bento_lib/schemas/bento.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from ._utils import load_json_schema


__all__ = [
"BENTO_INGEST_SCHEMA",
"BENTO_DATA_USE_SCHEMA",
]


# TODO: Refactor this schema and semi-combine with workflow schema
BENTO_INGEST_SCHEMA = load_json_schema("bento_ingest.schema.json")

BENTO_DATA_USE_SCHEMA = load_json_schema("bento_data_use.schema.json")
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$id": "https://raw.githubusercontent.com/c3g/chord_lib/master/chord_lib/schemas/chord_data_use.schema.json",
"$id": "https://raw.githubusercontent.com/bento-platform/bento_lib/master/bento_lib/schemas/bento_data_use.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "CHORD Data Use File",
"title": "Bento Data Use File",
"description": "Schema defining data usage conditions from the GA4GH DUO ontology.",
"type": "object",
"properties": {
Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$id": "https://raw.githubusercontent.com/c3g/chord_lib/master/chord_lib/schemas/ga4gh_service_info.schema.json",
"$id": "https://raw.githubusercontent.com/bento-platform/bento_lib/master/bento_lib/schemas/ga4gh_service_info.schema.json",
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"properties": {
Expand Down
File renamed without changes.
5 changes: 5 additions & 0 deletions bento_lib/search/_types.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from typing import Dict

__all__ = ["JSONSchema"]

JSONSchema = Dict
Loading

0 comments on commit 44649e6

Please sign in to comment.