Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added option to ignore SSL verification #1163

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions integration/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 4 additions & 0 deletions test/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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(
Expand All @@ -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(
Expand All @@ -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":
Expand Down
3 changes: 3 additions & 0 deletions weaviate/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down
1 change: 1 addition & 0 deletions weaviate/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions weaviate/connect/v3.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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'}.
Expand All @@ -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:
Expand Down Expand Up @@ -379,6 +383,7 @@ def delete(
timeout=self._timeout_config,
proxies=self._proxies,
params=params,
verify=self._verify,
)

def patch(
Expand Down Expand Up @@ -420,6 +425,7 @@ def patch(
timeout=self._timeout_config,
proxies=self._proxies,
params=params,
verify=self._verify,
)

def post(
Expand Down Expand Up @@ -463,6 +469,7 @@ def post(
timeout=self._timeout_config,
proxies=self._proxies,
params=params,
verify=self._verify,
)

def put(
Expand Down Expand Up @@ -504,6 +511,7 @@ def put(
timeout=self._timeout_config,
proxies=self._proxies,
params=params,
verify=self._verify,
)

def get(
Expand Down Expand Up @@ -546,6 +554,7 @@ def get(
timeout=self._timeout_config,
params=params,
proxies=self._proxies,
verify=self._verify,
)

def head(
Expand Down Expand Up @@ -584,6 +593,7 @@ def head(
timeout=self._timeout_config,
proxies=self._proxies,
params=params,
verify=self._verify,
)

@property
Expand Down
7 changes: 7 additions & 0 deletions weaviate/connect/v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand All @@ -651,6 +657,7 @@ def __init__(
timeout_config,
proxies,
trust_env,
verify,
additional_headers,
connection_config,
embedded_db,
Expand Down