hexway-hive-api 0.2.3__tar.gz → 0.2.4__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.
Files changed (29) hide show
  1. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/PKG-INFO +5 -2
  2. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/README.md +4 -1
  3. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/http_client/async_http_client.py +24 -4
  4. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api.egg-info/PKG-INFO +5 -2
  5. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/pyproject.toml +1 -1
  6. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/tests/test_async_http_client.py +23 -0
  7. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/LICENSE +0 -0
  8. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/__init__.py +0 -0
  9. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/clients/__init__.py +0 -0
  10. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/clients/async_rest_client.py +0 -0
  11. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/clients/rest_client.py +0 -0
  12. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/__init__.py +0 -0
  13. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/enums.py +0 -0
  14. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/error_handler.py +0 -0
  15. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/exceptions.py +0 -0
  16. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/http_client/__init__.py +0 -0
  17. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/http_client/exceptions.py +0 -0
  18. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/http_client/http_client.py +0 -0
  19. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/models/__init__.py +0 -0
  20. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/models/issue.py +0 -0
  21. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api/rest/models/project.py +0 -0
  22. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api.egg-info/SOURCES.txt +0 -0
  23. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api.egg-info/dependency_links.txt +0 -0
  24. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api.egg-info/requires.txt +0 -0
  25. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/hexway_hive_api.egg-info/top_level.txt +0 -0
  26. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/setup.cfg +0 -0
  27. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/tests/test_async_rest_client.py +0 -0
  28. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/tests/test_issue.py +0 -0
  29. {hexway_hive_api-0.2.3 → hexway_hive_api-0.2.4}/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
3
+ Version: 0.2.4
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
@@ -82,4 +82,7 @@ asyncio.run(main())
82
82
 
83
83
  ``AsyncHTTPClient`` accepts an optional ``ssl`` context in its constructor or
84
84
  through :meth:`update_params`. This context will be passed to all requests if no
85
- ``ssl`` argument is provided explicitly.
85
+ ``ssl`` argument is provided explicitly. Verification of server certificates can
86
+ be toggled via the ``verify_ssl`` flag or ``verify`` parameter in
87
+ :meth:`update_params` and individual request methods. Disabling verification will
88
+ still keep TLS encryption enabled.
@@ -63,4 +63,7 @@ asyncio.run(main())
63
63
 
64
64
  ``AsyncHTTPClient`` accepts an optional ``ssl`` context in its constructor or
65
65
  through :meth:`update_params`. This context will be passed to all requests if no
66
- ``ssl`` argument is provided explicitly.
66
+ ``ssl`` argument is provided explicitly. Verification of server certificates can
67
+ be toggled via the ``verify_ssl`` flag or ``verify`` parameter in
68
+ :meth:`update_params` and individual request methods. Disabling verification will
69
+ still keep TLS encryption enabled.
@@ -18,18 +18,21 @@ SUCCESSFUL_STATUS_CODES = [status for status in HTTPStatus if 200 <= status < 30
18
18
 
19
19
  class AsyncHTTPClient:
20
20
  """Asynchronous implementation of the HTTP client."""
21
- def __init__(self, *, ssl: Optional[ssl.SSLContext] = None) -> None:
21
+ def __init__(self, *, ssl: Optional[ssl.SSLContext] = None, verify_ssl: bool = True) -> None:
22
22
  """Create ``aiohttp`` session used for all requests.
23
23
 
24
24
  Parameters
25
25
  ----------
26
26
  ssl : :class:`ssl.SSLContext` | None
27
27
  Default SSL context applied to all requests.
28
+ verify_ssl : bool, optional
29
+ Flag controlling TLS certificate verification. ``True`` by default.
28
30
  """
29
31
 
30
32
  self.session: aiohttp.ClientSession = aiohttp.ClientSession()
31
33
  self._proxies: MutableMapping[str, str] = {}
32
34
  self.ssl = ssl
35
+ self.verify_ssl = verify_ssl
33
36
 
34
37
  async def _send(self, method: HTTPMethod, url: str, **kwargs) -> Union[dict, bytes, list]:
35
38
  """Internal helper performing HTTP request and parsing the response.
@@ -40,7 +43,20 @@ class AsyncHTTPClient:
40
43
  proxy = self._proxies.get('https' if url.startswith('https') else 'http')
41
44
  if proxy:
42
45
  kwargs.setdefault('proxy', proxy)
43
- kwargs.setdefault('ssl', self.ssl)
46
+
47
+ verify = kwargs.pop("verify", kwargs.pop("verify_ssl", self.verify_ssl))
48
+
49
+ if not verify:
50
+ base_context = kwargs.get("ssl") or self.ssl
51
+ if base_context is not None:
52
+ context = ssl.SSLContext(base_context.protocol)
53
+ else:
54
+ context = ssl.create_default_context()
55
+ context.check_hostname = False
56
+ context.verify_mode = ssl.CERT_NONE
57
+ kwargs.setdefault("ssl", context)
58
+ else:
59
+ kwargs.setdefault("ssl", self.ssl)
44
60
  try:
45
61
  async with self.session.request(method, url, **kwargs) as response:
46
62
  if response.status not in SUCCESSFUL_STATUS_CODES:
@@ -111,8 +127,12 @@ class AsyncHTTPClient:
111
127
 
112
128
  def update_params(self, **kwargs) -> Self:
113
129
  """Update session parameters and store ``ssl`` for later use."""
114
- if 'ssl' in kwargs:
115
- self.ssl = kwargs['ssl']
130
+ if "ssl" in kwargs:
131
+ self.ssl = kwargs["ssl"]
132
+ if "verify" in kwargs or "verify_ssl" in kwargs:
133
+ self.verify_ssl = bool(kwargs.get("verify", kwargs.get("verify_ssl")))
134
+ kwargs.pop("verify", None)
135
+ kwargs.pop("verify_ssl", None)
116
136
  self._update_params(**kwargs)
117
137
  return self
118
138
 
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: hexway-hive-api
3
- Version: 0.2.3
3
+ Version: 0.2.4
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
@@ -82,4 +82,7 @@ asyncio.run(main())
82
82
 
83
83
  ``AsyncHTTPClient`` accepts an optional ``ssl`` context in its constructor or
84
84
  through :meth:`update_params`. This context will be passed to all requests if no
85
- ``ssl`` argument is provided explicitly.
85
+ ``ssl`` argument is provided explicitly. Verification of server certificates can
86
+ be toggled via the ``verify_ssl`` flag or ``verify`` parameter in
87
+ :meth:`update_params` and individual request methods. Disabling verification will
88
+ still keep TLS encryption enabled.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "hexway-hive-api"
7
- version = "0.2.3"
7
+ version = "0.2.4"
8
8
  description = "Small wrapper for HexWay Hive API"
9
9
  readme = "README.md"
10
10
  requires-python = ">=3.12"
@@ -60,3 +60,26 @@ def test_send_uses_default_ssl():
60
60
  await client.close()
61
61
 
62
62
  asyncio.run(run())
63
+
64
+
65
+ def test_update_params_sets_verify_ssl():
66
+ async def run() -> None:
67
+ client = AsyncHTTPClient()
68
+ client.update_params(verify=False)
69
+ assert client.verify_ssl is False
70
+ await client.close()
71
+
72
+ asyncio.run(run())
73
+
74
+
75
+ def test_send_respects_verify_flag():
76
+ async def run() -> None:
77
+ client = AsyncHTTPClient()
78
+ client.session = DummySession()
79
+ await client.get("https://example.com", verify=False)
80
+ context = client.session.kwargs.get("ssl")
81
+ assert isinstance(context, ssl.SSLContext)
82
+ assert context.verify_mode == ssl.CERT_NONE
83
+ await client.close()
84
+
85
+ asyncio.run(run())
File without changes