Skip to content

Commit

Permalink
Merge pull request #27 from c3g/develop
Browse files Browse the repository at this point in the history
Version 0.3.0
  • Loading branch information
davidlougheed authored Feb 17, 2020
2 parents 38a602b + 9e53197 commit 3215f62
Show file tree
Hide file tree
Showing 8 changed files with 550 additions and 130 deletions.
3 changes: 3 additions & 0 deletions .idea/dictionaries/dlougheed.xml

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

24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ python3 -m pytest --cov=chord_lib --cov-branch

## Modules

### `auth`

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

### `events`

`events` facilitates JSON-serialized message-passing between CHORD
Expand Down Expand Up @@ -44,6 +50,24 @@ GA4GH-standardized schemas (possibly not exactly to spec.)
`search` contains definitions, validators, and transformations for the query
syntax for CHORD, as well as a transpiler to the `psycopg2` PostgreSQL IR.

The query syntax for CHORD 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
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
`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
methods for creating and processing ASTs.

### `utils`

`utils` contains miscellaneous utilities commonly required by CHORD services.
Expand Down
35 changes: 34 additions & 1 deletion chord_lib/responses/flask_errors.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
import sys
import traceback

from flask import jsonify
from functools import partial
from typing import Callable

from .errors import *


__all__ = [
"flask_error_wrap_with_traceback",
"flask_error_wrap",

"flask_error",

"flask_bad_request_error",
Expand All @@ -16,11 +24,36 @@
]


def flask_error_wrap_with_traceback(fn: Callable, service_name="CHORD Service") -> Callable:
"""
Function to wrap flask_* error creators with something that supports the application.register_error_handler method,
while also printing a traceback.
:param fn: The flask error-generating function to wrap
:param service_name: The name of the service (for logging purposes)
:return: The wrapped function
"""
# TODO: pass exception?
def handle_error(_e):
print(f"[{service_name}] Encountered error:", file=sys.stderr)
traceback.print_exc()
return fn()
return handle_error


def flask_error_wrap(fn: Callable) -> Callable:
"""
Function to wrap flask_* error creators with something that supports the application.register_error_handler method.
:param fn: The flask error-generating function to wrap
:return: The wrapped function
"""
return lambda _e: fn()


def flask_error(code: int, *errors):
return jsonify(http_error(code, *errors)), code


def _flask_error(code: int):
def _flask_error(code: int) -> Callable:
return partial(flask_error, code)


Expand Down
Loading

0 comments on commit 3215f62

Please sign in to comment.