@@ -35,6 +35,7 @@ def __init__(
3535 server = "my.geotab.com" ,
3636 timeout = DEFAULT_TIMEOUT ,
3737 proxies = None ,
38+ cert = None
3839 ):
3940 """
4041 Initialize the asynchronous MyGeotab API object with credentials.
@@ -46,9 +47,10 @@ def __init__(
4647 :param server: The server ie. my23.geotab.com. Optional as this usually gets resolved upon authentication.
4748 :param timeout: The timeout to make the call, in seconds. By default, this is 300 seconds (or 5 minutes).
4849 :param proxies: The proxies dictionary to apply to the request.
50+ :param cert: The path to client certificate. A single path to .pem file or a Tuple (.cer file, .pem file)
4951 :raise Exception: Raises an Exception if a username, or one of the session_id or password is not provided.
5052 """
51- super ().__init__ (username , password , database , session_id , server , timeout , proxies = proxies )
53+ super ().__init__ (username , password , database , session_id , server , timeout , proxies = proxies , cert = cert )
5254
5355 async def call_async (self , method , ** parameters ):
5456 """Makes an async call to the API.
@@ -68,7 +70,7 @@ async def call_async(self, method, **parameters):
6870 params ["credentials" ] = self .credentials .get_param ()
6971
7072 try :
71- result = await _query (self ._server , method , params , verify_ssl = self ._is_verify_ssl )
73+ result = await _query (self ._server , method , params , verify_ssl = self ._is_verify_ssl , cert = self . _cert )
7274 if result is not None :
7375 self .__reauthorize_count = 0
7476 return result
@@ -181,14 +183,15 @@ async def server_call_async(method, server, timeout=DEFAULT_TIMEOUT, verify_ssl=
181183 return await _query (server , method , parameters , timeout = timeout , verify_ssl = verify_ssl )
182184
183185
184- async def _query (server , method , parameters , timeout = DEFAULT_TIMEOUT , verify_ssl = True ):
186+ async def _query (server , method , parameters , timeout = DEFAULT_TIMEOUT , verify_ssl = True , cert = None ):
185187 """Formats and performs the asynchronous query against the API
186188
187189 :param server: The server to query.
188190 :param method: The method name.
189191 :param parameters: A dict of parameters to send
190192 :param timeout: The timeout to make the call, in seconds. By default, this is 300 seconds (or 5 minutes).
191193 :param verify_ssl: Whether or not to verify SSL connections
194+ :param cert: The path to client certificate. A single path to .pem file or a Tuple (.cer file, .pem file)
192195 :return: The JSON-decoded result from the server
193196 :raise MyGeotabException: Raises when an exception occurs on the MyGeotab server
194197 :raise TimeoutException: Raises when the request does not respond after some time.
@@ -197,7 +200,18 @@ async def _query(server, method, parameters, timeout=DEFAULT_TIMEOUT, verify_ssl
197200 api_endpoint = api .get_api_url (server )
198201 params = dict (id = - 1 , method = method , params = parameters )
199202 headers = get_headers ()
200- conn = aiohttp .TCPConnector (ssl = ssl .SSLContext (ssl .PROTOCOL_TLSv1_2 ) if verify_ssl else False )
203+
204+ ssl_context = False
205+ if verify_ssl or cert :
206+ ssl_context = ssl .SSLContext (ssl .PROTOCOL_TLSv1_2 )
207+ if cert :
208+ if isinstance (cert , str ):
209+ ssl_context .load_cert_chain (cert )
210+ elif isinstance (cert , tuple ):
211+ cer , key = cert
212+ ssl_context .load_cert_chain (cer , key )
213+
214+ conn = aiohttp .TCPConnector (ssl = ssl_context )
201215 try :
202216 async with aiohttp .ClientSession (connector = conn ) as session :
203217 response = await session .post (
0 commit comments