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

Commit 49c2201

Browse files
authored
Merge pull request #155 from CSCfi/dev
Dev
2 parents 6310ba4 + 3d71ef0 commit 49c2201

32 files changed

Lines changed: 1301 additions & 1220 deletions

.github/workflows/docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,9 @@ jobs:
2727
runs-on: ${{ matrix.os }}
2828

2929
steps:
30-
- uses: actions/checkout@v1
30+
- uses: actions/checkout@v2
3131
- name: Set up Python ${{ matrix.python-version }}
32-
uses: actions/setup-python@v1
32+
uses: actions/setup-python@v2
3333
with:
3434
python-version: ${{ matrix.python-version }}
3535
- name: Install dependencies

.github/workflows/int.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ jobs:
1515
name: Integration Tests
1616

1717
steps:
18-
- uses: actions/checkout@v1
18+
- uses: actions/checkout@v2
1919
- name: Set up Python ${{ matrix.python-version }}
20-
uses: actions/setup-python@v1
20+
uses: actions/setup-python@v2
2121
with:
2222
python-version: ${{ matrix.python-version }}
2323
- name: Install requirements

.github/workflows/publish.yml

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -8,50 +8,67 @@ on:
88

99
jobs:
1010
push_to_registry:
11-
name: Push Beacon Docker image to Docker Hub
11+
name: Push beacon python Docker image to Docker Hub
1212
runs-on: ubuntu-latest
1313
steps:
14-
- uses: actions/checkout@v1
15-
- name: Login to DockerHub Registry
16-
run: echo '${{ secrets.DOCKER_PASSWORD }}' | docker login -u '${{ secrets.DOCKER_USERNAME }}' --password-stdin
17-
- name: Get the version
18-
id: vars
19-
run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
20-
- name: Build the tagged Docker image
21-
if: ${{ steps.vars.outputs.tag != '/master' }}
22-
run: docker build . --file Dockerfile --tag cscfi/beacon-python:${{steps.vars.outputs.tag}}
23-
- name: Push the tagged Docker image
24-
if: ${{ steps.vars.outputs.tag != '/master' }}
25-
run: docker push cscfi/beacon-python:${{steps.vars.outputs.tag}}
26-
- name: Build the latest Docker image
27-
if: ${{ steps.vars.outputs.tag == '/master' }}
28-
run: docker build . --file Dockerfile --tag cscfi/beacon-python:latest
29-
- name: Push the latest Docker image
30-
if: ${{ steps.vars.outputs.tag == '/master' }}
31-
run: docker push cscfi/beacon-python:latest
32-
push_data_to_registry:
33-
name: Push Dataloader Docker image to Docker Hub
34-
runs-on: ubuntu-latest
35-
steps:
36-
- uses: actions/checkout@v1
37-
- name: Login to DockerHub Registry
38-
run: echo '${{ secrets.DOCKER_PASSWORD }}' | docker login -u '${{ secrets.DOCKER_USERNAME }}' --password-stdin
39-
- name: Get the version
40-
id: vars
41-
run: echo ::set-output name=tag::$(echo ${GITHUB_REF:10})
42-
- name: Build the tagged Docker image
43-
if: ${{ steps.vars.outputs.tag != '/master' }}
44-
run: |
45-
pushd deploy/dataloader
46-
docker build . --file Dockerfile --tag cscfi/beacon-dataloader:${{steps.vars.outputs.tag}}
47-
- name: Push the tagged Docker image
48-
if: ${{ steps.vars.outputs.tag != '/master' }}
49-
run: docker push cscfi/beacon-dataloader:${{steps.vars.outputs.tag}}
50-
- name: Build the latest Docker image
51-
if: ${{ steps.vars.outputs.tag == '/master' }}
14+
- name: Check out the repo
15+
uses: actions/checkout@v2
16+
17+
- name: Prepare
18+
id: prep
5219
run: |
53-
pushd deploy/dataloader
54-
docker build . --file Dockerfile --tag cscfi/beacon-dataloader:latest
55-
- name: Push the latest Docker image
56-
if: ${{ steps.vars.outputs.tag == '/master' }}
57-
run: docker push cscfi/beacon-dataloader:latest
20+
DOCKER_IMAGE=cscfi/beacon-python
21+
DOCKER_IMAGE_DATA=cscfi/beacon-python
22+
VERSION=edge
23+
if [[ $GITHUB_REF == refs/tags/* ]]; then
24+
VERSION=${GITHUB_REF#refs/tags/}
25+
elif [[ $GITHUB_REF == refs/heads/* ]]; then
26+
BRANCH=$(echo ${GITHUB_REF#refs/heads/} | sed -r 's#/+#-#g')
27+
if [[ $BRANCH == master ]]; then
28+
VERSION=latest
29+
fi
30+
fi
31+
TAGS="${DOCKER_IMAGE}:${VERSION}"
32+
TAGS_DATA="${DOCKER_IMAGE_DATA}:${VERSION}"
33+
echo ::set-output name=version::${VERSION}
34+
echo ::set-output name=tags::${TAGS}
35+
echo ::set-output name=tagsData::${TAGS_DATA}
36+
echo ::set-output name=created::$(date -u +'%Y-%m-%dT%H:%M:%SZ')
37+
38+
- name: Set up Docker Buildx
39+
uses: docker/setup-buildx-action@v1
40+
41+
- name: Login to DockerHub
42+
if: github.event_name != 'pull_request'
43+
uses: docker/login-action@v1
44+
with:
45+
username: ${{ secrets.DOCKER_USERNAME }}
46+
password: ${{ secrets.DOCKER_PASSWORD }}
47+
48+
- name: Build and push
49+
uses: docker/build-push-action@v2
50+
with:
51+
context: .
52+
file: ./Dockerfile
53+
push: ${{ github.event_name != 'pull_request' }}
54+
tags: ${{ steps.prep.outputs.tags }}
55+
cache-from: type=registry,ref=cscfi/beacon-python:latest
56+
cache-to: type=inline
57+
labels: |
58+
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
59+
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
60+
org.opencontainers.image.revision=${{ github.sha }}
61+
62+
- name: Build and push dataloader
63+
uses: docker/build-push-action@v2
64+
with:
65+
context: .
66+
file: ./deploy/dataloader/Dockerfile
67+
push: ${{ github.event_name != 'pull_request' }}
68+
tags: ${{ steps.prep.outputs.tagsData }}
69+
cache-from: type=registry,ref=cscfi/beacon-dataloader:latest
70+
cache-to: type=inline
71+
labels: |
72+
org.opencontainers.image.source=${{ github.event.repository.clone_url }}
73+
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
74+
org.opencontainers.image.revision=${{ github.sha }}

.github/workflows/style.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ jobs:
88
max-parallel: 4
99
matrix:
1010
os: [ubuntu-latest]
11-
python-version: [3.6, 3.7]
11+
python-version: [3.7]
1212

1313
runs-on: ${{ matrix.os }}
1414

1515
steps:
16-
- uses: actions/checkout@v1
16+
- uses: actions/checkout@v2
1717
- name: Set up Python ${{ matrix.python-version }}
1818
uses: actions/setup-python@v2
1919
with:

.github/workflows/unit.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,12 @@ jobs:
88
max-parallel: 4
99
matrix:
1010
os: [ubuntu-latest]
11-
python-version: [3.6, 3.7.7]
11+
python-version: [3.7.7]
1212

1313
runs-on: ${{ matrix.os }}
1414

1515
steps:
16-
- uses: actions/checkout@v1
16+
- uses: actions/checkout@v2
1717
- name: Set up Python ${{ matrix.python-version }}
1818
uses: actions/setup-python@v2
1919
with:

beacon_api/api/exceptions.py

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,32 @@
1111
from ..conf import CONFIG_INFO
1212

1313

14-
def process_exception_data(request: Dict,
15-
host: str,
16-
error_code: int,
17-
error: str) -> Dict:
14+
def process_exception_data(request: Dict, host: str, error_code: int, error: str) -> Dict:
1815
"""Return request data as dictionary.
1916
2017
Generates custom exception messages based on request parameters.
2118
"""
22-
data = {'beaconId': '.'.join(reversed(host.split('.'))),
23-
"apiVersion": __apiVersion__,
24-
'exists': None,
25-
'error': {'errorCode': error_code,
26-
'errorMessage': error},
27-
'alleleRequest': {'referenceName': request.get("referenceName", None),
28-
'referenceBases': request.get("referenceBases", None),
29-
'includeDatasetResponses': request.get("includeDatasetResponses", "NONE"),
30-
'assemblyId': request.get("assemblyId", None)},
31-
# showing empty datasetsAlleRsponse as no datasets found
32-
# A null/None would represent no data while empty array represents
33-
# none found or error and corresponds with exists null/None
34-
'datasetAlleleResponses': []}
19+
data = {
20+
"beaconId": ".".join(reversed(host.split("."))),
21+
"apiVersion": __apiVersion__,
22+
"exists": None,
23+
"error": {"errorCode": error_code, "errorMessage": error},
24+
"alleleRequest": {
25+
"referenceName": request.get("referenceName", None),
26+
"referenceBases": request.get("referenceBases", None),
27+
"includeDatasetResponses": request.get("includeDatasetResponses", "NONE"),
28+
"assemblyId": request.get("assemblyId", None),
29+
},
30+
# showing empty datasetsAlleRsponse as no datasets found
31+
# A null/None would represent no data while empty array represents
32+
# none found or error and corresponds with exists null/None
33+
"datasetAlleleResponses": [],
34+
}
3535
# include datasetIds only if they are specified
3636
# as per specification if they don't exist all datatsets will be queried
3737
# Only one of `alternateBases` or `variantType` is required, validated by schema
38-
oneof_fields = ["alternateBases", "variantType", "start", "end", "startMin", "startMax",
39-
"endMin", "endMax", "datasetIds"]
40-
data['alleleRequest'].update({k: request.get(k) for k in oneof_fields if k in request})
38+
oneof_fields = ["alternateBases", "variantType", "start", "end", "startMin", "startMax", "endMin", "endMax", "datasetIds"]
39+
data["alleleRequest"].update({k: request.get(k) for k in oneof_fields if k in request})
4140

4241
return data
4342

@@ -49,12 +48,11 @@ class BeaconBadRequest(web.HTTPBadRequest):
4948
Used in conjunction with JSON Schema validator.
5049
"""
5150

52-
def __init__(self, request: Dict,
53-
host: str, error: str) -> None:
51+
def __init__(self, request: Dict, host: str, error: str) -> None:
5452
"""Return custom bad request exception."""
5553
data = process_exception_data(request, host, 400, error)
5654
super().__init__(text=json.dumps(data), content_type="application/json")
57-
LOG.error(f'401 ERROR MESSAGE: {error}')
55+
LOG.error(f"401 ERROR MESSAGE: {error}")
5856

5957

6058
class BeaconUnauthorised(web.HTTPUnauthorized):
@@ -64,17 +62,21 @@ class BeaconUnauthorised(web.HTTPUnauthorized):
6462
Used in conjunction with Token authentication aiohttp middleware.
6563
"""
6664

67-
def __init__(self, request: Dict,
68-
host: str, error: str, error_message: str) -> None:
65+
def __init__(self, request: Dict, host: str, error: str, error_message: str) -> None:
6966
"""Return custom unauthorized exception."""
7067
data = process_exception_data(request, host, 401, error)
71-
headers_401 = {"WWW-Authenticate": f"Bearer realm=\"{CONFIG_INFO.url}\"\n\
72-
error=\"{error}\"\n\
73-
error_description=\"{error_message}\""}
74-
super().__init__(content_type="application/json", text=json.dumps(data),
75-
# we use auth scheme Bearer by default
76-
headers=headers_401)
77-
LOG.error(f'401 ERROR MESSAGE: {error}')
68+
headers_401 = {
69+
"WWW-Authenticate": f'Bearer realm="{CONFIG_INFO.url}"\n\
70+
error="{error}"\n\
71+
error_description="{error_message}"'
72+
}
73+
super().__init__(
74+
content_type="application/json",
75+
text=json.dumps(data),
76+
# we use auth scheme Bearer by default
77+
headers=headers_401,
78+
)
79+
LOG.error(f"401 ERROR MESSAGE: {error}")
7880

7981

8082
class BeaconForbidden(web.HTTPForbidden):
@@ -85,12 +87,11 @@ class BeaconForbidden(web.HTTPForbidden):
8587
but not granted the resource. Used in conjunction with Token authentication aiohttp middleware.
8688
"""
8789

88-
def __init__(self, request: Dict,
89-
host: str, error: str) -> None:
90+
def __init__(self, request: Dict, host: str, error: str) -> None:
9091
"""Return custom forbidden exception."""
9192
data = process_exception_data(request, host, 403, error)
9293
super().__init__(content_type="application/json", text=json.dumps(data))
93-
LOG.error(f'403 ERROR MESSAGE: {error}')
94+
LOG.error(f"403 ERROR MESSAGE: {error}")
9495

9596

9697
class BeaconServerError(web.HTTPInternalServerError):
@@ -101,7 +102,6 @@ class BeaconServerError(web.HTTPInternalServerError):
101102

102103
def __init__(self, error: str) -> None:
103104
"""Return custom forbidden exception."""
104-
data = {'errorCode': 500,
105-
'errorMessage': error}
105+
data = {"errorCode": 500, "errorMessage": error}
106106
super().__init__(content_type="application/json", text=json.dumps(data))
107-
LOG.error(f'500 ERROR MESSAGE: {error}')
107+
LOG.error(f"500 ERROR MESSAGE: {error}")

0 commit comments

Comments
 (0)