From 38a8149157688f3f0195bb3f06df9d44bfa0c439 Mon Sep 17 00:00:00 2001 From: Leonhard S Date: Tue, 10 May 2022 13:14:46 +0200 Subject: [PATCH 1/2] Add flag for ignoring expired SSL certs DBG regularly lets the API certs expire, causing the Auraxium Websocket connection to fail by default. This adds the "no_ssl_certs" flag that disables certificate checks as a workaround. See #55. --- auraxium/_rest.py | 5 +++-- auraxium/event/_client.py | 7 ++++++- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/auraxium/_rest.py b/auraxium/_rest.py index 59164da..842b966 100644 --- a/auraxium/_rest.py +++ b/auraxium/_rest.py @@ -48,12 +48,13 @@ class RequestClient: """The REST request handler for Auraxium.""" def __init__(self, loop: Optional[asyncio.AbstractEventLoop] = None, - service_id: str = 's:example', profiling: bool = False - ) -> None: + service_id: str = 's:example', profiling: bool = False, + no_ssl_certs: bool = False) -> None: self.loop = loop or asyncio.get_event_loop() self.profiling = profiling self.service_id = service_id self.session = aiohttp.ClientSession() + self._no_ssl_certs = no_ssl_certs self._timing_cache: List[float] = [] async def __aenter__(self: _T) -> _T: diff --git a/auraxium/event/_client.py b/auraxium/event/_client.py index 5d6ef57..dad4f28 100644 --- a/auraxium/event/_client.py +++ b/auraxium/event/_client.py @@ -2,6 +2,7 @@ import contextlib import json import logging +import ssl from typing import (Any, Callable, Coroutine, Dict, Iterator, List, Optional, Type, TypeVar, Union, cast, overload) @@ -264,7 +265,11 @@ async def _connection_handler(self) -> None: """ _log.info('Connecting to WebSocket endpoint...') url = f'{_ESS_ENDPOINT}?environment=ps2&service-id={self.service_id}' - async with ws_client.connect(url) as websocket: + if self._no_ssl_certs: + ssl_ctx = ssl.SSLContext() + else: + ssl_ctx = None + async with ws_client.connect(url, ssl=ssl_ctx) as websocket: self.websocket = websocket _log.info('Connected to %s?environment=ps2&service-id=XXX', _ESS_ENDPOINT) From 58e8109c6f0323c3d3a342152210590fa8417409 Mon Sep 17 00:00:00 2001 From: Leonhard S Date: Tue, 10 May 2022 13:18:14 +0200 Subject: [PATCH 2/2] Ignore server certs in event client test case --- tests/event_test.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/event_test.py b/tests/event_test.py index 2bc2e5c..2f472dc 100644 --- a/tests/event_test.py +++ b/tests/event_test.py @@ -29,7 +29,8 @@ async def asyncSetUp(self) -> None: """Reset the event streaming client before every test.""" if self._client is not None: await self._client.close() - self._client = auraxium.event.EventClient(service_id=SERVICE_ID) + self._client = auraxium.event.EventClient( + service_id=SERVICE_ID, no_ssl_certs=True) async def asyncTearDown(self) -> None: """Close the event streaming client after every test."""