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

Commit

Permalink
Merge pull request #52 from CSCfi/devel
Browse files Browse the repository at this point in the history
bump to bump to 0.5.9
  • Loading branch information
blankdots authored Jan 26, 2021
2 parents 9dcf92d + 860ef3d commit 2688801
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 21 deletions.
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM python:3.7-alpine3.12 as BACKEND
FROM python:3.8-alpine3.12 as BACKEND

RUN apk add --update \
&& apk add --no-cache build-base curl-dev linux-headers bash git\
Expand All @@ -13,15 +13,15 @@ RUN pip install --upgrade pip\
&& pip install -r /root/swift_sharing/requirements.txt \
&& pip install /root/swift_sharing

FROM python:3.7-alpine3.12
FROM python:3.8-alpine3.12

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

LABEL maintainer "CSC Developers"
LABEL org.label-schema.schema-version="1.0"
LABEL org.label-schema.vcs-url="https://github.com/CSCFI/swift-x-account-sharing"

COPY --from=BACKEND /usr/local/lib/python3.7 /usr/local/lib/python3.7/
COPY --from=BACKEND /usr/local/lib/python3.8 /usr/local/lib/python3.8/

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

Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ aiohttp
uvloop
asyncpg
gunicorn>=20.0.1
certifi
5 changes: 3 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"aiohttp",
"uvloop",
"asyncpg",
"certifi"
],
extras_require={
"test": ["tox", "pytest", "pytest-cov", "coverage", "flake8",
Expand All @@ -36,8 +37,8 @@
"Topic :: Internet :: WWW/HTTP :: HTTP Servers",

"License :: OSI Approved :: MIT License",

"Programming Language :: Python :: 3.6",

"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
],
)
2 changes: 1 addition & 1 deletion swift_x_account_sharing/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@


__name__ = "swift_x_account_sharing"
__version__ = "0.5.8"
__version__ = "0.5.9"
__author__ = "CSC Developers"
__license__ = "MIT License"
70 changes: 56 additions & 14 deletions swift_x_account_sharing/bindings/bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,18 @@

import json
import typing

import logging
import aiohttp

from .signature import sign_api_request

import ssl
import certifi


ssl_context = ssl.create_default_context()
ssl_context.load_verify_locations(certifi.where())


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

async def _handler_response(
self,
resp: aiohttp.ClientResponse
) -> typing.Any:
"""Handle API response."""
if resp.status == 200:
try:
return json.loads(await resp.text())
except json.decoder.JSONDecodeError:
logging.error("Decoding JSON error \
response was not possible.")
raise
except Exception as e:
logging.error(f"Unknown exception \
occured with content: {e}.")
raise
else:
logging.error(f"response status: {resp.status}.")
raise Exception(f"response status: {resp.status}.")

@staticmethod
def parse_list_to_string(
to_parse: typing.List[str]
Expand All @@ -48,8 +75,11 @@ async def get_access(

params = sign_api_request(path)

async with self.session.get(url, params=params) as resp:
return json.loads(await resp.text())
async with self.session.get(url,
params=params,
ssl=ssl_context) as resp:

return await self._handler_response(resp)

async def get_access_details(
self,
Expand All @@ -64,8 +94,10 @@ async def get_access_details(
params = sign_api_request(path)
params.update({"owner": owner})

async with self.session.get(url, params=params) as resp:
return json.loads(await resp.text())
async with self.session.get(url,
params=params,
ssl=ssl_context) as resp:
return await self._handler_response(resp)

async def get_share(
self,
Expand All @@ -77,8 +109,10 @@ async def get_share(

params = sign_api_request(path)

async with self.session.get(url, params=params) as resp:
return json.loads(await resp.text())
async with self.session.get(url,
params=params,
ssl=ssl_context) as resp:
return await self._handler_response(resp)

async def get_share_details(
self,
Expand All @@ -91,8 +125,10 @@ async def get_share_details(

params = sign_api_request(path)

async with self.session.get(url, params=params) as resp:
return json.loads(await resp.text())
async with self.session.get(url,
params=params,
ssl=ssl_context) as resp:
return await self._handler_response(resp)

async def share_new_access(
self,
Expand All @@ -114,8 +150,10 @@ async def share_new_access(
"address": address
})

async with self.session.post(url, params=params) as resp:
return json.loads(await resp.text())
async with self.session.post(url,
params=params,
ssl=ssl_context) as resp:
return await self._handler_response(resp)

async def share_edit_access(
self,
Expand All @@ -134,8 +172,10 @@ async def share_edit_access(
"access": self.parse_list_to_string(accesslist),
})

async with self.session.patch(url, params=params) as resp:
return json.loads(await resp.text())
async with self.session.patch(url,
params=params,
ssl=ssl_context) as resp:
return await self._handler_response(resp)

async def share_delete_access(
self,
Expand All @@ -152,5 +192,7 @@ async def share_delete_access(
"user": self.parse_list_to_string(userlist),
})

async with self.session.delete(url, params=params) as resp:
async with self.session.delete(url,
params=params,
ssl=ssl_context) as resp:
return bool(resp.status == 204)
2 changes: 1 addition & 1 deletion tests/test_bindings_bind.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, *args, **kwargs):
"text": asynctest.CoroutineMock(
return_value="[]"
),
"status": 204
"status": 200
})

async def __aenter__(self, *args, **kwargs):
Expand Down

0 comments on commit 2688801

Please sign in to comment.