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

Commit 2688801

Browse files
authored
Merge pull request #52 from CSCfi/devel
bump to bump to 0.5.9
2 parents 9dcf92d + 860ef3d commit 2688801

File tree

6 files changed

+65
-21
lines changed

6 files changed

+65
-21
lines changed

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_sharing/requirements.txt \
1414
&& pip install /root/swift_sharing
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-x-account-sharing"
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 @@ aiohttp
22
uvloop
33
asyncpg
44
gunicorn>=20.0.1
5+
certifi

setup.py

Lines changed: 3 additions & 2 deletions
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",
@@ -36,8 +37,8 @@
3637
"Topic :: Internet :: WWW/HTTP :: HTTP Servers",
3738

3839
"License :: OSI Approved :: MIT License",
39-
40-
"Programming Language :: Python :: 3.6",
40+
4141
"Programming Language :: Python :: 3.7",
42+
"Programming Language :: Python :: 3.8",
4243
],
4344
)

swift_x_account_sharing/__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_x_account_sharing"
5-
__version__ = "0.5.8"
5+
__version__ = "0.5.9"
66
__author__ = "CSC Developers"
77
__license__ = "MIT License"

swift_x_account_sharing/bindings/bind.py

Lines changed: 56 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,18 @@
33

44
import json
55
import typing
6-
6+
import logging
77
import aiohttp
88

99
from .signature import sign_api_request
1010

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

1219
class SwiftXAccountSharing:
1320
"""Swift X Account Sharing backend client."""
@@ -28,6 +35,26 @@ async def __aexit__(self, *excinfo: BaseException) -> None:
2835
"""."""
2936
await self.session.close()
3037

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

4976
params = sign_api_request(path)
5077

51-
async with self.session.get(url, params=params) as resp:
52-
return json.loads(await resp.text())
78+
async with self.session.get(url,
79+
params=params,
80+
ssl=ssl_context) as resp:
81+
82+
return await self._handler_response(resp)
5383

5484
async def get_access_details(
5585
self,
@@ -64,8 +94,10 @@ async def get_access_details(
6494
params = sign_api_request(path)
6595
params.update({"owner": owner})
6696

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

70102
async def get_share(
71103
self,
@@ -77,8 +109,10 @@ async def get_share(
77109

78110
params = sign_api_request(path)
79111

80-
async with self.session.get(url, params=params) as resp:
81-
return json.loads(await resp.text())
112+
async with self.session.get(url,
113+
params=params,
114+
ssl=ssl_context) as resp:
115+
return await self._handler_response(resp)
82116

83117
async def get_share_details(
84118
self,
@@ -91,8 +125,10 @@ async def get_share_details(
91125

92126
params = sign_api_request(path)
93127

94-
async with self.session.get(url, params=params) as resp:
95-
return json.loads(await resp.text())
128+
async with self.session.get(url,
129+
params=params,
130+
ssl=ssl_context) as resp:
131+
return await self._handler_response(resp)
96132

97133
async def share_new_access(
98134
self,
@@ -114,8 +150,10 @@ async def share_new_access(
114150
"address": address
115151
})
116152

117-
async with self.session.post(url, params=params) as resp:
118-
return json.loads(await resp.text())
153+
async with self.session.post(url,
154+
params=params,
155+
ssl=ssl_context) as resp:
156+
return await self._handler_response(resp)
119157

120158
async def share_edit_access(
121159
self,
@@ -134,8 +172,10 @@ async def share_edit_access(
134172
"access": self.parse_list_to_string(accesslist),
135173
})
136174

137-
async with self.session.patch(url, params=params) as resp:
138-
return json.loads(await resp.text())
175+
async with self.session.patch(url,
176+
params=params,
177+
ssl=ssl_context) as resp:
178+
return await self._handler_response(resp)
139179

140180
async def share_delete_access(
141181
self,
@@ -152,5 +192,7 @@ async def share_delete_access(
152192
"user": self.parse_list_to_string(userlist),
153193
})
154194

155-
async with self.session.delete(url, params=params) as resp:
195+
async with self.session.delete(url,
196+
params=params,
197+
ssl=ssl_context) as resp:
156198
return bool(resp.status == 204)

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)