Skip to content
This repository was archived by the owner on Aug 4, 2021. It is now read-only.

Commit 08114e9

Browse files
authored
Merge pull request #20 from CSCfi/devel
bump to 0.4.3
2 parents d415cca + 7ed5e7a commit 08114e9

File tree

18 files changed

+261
-115
lines changed

18 files changed

+261
-115
lines changed

.github/workflows/eslint.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
name: Javascript ESLint check
2+
3+
on: [push]
4+
5+
6+
jobs:
7+
build:
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
node: [ '12', '14' ]
12+
name: Node ${{ matrix.node }} eslint check
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: Setup node
16+
uses: actions/setup-node@v1
17+
with:
18+
node-version: ${{ matrix.node }}
19+
- name: Install dependencies
20+
run: npm i -g eslint
21+
- name: Run eslint
22+
run: |
23+
pushd bindings/js
24+
eslint --no-eslintrc --ext js --env es6,node --parser-options=ecmaVersion:8 --parser-options=sourceType:module swift_sharing_request_bind.js
25+

.github/workflows/publish.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Publish Docker image
2+
3+
on:
4+
release:
5+
types: [published]
6+
push:
7+
branches: [master, devel]
8+
9+
jobs:
10+
push_to_registry:
11+
name: Push swift-sharing-request Docker image to Docker Hub
12+
runs-on: ubuntu-latest
13+
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' && steps.vars.outputs.tag != '/devel' }}
22+
run: docker build . --file Dockerfile --tag cscfi/swift-sharing-request:${{steps.vars.outputs.tag}}
23+
- name: Push the tagged Docker image
24+
if: ${{ steps.vars.outputs.tag != '/master' && steps.vars.outputs.tag != '/devel' }}
25+
run: docker push cscfi/swift-sharing-request:${{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/swift-sharing-request:latest
29+
- name: Push the latest Docker image
30+
if: ${{ steps.vars.outputs.tag == '/master' }}
31+
run: docker push cscfi/swift-sharing-request:latest
32+
- name: Build the stage Docker image
33+
if: ${{ steps.vars.outputs.tag == '/devel' }}
34+
run: docker build . --file Dockerfile --tag cscfi/swift-sharing-request:stage
35+
- name: Push the stage Docker image
36+
if: ${{ steps.vars.outputs.tag == '/devel' }}
37+
run: docker push cscfi/swift-sharing-request:stage

.github/workflows/style.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Python style check
2+
3+
on: [push]
4+
5+
jobs:
6+
style_check:
7+
strategy:
8+
max-parallel: 4
9+
matrix:
10+
os: [ubuntu-latest]
11+
python-version: [3.7]
12+
13+
runs-on: ${{ matrix.os }}
14+
15+
steps:
16+
- uses: actions/checkout@v1
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v1
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install tox tox-gh-actions
25+
- name: Test flake8 syntax with tox
26+
run: tox -e flake8
27+
- name: bandit static check
28+
run: tox -e bandit

.github/workflows/unit.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Python Unit Tests
2+
3+
on: [push]
4+
5+
jobs:
6+
unit_test:
7+
strategy:
8+
max-parallel: 4
9+
matrix:
10+
os: [ubuntu-latest]
11+
python-version: [3.6, 3.7]
12+
13+
runs-on: ${{ matrix.os }}
14+
15+
steps:
16+
- uses: actions/checkout@v1
17+
- name: Set up Python ${{ matrix.python-version }}
18+
uses: actions/setup-python@v1
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install tox tox-gh-actions
25+
- name: Run unit tests
26+
run: tox -e pytest

.travis.yml

Lines changed: 0 additions & 51 deletions
This file was deleted.

Dockerfile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM python:3.7-alpine3.9 as BACKEND
1+
FROM python:3.7-alpine3.12 as BACKEND
22

33
RUN apk add --update \
44
&& apk add --no-cache build-base curl-dev linux-headers bash git\
@@ -13,15 +13,15 @@ RUN pip install --upgrade pip\
1313
&& pip install -r /root/swift_request/requirements.txt \
1414
&& pip install /root/swift_request
1515

16-
FROM python:3.7-alpine3.9
16+
FROM python:3.7-alpine3.12
1717

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

2020
LABEL maintainer "CSC Developers"
2121
LABEL org.label-schema.schema-version="1.0"
2222
LABEL org.label-schema.vcs-url="https://github.com/CSCFI/swift-sharing-request"
2323

24-
COPY --from=BACKEND usr/local/lib/python3.7 usr/local/lib/python3.7/
24+
COPY --from=BACKEND /usr/local/lib/python3.7 /usr/local/lib/python3.7/
2525

2626
COPY --from=BACKEND /usr/local/bin/gunicorn /usr/local/bin/
2727

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
![Python style check](https://github.com/CSCfi/swift-sharing-request/workflows/Python%20style%20check/badge.svg)
2+
![Javascript ESLint check](https://github.com/CSCfi/swift-sharing-request/workflows/Javascript%20ESLint%20check/badge.svg)
3+
![Python Unit Tests](https://github.com/CSCfi/swift-sharing-request/workflows/Python%20Unit%20Tests/badge.svg)
4+
15
### swift-request-backend
26
API for requesting access to swift containers, to enable more fluid container
37
sharing process, the main use being the abstraction of separation of the

swift_sharing_request/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@
22

33

44
__name__ = "swift_sharing_request"
5-
__version__ = "0.4.2"
5+
__version__ = "0.4.3"
66
__author__ = "CSC Developers"
77
__license__ = "MIT License"

swift_sharing_request/api.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,15 @@
22

33

44
import logging
5-
import asyncio
65

76
import aiohttp.web
87
from asyncpg import InterfaceError
98

109

11-
MODULE_LOGGER = logging.getLogger("api")
10+
from .db import handle_dropped_connection
1211

1312

14-
def handle_dropped_connection(request):
15-
"""Handle dropped database connection."""
16-
MODULE_LOGGER.log(
17-
logging.ERROR,
18-
"Lost database connection, reconnecting..."
19-
)
20-
request.app["db_conn"].erase()
21-
asyncio.ensure_future(
22-
request.app["db_conn"].open()
23-
)
24-
raise aiohttp.web.HTTPServiceUnavailable(
25-
reason="No database connection."
26-
)
13+
MODULE_LOGGER = logging.getLogger("api")
2714

2815

2916
async def handle_share_request_post(request):
@@ -166,3 +153,30 @@ async def handle_user_list_tokens(
166153
rec["identifier"]
167154
for rec in tokens
168155
])
156+
157+
158+
async def handle_health_check(
159+
request: aiohttp.web.Request
160+
) -> aiohttp.web.Response:
161+
"""Answer a service health check."""
162+
# Case degraded
163+
try:
164+
if request.app["db_conn"].conn.is_closed():
165+
return aiohttp.web.json_response({
166+
"status": "Degraded",
167+
"degraded": [
168+
"database"
169+
]
170+
})
171+
except AttributeError:
172+
return aiohttp.web.json_response({
173+
"status": "Degraded",
174+
"degraded": [
175+
"database"
176+
]
177+
})
178+
179+
# Case nominal
180+
return aiohttp.web.json_response({
181+
"status": "Ok",
182+
})

swift_sharing_request/auth.py

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515
import logging
1616

1717
import aiohttp.web
18+
from asyncpg import InterfaceError
19+
20+
from .db import handle_dropped_connection
1821

1922

2023
AiohttpHandler = typing.Callable[
@@ -84,7 +87,6 @@ async def handle_validate_authentication(
8487
)
8588

8689
project_tokens = []
87-
project = None
8890
try:
8991
project = request.match_info["project"]
9092
except KeyError:
@@ -94,18 +96,22 @@ async def handle_validate_authentication(
9496
try:
9597
project = request.query["project"]
9698
except KeyError:
97-
pass
99+
project = None
98100
finally:
99101
if project:
100-
project_tokens = [
101-
rec["token"].encode("utf-8")
102-
for rec in await request.app["db_conn"].get_tokens(project)
103-
]
102+
try:
103+
project_tokens = [
104+
rec["token"].encode("utf-8")
105+
for rec in await request.app["db_conn"].get_tokens(project)
106+
]
107+
except InterfaceError:
108+
handle_dropped_connection(request)
104109
else:
105110
LOGGER.debug(f"No project ID found in request {request}")
106-
raise aiohttp.web.HTTPUnauthorized(
107-
reason="No project ID in request"
108-
)
111+
if request.path != "/health":
112+
raise aiohttp.web.HTTPUnauthorized(
113+
reason="No project ID in request"
114+
)
109115

110116
await test_signature(
111117
request.app["tokens"] + project_tokens,

0 commit comments

Comments
 (0)