hexway-hive-api 0.2.1__tar.gz → 0.2.2__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/PKG-INFO +7 -1
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/README.md +7 -1
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/clients/async_rest_client.py +28 -1
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/rest/http_client/async_http_client.py +20 -6
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api.egg-info/PKG-INFO +7 -1
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api.egg-info/SOURCES.txt +1 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/pyproject.toml +1 -1
- hexway_hive_api-0.2.2/tests/test_async_http_client.py +62 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/tests/test_async_rest_client.py +53 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/LICENSE +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/__init__.py +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/clients/__init__.py +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/clients/rest_client.py +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/rest/__init__.py +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/rest/enums.py +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/rest/error_handler.py +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/rest/exceptions.py +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/rest/http_client/__init__.py +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/rest/http_client/exceptions.py +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/rest/http_client/http_client.py +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/rest/models/__init__.py +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/rest/models/issue.py +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/rest/models/project.py +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api.egg-info/dependency_links.txt +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api.egg-info/requires.txt +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api.egg-info/top_level.txt +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/setup.cfg +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/tests/test_issue.py +0 -0
- {hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/tests/test_project.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hexway-hive-api
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Small wrapper for HexWay Hive API
|
|
5
5
|
Author-email: "@Cur1iosity" <Cur1iosity@protonmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/Cur1iosity/hexway-hive-api
|
|
@@ -77,3 +77,9 @@ async def main() -> None:
|
|
|
77
77
|
|
|
78
78
|
asyncio.run(main())
|
|
79
79
|
```
|
|
80
|
+
|
|
81
|
+
### TLS configuration
|
|
82
|
+
|
|
83
|
+
``AsyncHTTPClient`` accepts an optional ``ssl`` context in its constructor or
|
|
84
|
+
through :meth:`update_params`. This context will be passed to all requests if no
|
|
85
|
+
``ssl`` argument is provided explicitly.
|
|
@@ -57,4 +57,10 @@ async def main() -> None:
|
|
|
57
57
|
|
|
58
58
|
|
|
59
59
|
asyncio.run(main())
|
|
60
|
-
```
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
### TLS configuration
|
|
63
|
+
|
|
64
|
+
``AsyncHTTPClient`` accepts an optional ``ssl`` context in its constructor or
|
|
65
|
+
through :meth:`update_params`. This context will be passed to all requests if no
|
|
66
|
+
``ssl`` argument is provided explicitly.
|
{hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/clients/async_rest_client.py
RENAMED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"""Asynchronous version of the Hive REST client."""
|
|
2
2
|
|
|
3
3
|
import json
|
|
4
|
+
import ssl
|
|
4
5
|
from contextlib import asynccontextmanager
|
|
5
6
|
from typing import Optional, MutableMapping, Union, Self, AsyncGenerator
|
|
6
7
|
from uuid import UUID
|
|
@@ -43,6 +44,8 @@ class AsyncRestClient:
|
|
|
43
44
|
Optional mapping with proxy configuration.
|
|
44
45
|
other: dict
|
|
45
46
|
Additional parameters forwarded to :class:`aiohttp.ClientSession`.
|
|
47
|
+
The ``cert`` key may specify a certificate path or ``(cert, key)``
|
|
48
|
+
tuple for TLS authentication.
|
|
46
49
|
"""
|
|
47
50
|
|
|
48
51
|
self.http_client: AsyncHTTPClient = AsyncHTTPClient()
|
|
@@ -54,7 +57,12 @@ class AsyncRestClient:
|
|
|
54
57
|
self.__password: Optional[str] = password
|
|
55
58
|
self.proxies = proxies
|
|
56
59
|
|
|
60
|
+
cert = other.pop('cert', None)
|
|
61
|
+
self.cert: Optional[Union[str, tuple[str, str]]] = cert
|
|
57
62
|
self.http_client.update_params(**other)
|
|
63
|
+
if cert:
|
|
64
|
+
context = self._make_ssl_context(cert)
|
|
65
|
+
self.http_client.update_params(ssl=context)
|
|
58
66
|
|
|
59
67
|
async def connect(self,
|
|
60
68
|
*,
|
|
@@ -64,7 +72,10 @@ class AsyncRestClient:
|
|
|
64
72
|
password: Optional[str] = None,
|
|
65
73
|
**other,
|
|
66
74
|
) -> None:
|
|
67
|
-
"""Authenticate asynchronously with the Hive server.
|
|
75
|
+
"""Authenticate asynchronously with the Hive server.
|
|
76
|
+
|
|
77
|
+
``cert`` may be supplied in ``other`` for client TLS configuration.
|
|
78
|
+
"""
|
|
68
79
|
|
|
69
80
|
if not any([server, self.server]) and not any([api_url, self.api_url]):
|
|
70
81
|
raise exceptions.ServerNotFound()
|
|
@@ -72,7 +83,12 @@ class AsyncRestClient:
|
|
|
72
83
|
if not any([username, self.username]) and not any([password, self.__password]):
|
|
73
84
|
raise exceptions.RestConnectionError('You must provide username and password.')
|
|
74
85
|
|
|
86
|
+
cert = other.pop('cert', None) or self.cert
|
|
75
87
|
self.http_client.update_params(**other)
|
|
88
|
+
if cert:
|
|
89
|
+
self.cert = cert
|
|
90
|
+
context = self._make_ssl_context(cert)
|
|
91
|
+
self.http_client.update_params(ssl=context)
|
|
76
92
|
|
|
77
93
|
self.server = server or self.server
|
|
78
94
|
self.api_url = api_url or self.api_url or self.make_api_url_from(self.server)
|
|
@@ -114,6 +130,17 @@ class AsyncRestClient:
|
|
|
114
130
|
finally:
|
|
115
131
|
await self.disconnect()
|
|
116
132
|
|
|
133
|
+
@staticmethod
|
|
134
|
+
def _make_ssl_context(cert: Union[str, tuple[str, str]]) -> ssl.SSLContext:
|
|
135
|
+
"""Create SSL context from certificate chain."""
|
|
136
|
+
|
|
137
|
+
context = ssl.create_default_context()
|
|
138
|
+
if isinstance(cert, (list, tuple)):
|
|
139
|
+
context.load_cert_chain(cert[0], cert[1])
|
|
140
|
+
else:
|
|
141
|
+
context.load_cert_chain(cert)
|
|
142
|
+
return context
|
|
143
|
+
|
|
117
144
|
@staticmethod
|
|
118
145
|
def make_api_url_from(server: str, port: Optional[int] = None) -> str:
|
|
119
146
|
"""Build API URL from server string.
|
|
@@ -2,10 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
Attributes:
|
|
4
4
|
session (aiohttp.ClientSession): Session used for all outgoing requests.
|
|
5
|
+
ssl (ssl.SSLContext | None): Default SSL context for requests.
|
|
5
6
|
"""
|
|
6
7
|
|
|
7
8
|
from http import HTTPStatus, HTTPMethod
|
|
8
|
-
from typing import Self, Union, MutableMapping, Any
|
|
9
|
+
from typing import Self, Union, MutableMapping, Any, Optional
|
|
10
|
+
import ssl
|
|
9
11
|
|
|
10
12
|
import aiohttp
|
|
11
13
|
|
|
@@ -16,18 +18,29 @@ SUCCESSFUL_STATUS_CODES = [status for status in HTTPStatus if 200 <= status < 30
|
|
|
16
18
|
|
|
17
19
|
class AsyncHTTPClient:
|
|
18
20
|
"""Asynchronous implementation of the HTTP client."""
|
|
19
|
-
def __init__(self) -> None:
|
|
20
|
-
"""Create ``aiohttp`` session used for all requests.
|
|
21
|
+
def __init__(self, *, ssl: Optional[ssl.SSLContext] = None) -> None:
|
|
22
|
+
"""Create ``aiohttp`` session used for all requests.
|
|
23
|
+
|
|
24
|
+
Parameters
|
|
25
|
+
----------
|
|
26
|
+
ssl : :class:`ssl.SSLContext` | None
|
|
27
|
+
Default SSL context applied to all requests.
|
|
28
|
+
"""
|
|
21
29
|
|
|
22
30
|
self.session: aiohttp.ClientSession = aiohttp.ClientSession()
|
|
23
31
|
self._proxies: MutableMapping[str, str] = {}
|
|
32
|
+
self.ssl = ssl
|
|
24
33
|
|
|
25
34
|
async def _send(self, method: HTTPMethod, url: str, **kwargs) -> Union[dict, bytes, list]:
|
|
26
|
-
"""Internal helper performing HTTP request and parsing the response.
|
|
35
|
+
"""Internal helper performing HTTP request and parsing the response.
|
|
36
|
+
|
|
37
|
+
The default SSL context is appended to ``kwargs`` if not specified.
|
|
38
|
+
"""
|
|
27
39
|
|
|
28
40
|
proxy = self._proxies.get('https' if url.startswith('https') else 'http')
|
|
29
41
|
if proxy:
|
|
30
42
|
kwargs.setdefault('proxy', proxy)
|
|
43
|
+
kwargs.setdefault('ssl', self.ssl)
|
|
31
44
|
try:
|
|
32
45
|
async with self.session.request(method, url, **kwargs) as response:
|
|
33
46
|
if response.status not in SUCCESSFUL_STATUS_CODES:
|
|
@@ -97,8 +110,9 @@ class AsyncHTTPClient:
|
|
|
97
110
|
return self
|
|
98
111
|
|
|
99
112
|
def update_params(self, **kwargs) -> Self:
|
|
100
|
-
"""
|
|
101
|
-
|
|
113
|
+
"""Update session parameters and store ``ssl`` for later use."""
|
|
114
|
+
if 'ssl' in kwargs:
|
|
115
|
+
self.ssl = kwargs['ssl']
|
|
102
116
|
self._update_params(**kwargs)
|
|
103
117
|
return self
|
|
104
118
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hexway-hive-api
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.2
|
|
4
4
|
Summary: Small wrapper for HexWay Hive API
|
|
5
5
|
Author-email: "@Cur1iosity" <Cur1iosity@protonmail.com>
|
|
6
6
|
Project-URL: Homepage, https://github.com/Cur1iosity/hexway-hive-api
|
|
@@ -77,3 +77,9 @@ async def main() -> None:
|
|
|
77
77
|
|
|
78
78
|
asyncio.run(main())
|
|
79
79
|
```
|
|
80
|
+
|
|
81
|
+
### TLS configuration
|
|
82
|
+
|
|
83
|
+
``AsyncHTTPClient`` accepts an optional ``ssl`` context in its constructor or
|
|
84
|
+
through :meth:`update_params`. This context will be passed to all requests if no
|
|
85
|
+
``ssl`` argument is provided explicitly.
|
|
@@ -21,6 +21,7 @@ hexway_hive_api/rest/http_client/http_client.py
|
|
|
21
21
|
hexway_hive_api/rest/models/__init__.py
|
|
22
22
|
hexway_hive_api/rest/models/issue.py
|
|
23
23
|
hexway_hive_api/rest/models/project.py
|
|
24
|
+
tests/test_async_http_client.py
|
|
24
25
|
tests/test_async_rest_client.py
|
|
25
26
|
tests/test_issue.py
|
|
26
27
|
tests/test_project.py
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
import ssl
|
|
3
|
+
|
|
4
|
+
from hexway_hive_api.rest.http_client.async_http_client import AsyncHTTPClient
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class DummyResponse:
|
|
8
|
+
def __init__(self) -> None:
|
|
9
|
+
self.status = 200
|
|
10
|
+
|
|
11
|
+
async def json(self):
|
|
12
|
+
return {}
|
|
13
|
+
|
|
14
|
+
async def read(self):
|
|
15
|
+
return b""
|
|
16
|
+
|
|
17
|
+
async def text(self):
|
|
18
|
+
return ""
|
|
19
|
+
|
|
20
|
+
async def __aenter__(self):
|
|
21
|
+
return self
|
|
22
|
+
|
|
23
|
+
async def __aexit__(self, exc_type, exc, tb):
|
|
24
|
+
pass
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class DummySession:
|
|
28
|
+
def __init__(self) -> None:
|
|
29
|
+
self.headers = {}
|
|
30
|
+
self.kwargs = None
|
|
31
|
+
self.closed = False
|
|
32
|
+
|
|
33
|
+
def request(self, *args, **kwargs):
|
|
34
|
+
self.kwargs = kwargs
|
|
35
|
+
return DummyResponse()
|
|
36
|
+
|
|
37
|
+
async def close(self):
|
|
38
|
+
self.closed = True
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_update_params_sets_ssl():
|
|
42
|
+
async def run() -> None:
|
|
43
|
+
client = AsyncHTTPClient()
|
|
44
|
+
context = ssl.create_default_context()
|
|
45
|
+
client.update_params(ssl=context)
|
|
46
|
+
assert client.ssl is context
|
|
47
|
+
await client.close()
|
|
48
|
+
|
|
49
|
+
asyncio.run(run())
|
|
50
|
+
|
|
51
|
+
|
|
52
|
+
def test_send_uses_default_ssl():
|
|
53
|
+
async def run() -> None:
|
|
54
|
+
client = AsyncHTTPClient()
|
|
55
|
+
client.session = DummySession()
|
|
56
|
+
context = ssl.create_default_context()
|
|
57
|
+
client.update_params(ssl=context)
|
|
58
|
+
await client.get("http://example.com")
|
|
59
|
+
assert client.session.kwargs.get("ssl") is context
|
|
60
|
+
await client.close()
|
|
61
|
+
|
|
62
|
+
asyncio.run(run())
|
|
@@ -56,3 +56,56 @@ def test_disconnect_closes_session() -> None:
|
|
|
56
56
|
|
|
57
57
|
import asyncio
|
|
58
58
|
asyncio.run(run())
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_connect_uses_ssl_context(monkeypatch) -> None:
|
|
62
|
+
"""SSL context from ``cert`` parameter should be passed to requests."""
|
|
63
|
+
import ssl
|
|
64
|
+
async def run() -> None:
|
|
65
|
+
captured = None
|
|
66
|
+
|
|
67
|
+
# avoid loading real certificate
|
|
68
|
+
monkeypatch.setattr(
|
|
69
|
+
AsyncRestClient,
|
|
70
|
+
"_make_ssl_context",
|
|
71
|
+
staticmethod(lambda cert: ssl.create_default_context()),
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
client = AsyncRestClient(cert="path/to/cert.pem")
|
|
75
|
+
|
|
76
|
+
async def dummy_request(self, method, url, **kwargs):
|
|
77
|
+
nonlocal captured
|
|
78
|
+
captured = kwargs.get("ssl")
|
|
79
|
+
class DummyResponse:
|
|
80
|
+
def __init__(self) -> None:
|
|
81
|
+
self.cookies = {"BSESSIONID": "cookie"}
|
|
82
|
+
|
|
83
|
+
async def json(self):
|
|
84
|
+
return {}
|
|
85
|
+
|
|
86
|
+
return DummyResponse()
|
|
87
|
+
|
|
88
|
+
from types import MethodType
|
|
89
|
+
|
|
90
|
+
monkeypatch.setattr(
|
|
91
|
+
client.http_client.session,
|
|
92
|
+
"request",
|
|
93
|
+
MethodType(dummy_request, client.http_client.session),
|
|
94
|
+
)
|
|
95
|
+
|
|
96
|
+
async def dummy_post(self, url, **kwargs):
|
|
97
|
+
return await self.request("POST", url, ssl=client.http_client.ssl, **kwargs)
|
|
98
|
+
|
|
99
|
+
monkeypatch.setattr(
|
|
100
|
+
client.http_client.session,
|
|
101
|
+
"post",
|
|
102
|
+
MethodType(dummy_post, client.http_client.session),
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
await client.connect(server="https://hive.local", api_url="https://hive.local/api", username="u", password="p")
|
|
106
|
+
|
|
107
|
+
assert isinstance(captured, ssl.SSLContext)
|
|
108
|
+
await client.http_client.session.close()
|
|
109
|
+
|
|
110
|
+
import asyncio
|
|
111
|
+
asyncio.run(run())
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/rest/http_client/__init__.py
RENAMED
|
File without changes
|
{hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/rest/http_client/exceptions.py
RENAMED
|
File without changes
|
{hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api/rest/http_client/http_client.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{hexway_hive_api-0.2.1 → hexway_hive_api-0.2.2}/hexway_hive_api.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|