-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support overriding
additional_headers
with `PINECONE_ADDITIONAL_HEA…
…DERS` environment variable (#304) ## Problem We need a way to attach special request headers in integration testing. ## Solution Add support for overriding additional_headers via the `PINECONE_ADDITIONAL_HEADERS` environment variable. ## Type of Change - [x] New feature (non-breaking change which adds functionality) ## Test Plan Unit tests ``` $ cd pinecone-python-client/ $ export PINECONE_ADDITIONAL_HEADERS='{"header": "value"}' $ python3 >>> from pinecone import Pinecone >>> client = Pinecone(api_key='key', host='host') >>> vars(client) {'config': ... additional_headers={'header': 'value'}), ...} ``` --------- Co-authored-by: Jennifer Hamon <jhamon@pinecone.io>
- Loading branch information
Showing
2 changed files
with
19 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,24 @@ | ||
from typing import Optional, Dict | ||
import logging | ||
import json | ||
import os | ||
from .config import ConfigBuilder, Config | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
DEFAULT_CONTROLLER_HOST = "https://api.pinecone.io" | ||
|
||
|
||
class PineconeConfig(): | ||
@staticmethod | ||
def build(api_key: Optional[str] = None, host: Optional[str] = None, additional_headers: Optional[Dict[str, str]] = {}, **kwargs) -> Config: | ||
host = host or kwargs.get("host") or os.getenv("PINECONE_CONTROLLER_HOST") or DEFAULT_CONTROLLER_HOST | ||
headers_json = os.getenv("PINECONE_ADDITIONAL_HEADERS") | ||
if headers_json: | ||
try: | ||
headers = json.loads(headers_json) | ||
additional_headers = additional_headers or headers | ||
except Exception as e: | ||
logger.warn(f'Ignoring PINECONE_ADDITIONAL_HEADERS: {e}') | ||
|
||
return ConfigBuilder.build(api_key=api_key, host=host, additional_headers=additional_headers, **kwargs) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters