From 11c2d5c10773f7bbb095159b608ffd6e4c3f2866 Mon Sep 17 00:00:00 2001 From: dhanshew72 Date: Fri, 5 Jul 2024 09:29:42 -0700 Subject: [PATCH] Added option to ignore SSL verification --- integration/test_client.py | 17 +++++++++++++++++ test/test_client.py | 4 ++++ weaviate/client.py | 3 +++ weaviate/config.py | 1 + weaviate/connect/v3.py | 10 ++++++++++ weaviate/connect/v4.py | 7 +++++++ 6 files changed, 42 insertions(+) diff --git a/integration/test_client.py b/integration/test_client.py index 7406d546b..6bda00dc8 100644 --- a/integration/test_client.py +++ b/integration/test_client.py @@ -483,6 +483,23 @@ def test_client_with_extra_options(timeout: Union[Tuple[int, int], Timeout]) -> assert client._connection.timeout_config == Timeout(query=1, insert=2, init=2) +def test_client_with_verify() -> None: + additional_config = wvc.init.AdditionalConfig( + timeout=Timeout(query=1, insert=2, init=2), trust_env=True, verify=False + ) + client = weaviate.connect_to_custom( + http_secure=True, + http_host=WCS_HOST, + http_port=443, + grpc_secure=True, + grpc_host=WCS_GRPC_HOST, + grpc_port=443, + auth_credentials=WCS_CREDS, + additional_config=additional_config, + ) + assert not client._connection.verify + + def test_client_error_for_wcs_without_auth() -> None: with pytest.raises(weaviate.exceptions.AuthenticationFailedError) as e: weaviate.connect_to_wcs(cluster_url=WCS_URL, auth_credentials=None) diff --git a/test/test_client.py b/test/test_client.py index cde8c90cb..3a417e99c 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -51,6 +51,7 @@ def test___init__(self, mock_get_meta_method): embedded_db=None, grcp_port=None, connection_config=ConnectionConfig(), + verify=True, ) with patch( @@ -75,6 +76,7 @@ def test___init__(self, mock_get_meta_method): embedded_db=None, grcp_port=None, connection_config=ConnectionConfig(), + verify=True, ) with patch( @@ -95,6 +97,7 @@ def test___init__(self, mock_get_meta_method): embedded_db=None, grcp_port=None, connection_config=ConnectionConfig(), + verify=True, ) with patch( @@ -121,6 +124,7 @@ def test___init__(self, mock_get_meta_method): embedded_db=None, grcp_port=None, connection_config=ConnectionConfig(), + verify=True, ) if platform == "linux": diff --git a/weaviate/client.py b/weaviate/client.py index 8a84e16a4..1eee904e0 100644 --- a/weaviate/client.py +++ b/weaviate/client.py @@ -201,6 +201,7 @@ def __init__( connection_config=config.connection, proxies=config.proxies, trust_env=config.trust_env, + verify=config.verify, ) self.backup = _Backup(self._connection) @@ -384,6 +385,7 @@ def __init__( timeout_config: TIMEOUT_TYPE = (10, 60), proxies: Union[dict, str, None] = None, trust_env: bool = False, + verify: bool = True, additional_headers: Optional[dict] = None, startup_period: Optional[int] = None, embedded_options: Optional[EmbeddedOptions] = None, @@ -449,6 +451,7 @@ def __init__( timeout_config=_get_valid_timeout_config(timeout_config), proxies=proxies, trust_env=trust_env, + verify=verify, additional_headers=additional_headers, startup_period=startup_period, embedded_db=embedded_db, diff --git a/weaviate/config.py b/weaviate/config.py index 8ed905138..534888728 100644 --- a/weaviate/config.py +++ b/weaviate/config.py @@ -76,6 +76,7 @@ class AdditionalConfig(BaseModel): proxies: Union[str, Proxies, None] = Field(default=None) timeout_: Union[Tuple[int, int], Timeout] = Field(default_factory=Timeout, alias="timeout") trust_env: bool = Field(default=False) + verify: bool = Field(default=True) @property def timeout(self) -> Timeout: diff --git a/weaviate/connect/v3.py b/weaviate/connect/v3.py index 04bbfd08e..e9b0ae507 100644 --- a/weaviate/connect/v3.py +++ b/weaviate/connect/v3.py @@ -61,6 +61,7 @@ def __init__( timeout_config: TIMEOUT_TYPE_RETURN, proxies: Union[dict, str, None], trust_env: bool, + verify: bool, additional_headers: Optional[Dict[str, Any]], startup_period: Optional[int], connection_config: ConnectionConfig, @@ -92,6 +93,8 @@ def __init__( or https_proxy). NOTE: 'proxies' has priority over 'trust_env', i.e. if 'proxies' is NOT None, 'trust_env' is ignored. + verify : bool, optional + Whether to enable SSL verification additional_headers : Dict[str, Any] or None Additional headers to include in the requests, used to set OpenAI key. OpenAI key looks like this: {'X-OpenAI-Api-Key': 'KEY'}. @@ -112,6 +115,7 @@ def __init__( self.embedded_db = embedded_db self._grpc_stub: Optional[weaviate_pb2_grpc.WeaviateStub] = None + self._verify = verify # create GRPC channel. If weaviate does not support GRPC, fallback to GraphQL is used. if grcp_port is not None: @@ -379,6 +383,7 @@ def delete( timeout=self._timeout_config, proxies=self._proxies, params=params, + verify=self._verify, ) def patch( @@ -420,6 +425,7 @@ def patch( timeout=self._timeout_config, proxies=self._proxies, params=params, + verify=self._verify, ) def post( @@ -463,6 +469,7 @@ def post( timeout=self._timeout_config, proxies=self._proxies, params=params, + verify=self._verify, ) def put( @@ -504,6 +511,7 @@ def put( timeout=self._timeout_config, proxies=self._proxies, params=params, + verify=self._verify, ) def get( @@ -546,6 +554,7 @@ def get( timeout=self._timeout_config, params=params, proxies=self._proxies, + verify=self._verify, ) def head( @@ -584,6 +593,7 @@ def head( timeout=self._timeout_config, proxies=self._proxies, params=params, + verify=self._verify, ) @property diff --git a/weaviate/connect/v4.py b/weaviate/connect/v4.py index 1f46dbd3a..d110b123f 100644 --- a/weaviate/connect/v4.py +++ b/weaviate/connect/v4.py @@ -91,6 +91,7 @@ def __init__( timeout_config: TimeoutConfig, proxies: Union[str, Proxies, None], trust_env: bool, + verify: bool, additional_headers: Optional[Dict[str, Any]], connection_config: ConnectionConfig, embedded_db: Optional[EmbeddedV4] = None, @@ -110,6 +111,7 @@ def __init__( self.timeout_config = timeout_config self.__connection_config = connection_config self.__trust_env = trust_env + self.verify = verify self._weaviate_version = _ServerVersion.from_string("") self.__connected = False @@ -209,6 +211,7 @@ def __make_mounts( proxy=proxy, retries=self.__connection_config.session_pool_max_retries, trust_env=self.__trust_env, + verify=self.verify, ) for key, proxy in self._proxies.items() if key != "grpc" @@ -221,6 +224,7 @@ def __make_sync_client(self) -> Client: None, connect=self.timeout_config.query, read=self.timeout_config.insert ), mounts=self.__make_mounts("sync"), + verify=self.verify, ) def __make_async_client(self) -> AsyncClient: @@ -230,6 +234,7 @@ def __make_async_client(self) -> AsyncClient: None, connect=self.timeout_config.query, read=self.timeout_config.insert ), mounts=self.__make_mounts("async"), + verify=self.verify, ) def __make_clients(self) -> None: @@ -641,6 +646,7 @@ def __init__( timeout_config: TimeoutConfig, proxies: Union[str, Proxies, None], trust_env: bool, + verify: bool, additional_headers: Optional[Dict[str, Any]], connection_config: ConnectionConfig, embedded_db: Optional[EmbeddedV4] = None, @@ -651,6 +657,7 @@ def __init__( timeout_config, proxies, trust_env, + verify, additional_headers, connection_config, embedded_db,