Skip to content

Commit

Permalink
Ensure SSL certificate loading is done in a non-blocking fashion
Browse files Browse the repository at this point in the history
  • Loading branch information
masaccio committed Oct 27, 2024
1 parent ded8670 commit f19764b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ name = "kingspan-connect-sensor"
packages = [{include = "connectsensor", from = "src"}]
readme = "README.md"
repository = "https://github.com/masaccio/kingspan-connect-sensor"
version = "3.0.4"
version = "3.0.5"

[tool.poetry.dependencies]
async-property = "^0.2.1"
Expand Down
18 changes: 15 additions & 3 deletions src/connectsensor/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from zeep import Client as SoapClient
from zeep import AsyncClient as AsyncSoapClient

from asyncio import get_running_loop
from .tank import Tank, AsyncTank
from .exceptions import APIError

Expand Down Expand Up @@ -70,17 +71,28 @@ def _get_history(self, signalman_no, start_date=None, end_date=None):

class AsyncSensorClient:
def __init__(self, base=DEFAULT_SERVER):
url = urljoin(base, WSDL_PATH)
self._soap_client = AsyncSoapClient(url)
self._soap_client.set_ns_prefix(None, "http://mobileapp/")
self._soap_url = urljoin(base, WSDL_PATH)
self._soap_client = None

async def __aenter__(self):
return self

async def __aexit__(self, exc_t, exc_v, exc_tb):
pass

async def _init_zeep(self):
# Zeep.AsyncClient uses httpx which loads SSL cerficates at construction
# time. An alternative would be disabling certificate verification.
loop = get_running_loop()
self._soap_client = await loop.run_in_executor(
None, AsyncSoapClient, self._soap_url
)
self._soap_client.set_ns_prefix(None, "http://mobileapp/")

async def login(self, username, password):
if self._soap_client is None:
await self._init_zeep()

self._username = username
self._password = password

Expand Down

0 comments on commit f19764b

Please sign in to comment.