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

[Fix] Configuring SSL proxy via openapi_config object #321

Merged
merged 6 commits into from
Mar 14, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Thread SSL configuration through to index client
  • Loading branch information
jhamon committed Mar 12, 2024
commit dfa9f5eb67b862b8c23d8b326e47b6386c0c42d1
18 changes: 16 additions & 2 deletions pinecone/control/pinecone.py
Original file line number Diff line number Diff line change
Expand Up @@ -515,12 +515,26 @@ def Index(self, name: str = '', host: str = '', **kwargs):
raise ValueError("Either name or host must be specified")

pt = kwargs.pop('pool_threads', None) or self.pool_threads
api_key = self.config.api_key
openapi_config = self.config.openapi_config

if host != '':
# Use host url if it is provided
return Index(api_key=self.config.api_key, host=normalize_host(host), pool_threads=pt, **kwargs)
return Index(
host=normalize_host(host),
api_key=api_key,
pool_threads=pt,
openapi_config=openapi_config,
**kwargs
)

if name != '':
# Otherwise, get host url from describe_index using the index name
index_host = self.index_host_store.get_host(self.index_api, self.config, name)
return Index(api_key=self.config.api_key, host=index_host, pool_threads=pt, **kwargs)
return Index(
host=index_host,
api_key=api_key,
pool_threads=pt,
openapi_config=openapi_config,
**kwargs
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This may be out of the scope for this change since you're just adding the openapi_config param, but it looks like these two blocks are largely identical, differing only by how the host param is init'd

4 changes: 3 additions & 1 deletion pinecone/data/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ def __init__(
host: str,
pool_threads: Optional[int] = 1,
additional_headers: Optional[Dict[str, str]] = {},
openapi_config = None,
**kwargs
):
self._config = ConfigBuilder.build(
api_key=api_key,
host=host,
additional_headers=additional_headers,
additional_headers=additional_headers,
openapi_config=openapi_config,
**kwargs
)
self._vector_api = setup_openapi_client(DataPlaneApi, self._config, pool_threads)
Expand Down
21 changes: 19 additions & 2 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import pytest
import os

from urllib3 import make_headers

class TestConfig:
@pytest.fixture(autouse=True)
def run_before_and_after_tests(tmpdir):
Expand Down Expand Up @@ -87,6 +89,21 @@ def test_config_pool_threads(self):
assert idx._vector_api.api_client.pool_threads == 10

def test_config_when_openapi_config_is_passed_merges_api_key(self):
oai_config = OpenApiConfiguration.get_default_copy()
oai_config = OpenApiConfiguration()
pc = Pinecone(api_key='asdf', openapi_config=oai_config)
assert pc.config.openapi_config.api_key == {'ApiKeyAuth': 'asdf'}
assert pc.config.openapi_config.api_key == {'ApiKeyAuth': 'asdf'}

def test_ssl_config_passed_to_index_client(self):
oai_config = OpenApiConfiguration()
oai_config.ssl_ca_cert = 'path/to/cert'
proxy_headers = make_headers(proxy_basic_auth='asdf')
oai_config.proxy_headers = proxy_headers

pc = Pinecone(api_key='key', openapi_config=oai_config)

assert pc.config.openapi_config.ssl_ca_cert == 'path/to/cert'
assert pc.config.openapi_config.proxy_headers == proxy_headers

idx = pc.Index(host='host')
assert idx._vector_api.api_client.configuration.ssl_ca_cert == 'path/to/cert'
assert idx._vector_api.api_client.configuration.proxy_headers == proxy_headers