diff --git a/src/onepasswordconnectsdk/async_client.py b/src/onepasswordconnectsdk/async_client.py index f7e357b..ae920c3 100644 --- a/src/onepasswordconnectsdk/async_client.py +++ b/src/onepasswordconnectsdk/async_client.py @@ -16,14 +16,16 @@ class AsyncClient: """Python Async Client Class""" - def __init__(self, url: str, token: str) -> None: + def __init__(self, url: str, token: str, cert: str = None) -> None: """Initialize async client""" self.url = url self.token = token - self.session = self.create_session(url, token) + self.session = self.create_session(url, token, cert) self.serializer = Serializer() - def create_session(self, url: str, token: str) -> httpx.AsyncClient: + def create_session(self, url: str, token: str, cert: str = None) -> httpx.AsyncClient: + if cert: + return httpx.AsyncClient(base_url=url, headers=self.build_headers(token), verify=cert) return httpx.AsyncClient(base_url=url, headers=self.build_headers(token)) def build_headers(self, token: str) -> Dict[str, str]: diff --git a/src/onepasswordconnectsdk/client.py b/src/onepasswordconnectsdk/client.py index 2b40327..40cc846 100644 --- a/src/onepasswordconnectsdk/client.py +++ b/src/onepasswordconnectsdk/client.py @@ -24,14 +24,16 @@ class Client: """Python Client Class""" - def __init__(self, url: str, token: str) -> None: + def __init__(self, url: str, token: str, cert: str = None) -> None: """Initialize client""" self.url = url self.token = token - self.session = self.create_session(url, token) + self.session = self.create_session(url, token, cert) self.serializer = Serializer() - def create_session(self, url: str, token: str) -> httpx.Client: + def create_session(self, url: str, token: str, cert: str = None) -> httpx.Client: + if cert: + return httpx.Client(base_url=url, headers=self.build_headers(token), verify=cert) return httpx.Client(base_url=url, headers=self.build_headers(token)) def build_headers(self, token: str) -> Dict[str, str]: @@ -381,19 +383,25 @@ def sanitize_for_serialization(self, obj): return self.serializer.sanitize_for_serialization(obj) -def new_client(url: str, token: str, is_async: bool = False) -> Union[AsyncClient, Client]: +def new_client(url: str, token: str, is_async: bool = False, certificate: str = None) -> Union[AsyncClient, Client]: """Builds a new client for interacting with 1Password Connect Parameters: url: The url of the 1Password Connect API token: The 1Password Service Account token is_async: Initialize async or sync client + certificate: Optional path to custom certificate bundle for verification Returns: Client: The 1Password Connect client """ - if is_async: + if is_async and certificate: + return AsyncClient(url, token, certificate) + elif is_async: return AsyncClient(url, token) - return Client(url, token) + elif certificate: + return Client(url, token, certificate) + else: + return Client(url, token) def new_client_from_environment(url: str = None) -> Union[AsyncClient, Client]: