Skip to content

Commit 4dced5e

Browse files
authored
Expose SSL configurations for PineconeAsyncio (#449)
## Problem Need to wire up several properties that pass configurations in to the underlying aiohttp library. ## Solution Wire up several properties for `PineconeAsyncio` that are already supported in `Pinecone`: - `additional_headers` to pass extra headers on each request. Useful for internal testing. - `ssl_verify` to turn off ssl verification. Sometimes useful for testing. - `proxy_url` to send traffic through a proxy - `ssl_ca_certs` to specify a custom cert bundle. Expecting a path to a PEM file. Currently `proxy_headers` is not accepted by `PineconeAsyncio` because I haven't figured out how to use these with aiohttp. ## Type of Change - [x] New feature (non-breaking change which adds functionality)
1 parent 8a2afef commit 4dced5e

File tree

4 files changed

+44
-29
lines changed

4 files changed

+44
-29
lines changed

pinecone/control/pinecone.py

+5-8
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,11 @@ def __init__(
6363
pool_threads: Optional[int] = None,
6464
**kwargs,
6565
):
66-
if kwargs.get("config", None):
67-
raise Exception(
68-
"Passing config is no longer supported. Please pass individual settings such as proxy_url, proxy_headers, ssl_ca_certs, and ssl_verify directly to the Pinecone constructor as keyword arguments. See the README at https://github.com/pinecone-io/pinecone-python-client for examples."
69-
)
70-
if kwargs.get("openapi_config", None):
71-
raise Exception(
72-
"Passing openapi_config is no longer supported. Please pass individual settings such as proxy_url, proxy_headers, ssl_ca_certs, and ssl_verify directly to the Pinecone constructor as keyword arguments. See the README at https://github.com/pinecone-io/pinecone-python-client for examples."
73-
)
66+
for deprecated_kwarg in {"config", "openapi_config"}:
67+
if deprecated_kwarg in kwargs:
68+
raise NotImplementedError(
69+
f"Passing {deprecated_kwarg} is no longer supported. Please pass individual settings such as proxy_url, proxy_headers, ssl_ca_certs, and ssl_verify directly to the Pinecone constructor as keyword arguments. See the README at {docslinks['README']} for examples."
70+
)
7471

7572
self.config = PineconeConfig.build(
7673
api_key=api_key,

pinecone/control/pinecone_asyncio.py

+17-17
Original file line numberDiff line numberDiff line change
@@ -51,33 +51,33 @@ def __init__(
5151
self,
5252
api_key: Optional[str] = None,
5353
host: Optional[str] = None,
54-
# proxy_url: Optional[str] = None,
54+
proxy_url: Optional[str] = None,
5555
# proxy_headers: Optional[Dict[str, str]] = None,
56-
# ssl_ca_certs: Optional[str] = None,
57-
# ssl_verify: Optional[bool] = None,
58-
# additional_headers: Optional[Dict[str, str]] = {},
56+
ssl_ca_certs: Optional[str] = None,
57+
ssl_verify: Optional[bool] = None,
58+
additional_headers: Optional[Dict[str, str]] = {},
5959
**kwargs,
6060
):
61-
for kwarg in {
62-
"additional_headers",
63-
"proxy_url",
64-
"proxy_headers",
65-
"ssl_ca_certs",
66-
"ssl_verify",
67-
}:
68-
if kwarg in kwargs:
61+
for deprecated_kwarg in {"config", "openapi_config"}:
62+
if deprecated_kwarg in kwargs:
6963
raise NotImplementedError(
70-
f"You have passed {kwarg} but this configuration has not been implemented yet for PineconeAsyncio."
64+
f"Passing {deprecated_kwarg} is no longer supported. Please pass individual settings such as proxy_url, ssl_ca_certs, and ssl_verify directly to the Pinecone constructor as keyword arguments. See the README at {docslinks['README']} for examples."
65+
)
66+
67+
for unimplemented_kwarg in {"proxy_headers"}:
68+
if unimplemented_kwarg in kwargs:
69+
raise NotImplementedError(
70+
f"You have passed {unimplemented_kwarg} but this configuration has not been implemented for PineconeAsyncio."
7171
)
7272

7373
self.config = PineconeConfig.build(
7474
api_key=api_key,
7575
host=host,
76-
additional_headers=None,
77-
proxy_url=None,
76+
additional_headers=additional_headers,
77+
proxy_url=proxy_url,
7878
proxy_headers=None,
79-
ssl_ca_certs=None,
80-
ssl_verify=None,
79+
ssl_ca_certs=ssl_ca_certs,
80+
ssl_verify=ssl_verify,
8181
**kwargs,
8282
)
8383
self.openapi_config = ConfigBuilder.build_openapi_config(self.config, **kwargs)

pinecone/openapi_support/rest_aiohttp.py

+17-3
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,32 @@
1+
import ssl
2+
import certifi
13
import json
24
from .rest_utils import RestClientInterface, RESTResponse, raise_exceptions_or_return
5+
from .configuration import Configuration
36

47

58
class AiohttpRestClient(RestClientInterface):
6-
def __init__(self, configuration) -> None:
9+
def __init__(self, configuration: Configuration) -> None:
710
try:
811
import aiohttp
912
except ImportError:
1013
raise ImportError(
1114
"Additional dependencies are required to use Pinecone with asyncio. Include these extra dependencies in your project by installing `pinecone[asyncio]`."
1215
) from None
1316

14-
conn = aiohttp.TCPConnector()
15-
self._session = aiohttp.ClientSession(connector=conn)
17+
if configuration.ssl_ca_cert is not None:
18+
ca_certs = configuration.ssl_ca_cert
19+
else:
20+
ca_certs = certifi.where()
21+
22+
ssl_context = ssl.create_default_context(cafile=ca_certs)
23+
24+
conn = aiohttp.TCPConnector(verify_ssl=configuration.verify_ssl, ssl=ssl_context)
25+
26+
if configuration.proxy:
27+
self._session = aiohttp.ClientSession(connector=conn, proxy=configuration.proxy)
28+
else:
29+
self._session = aiohttp.ClientSession(connector=conn)
1630

1731
async def close(self):
1832
await self._session.close()

pinecone/openapi_support/rest_urllib3.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
import logging
33
import ssl
44
import os
5+
from typing import Optional
56
from urllib.parse import urlencode, quote
7+
from .configuration import Configuration
68
from .rest_utils import raise_exceptions_or_return, RESTResponse, RestClientInterface
79

810
import urllib3
@@ -28,7 +30,9 @@ class bcolors:
2830
class Urllib3RestClient(RestClientInterface):
2931
pool_manager: urllib3.PoolManager
3032

31-
def __init__(self, configuration, pools_size=4, maxsize=None) -> None:
33+
def __init__(
34+
self, configuration: Configuration, pools_size: int = 4, maxsize: Optional[int] = None
35+
) -> None:
3236
# urllib3.PoolManager will pass all kw parameters to connectionpool
3337
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/poolmanager.py#L75 # noqa: E501
3438
# https://github.com/shazow/urllib3/blob/f9409436f83aeb79fbaf090181cd81b784f1b8ce/urllib3/connectionpool.py#L680 # noqa: E501

0 commit comments

Comments
 (0)