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

Commit 6007b00

Browse files
authored
Merge pull request #28 from CSCfi/devel
bump to 0.4.7
2 parents c18df21 + b94e87d commit 6007b00

6 files changed

Lines changed: 57 additions & 15 deletions

File tree

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.12 as BACKEND
1+
FROM python:3.8-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.12
16+
FROM python:3.8-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.8 /usr/local/lib/python3.8/
2525

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

requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ asyncpg
22
aiohttp
33
uvloop
44
gunicorn>=20.0.1
5+
certifi

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"aiohttp",
1717
"uvloop",
1818
"asyncpg",
19+
"certifi"
1920
],
2021
extras_require={
2122
"test": ["tox", "pytest", "pytest-cov", "coverage", "flake8",
@@ -37,7 +38,7 @@
3738

3839
"License :: OSI Approved :: MIT License",
3940

40-
"Programming Language :: Python :: 3.6",
4141
"Programming Language :: Python :: 3.7",
42+
"Programming Language :: Python :: 3.8",
4243
],
4344
)

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.6"
5+
__version__ = "0.4.7"
66
__author__ = "CSC Developers"
77
__license__ = "MIT License"

swift_sharing_request/bindings/bind.py

Lines changed: 49 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,18 @@
44
import os
55
import json
66
import typing
7-
7+
import logging
88
import aiohttp
99

1010
from .signature import sign_api_request
1111

12+
import ssl
13+
import certifi
14+
15+
16+
ssl_context = ssl.create_default_context()
17+
ssl_context.load_verify_locations(certifi.where())
18+
1219

1320
class SwiftSharingRequest:
1421
"""Swift Sharing Request backend client."""
@@ -29,6 +36,26 @@ async def __aexit__(self, *excinfo: BaseException) -> None:
2936
"""."""
3037
await self.session.close()
3138

39+
async def _handler_response(
40+
self,
41+
resp: aiohttp.ClientResponse
42+
) -> typing.Any:
43+
"""Handle API response."""
44+
if resp.status == 200:
45+
try:
46+
return json.loads(await resp.text())
47+
except json.decoder.JSONDecodeError:
48+
logging.error("Decoding JSON error \
49+
response was not possible.")
50+
raise
51+
except Exception as e:
52+
logging.error(f"Unknown exception \
53+
occured with content: {e}.")
54+
raise
55+
else:
56+
logging.error(f"response status: {resp.status}.")
57+
raise Exception(f"response status: {resp.status}.")
58+
3259
async def add_access_request(
3360
self,
3461
user: str,
@@ -47,8 +74,11 @@ async def add_access_request(
4774
"signature": signature["signature"],
4875
}
4976

50-
async with self.session.post(url, params=params) as resp:
51-
return json.loads(await resp.text())
77+
async with self.session.post(url,
78+
params=params,
79+
ssl=ssl_context) as resp:
80+
81+
return await self._handler_response(resp)
5282

5383
async def list_made_requests(
5484
self,
@@ -65,8 +95,11 @@ async def list_made_requests(
6595
"signature": signature["signature"],
6696
}
6797

68-
async with self.session.get(url, params=params) as resp:
69-
return json.loads(await resp.text())
98+
async with self.session.get(url,
99+
params=params,
100+
ssl=ssl_context) as resp:
101+
102+
return await self._handler_response(resp)
70103

71104
async def list_owned_requests(
72105
self,
@@ -83,8 +116,11 @@ async def list_owned_requests(
83116
"signature": signature["signature"],
84117
}
85118

86-
async with self.session.get(url, params=params) as resp:
87-
return json.loads(await resp.text())
119+
async with self.session.get(url,
120+
params=params,
121+
ssl=ssl_context) as resp:
122+
123+
return await self._handler_response(resp)
88124

89125
async def list_container_requests(
90126
self,
@@ -106,7 +142,9 @@ async def list_container_requests(
106142
if project:
107143
params["project"] = project
108144

109-
async with self.session.get(url, params=params) as resp:
145+
async with self.session.get(url,
146+
params=params,
147+
ssl=ssl_context) as resp:
110148
return json.loads(await resp.text())
111149

112150
async def share_delete_access(
@@ -127,5 +165,7 @@ async def share_delete_access(
127165
"signature": signature["signature"],
128166
}
129167

130-
async with self.session.delete(url, params=params) as resp:
168+
async with self.session.delete(url,
169+
params=params,
170+
ssl=ssl_context) as resp:
131171
return bool(resp.status == 200)

tests/test_bindings_bind.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def __init__(self, *args, **kwargs):
2020
"text": asynctest.CoroutineMock(
2121
return_value="[]"
2222
),
23-
"status": 204
23+
"status": 200
2424
})
2525

2626
async def __aenter__(self, *args, **kwargs):

0 commit comments

Comments
 (0)