Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
Merge pull request #238 from CSCfi/dev
Browse files Browse the repository at this point in the history
release 1.9.0
  • Loading branch information
blankdots committed Jan 3, 2022
2 parents 08ea07b + 462f575 commit 04f3681
Show file tree
Hide file tree
Showing 35 changed files with 1,073 additions and 1,083 deletions.
7 changes: 3 additions & 4 deletions .github/workflows/docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,9 @@ jobs:
runs-on: ${{ matrix.os }}

steps:
- name: Spell check install
run: curl -L https://git.io/misspell | bash
- name: Spell check docs
run: bin/misspell -error docs/*
- uses: actions/checkout@master
- uses: rojopolis/spellcheck-github-actions@0.20.0
name: Spellcheck

code_docs:
strategy:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/s2i-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:

- name: Install requirements
run: |
wget https://github.com/openshift/source-to-image/releases/download/v1.2.0/source-to-image-v1.2.0-2a579ecd-linux-amd64.tar.gz
tar -xvf source-to-image-v1.2.0-2a579ecd-linux-amd64.tar.gz
wget https://github.com/openshift/source-to-image/releases/download/v1.3.1/source-to-image-v1.3.1-a5a77147-linux-amd64.tar.gz
tar -xvf source-to-image-v1.3.1-a5a77147-linux-amd64.tar.gz
sudo cp s2i /usr/local/bin
- name: Build image
run: |
s2i build . centos/python-36-centos7 cscfi/beacon-python
s2i build . centos/python-38-centos7 cscfi/beacon-python
4 changes: 3 additions & 1 deletion .github/workflows/style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,11 @@ jobs:
run: tox -e flake8
- name: Do bandit static check with tox
run: tox -e bandit
- name: Black formatting check
run: tox -e black
- name: Install libcurl-devel
run: |
sudo apt-get update
sudo apt-get install libcurl4-openssl-dev
- name: Do typing check with tox
- name: Type hints check
run: tox -e mypy
27 changes: 27 additions & 0 deletions .spellcheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
matrix:
- name: Markdown
aspell:
lang: en
dictionary:
wordlists:
- .wordlist.txt
encoding: utf-8
pipeline:
- pyspelling.filters.markdown:
- pyspelling.filters.context:
context_visible_first: true
escapes: '\\[\\`~]'
delimiters:
# Ignore text between inline back ticks as this is code or hightlight words
- open: '(?P<open>`+)'
close: '(?P=open)'
# Ignore surrounded in <> as in RST it is link
- open: '<([A-Za-z0-9-_:.]+)|(https?://[^\\s/$.?#].[^\\s]+|[A-Za-z0-9-_:.]+)'
close: '>'
# Ignore code in RST starting with $
- open: '\$.+'
close: ''
sources:
- 'docs/*.rst'
- '**/*.md'
default_encoding: utf-8
144 changes: 144 additions & 0 deletions .wordlist.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
AAI
accessType
aiohttp
alleleCount
alleleRequest
alternateBases
alternativeUrl
api
APIBehavior
APITest
apiVersion
assemblyId
automodule
autosummary
beacondb
beaconId
beaconpy
BND
BONA
btree
callCount
cd
chr
CHR
claimName
conf
config
contactUrl
containerPort
createdAt
createDateTime
csc
CSC
cscfi
CSCfi
datafile
datafiles
dataloader
dataset
DATASET
datasetAlleleResponses
datasetHandover
datasetId
datasetIds
datasets
dedent
documentationUrl
ebi
ega
EGA
endMax
endMin
env
ENV
Espoo
examplebrowser
exampleid
externalUrl
fi
FIDE
finland
ga
genomic
gh
GH
GHBeacon
github
GRCh
Gunicorn
GunicornUVLoopWebWorker
handoverType
hg
hostPath
html
http
HttpLocust
https
ICT
ietf
imagePullPolicy
includeDatasetResponses
ini
init
io
javascript
jpg
json
JSON
JWK
jwt
JWT
Keilaranta
literalinclude
localhost
logoUrl
matchLabels
mateID
mateName
mateStart
mountPath
namespace
NodePort
OAuth
orgInfo
persistentVolumeClaim
pgtune
postgres
POSTGRES
py
readthedocs
referenceBases
referenceID
referenceName
restartPolicy
rfc
RGB
sampleAlleleRequests
sampleCount
schemas
secretKeyRef
SNP
sql
startMax
startMin
targetPort
TaskSet
TCP
toctree
txt
ua
uk
updatedAt
updateDateTime
uri
url
utils
valueFrom
variantCount
varianttype
variantType
vcf
volumeMounts
welcomeUrl
www
16 changes: 9 additions & 7 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
FROM python:3.8-alpine3.13 as BUILD
FROM python:3.8-alpine3.15 as BUILD

RUN apk add --update \
&& apk add --no-cache build-base curl-dev linux-headers bash git musl-dev\
&& apk add --no-cache libressl-dev libffi-dev autoconf bzip2-dev xz-dev\
&& apk add --no-cache openssl-dev libffi-dev autoconf bzip2-dev xz-dev\
&& apk add --no-cache python3-dev rust cargo \
&& rm -rf /var/cache/apk/*

COPY requirements.txt /root/beacon/requirements.txt
COPY setup.py /root/beacon/setup.py
COPY beacon_api /root/beacon/beacon_api

ENV CYTHONIZE=1

RUN pip install --upgrade pip && \
pip install -r /root/beacon/requirements.txt && \
pip install /root/beacon
pip install Cython==0.29.26 && \
pip install -r /root/beacon/requirements.txt

COPY setup.py /root/beacon/setup.py
COPY beacon_api /root/beacon/beacon_api
RUN pip install /root/beacon

FROM python:3.8-alpine3.13
FROM python:3.8-alpine3.15

RUN apk add --no-cache --update bash

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ Documentation: https://beacon-python.readthedocs.io
### Quick start

`beacon-python` Web Server requires:
* Python 3.6+;
* running DB [PostgreSQL Server](https://www.postgresql.org/) 9.6+ (recommended 11.6).
* Python 3.8+;
* running DB [PostgreSQL Server](https://www.postgresql.org/) 9.6+ (recommended 13).

```shell
git clone https://github.com/CSCfi/beacon-python
Expand All @@ -30,7 +30,7 @@ docker run -e POSTGRES_USER=beacon \
-e POSTGRES_PASSWORD=beacon \
-v "$PWD/data":/docker-entrypoint-initdb.d \
-e POSTGRES_DB=beacondb \
-p 5432:5432 postgres:11.6
-p 5432:5432 postgres:13
```

#### Run beacon-python
Expand Down
8 changes: 3 additions & 5 deletions beacon_api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
__url__ = CONFIG_INFO.url
__alturl__ = CONFIG_INFO.alturl
__createtime__ = CONFIG_INFO.createtime
__updatetime__ = datetime.datetime.now().strftime('%Y-%m-%dT%H:%M:%SZ') # Every restart of the application means an update to it
__updatetime__ = datetime.datetime.now().strftime("%Y-%m-%dT%H:%M:%SZ") # Every restart of the application means an update to it

__org_id__ = CONFIG_INFO.org_id
__org_name__ = CONFIG_INFO.org_name
Expand All @@ -33,12 +33,10 @@
__org_welcomeUrl__ = CONFIG_INFO.org_welcomeUrl
__org_contactUrl__ = CONFIG_INFO.org_contactUrl
__org_logoUrl__ = CONFIG_INFO.org_logoUrl
__org_info__ = {'orgInfo': CONFIG_INFO.org_info}
__org_info__ = {"orgInfo": CONFIG_INFO.org_info}

__sample_queries__ = SAMPLE_QUERIES

# GA4GH Discovery
__service_type__ = {'group': f'{CONFIG_INFO.service_group}',
'artifact': f'{CONFIG_INFO.service_artifact}',
'version': f'{__apiVersion__}'}
__service_type__ = {"group": f"{CONFIG_INFO.service_group}", "artifact": f"{CONFIG_INFO.service_artifact}", "version": f"{__apiVersion__}"}
__service_env__ = CONFIG_INFO.environment
28 changes: 17 additions & 11 deletions beacon_api/api/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
API specification requires custom messages upon error.
"""

import json
import ujson
from typing import Dict
from aiohttp import web
from .. import __apiVersion__
Expand Down Expand Up @@ -35,7 +35,17 @@ def process_exception_data(request: Dict, host: str, error_code: int, error: str
# include datasetIds only if they are specified
# as per specification if they don't exist all datatsets will be queried
# Only one of `alternateBases` or `variantType` is required, validated by schema
oneof_fields = ["alternateBases", "variantType", "start", "end", "startMin", "startMax", "endMin", "endMax", "datasetIds"]
oneof_fields = [
"alternateBases",
"variantType",
"start",
"end",
"startMin",
"startMax",
"endMin",
"endMax",
"datasetIds",
]
data["alleleRequest"].update({k: request.get(k) for k in oneof_fields if k in request})

return data
Expand All @@ -51,7 +61,7 @@ class BeaconBadRequest(web.HTTPBadRequest):
def __init__(self, request: Dict, host: str, error: str) -> None:
"""Return custom bad request exception."""
data = process_exception_data(request, host, 400, error)
super().__init__(text=json.dumps(data), content_type="application/json")
super().__init__(text=ujson.dumps(data, escape_forward_slashes=False), content_type="application/json")
LOG.error(f"401 ERROR MESSAGE: {error}")


Expand All @@ -65,14 +75,10 @@ class BeaconUnauthorised(web.HTTPUnauthorized):
def __init__(self, request: Dict, host: str, error: str, error_message: str) -> None:
"""Return custom unauthorized exception."""
data = process_exception_data(request, host, 401, error)
headers_401 = {
"WWW-Authenticate": f'Bearer realm="{CONFIG_INFO.url}"\n\
error="{error}"\n\
error_description="{error_message}"'
}
headers_401 = {"WWW-Authenticate": f"""Bearer realm=\"{CONFIG_INFO.url}\",error=\"{error},\" error_description=\"{error_message}\""""}
super().__init__(
content_type="application/json",
text=json.dumps(data),
text=ujson.dumps(data, escape_forward_slashes=False),
# we use auth scheme Bearer by default
headers=headers_401,
)
Expand All @@ -90,7 +96,7 @@ class BeaconForbidden(web.HTTPForbidden):
def __init__(self, request: Dict, host: str, error: str) -> None:
"""Return custom forbidden exception."""
data = process_exception_data(request, host, 403, error)
super().__init__(content_type="application/json", text=json.dumps(data))
super().__init__(content_type="application/json", text=ujson.dumps(data, escape_forward_slashes=False))
LOG.error(f"403 ERROR MESSAGE: {error}")


Expand All @@ -103,5 +109,5 @@ class BeaconServerError(web.HTTPInternalServerError):
def __init__(self, error: str) -> None:
"""Return custom forbidden exception."""
data = {"errorCode": 500, "errorMessage": error}
super().__init__(content_type="application/json", text=json.dumps(data))
super().__init__(content_type="application/json", text=ujson.dumps(data, escape_forward_slashes=False))
LOG.error(f"500 ERROR MESSAGE: {error}")

0 comments on commit 04f3681

Please sign in to comment.