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: re-add service to fix integration with LangChain. #603

Merged
merged 1 commit into from
Nov 17, 2023
Merged
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
### Removed
### Fixed
- Fix `TypeError` on `parallel_bulk` ([#601](https://github.com/opensearch-project/opensearch-py/pull/601))
- Fix Amazon OpenSearch Serverless integration with LangChain ([#603](https://github.com/opensearch-project/opensearch-py/pull/603))
### Security

## [2.4.1]
Expand Down
2 changes: 2 additions & 0 deletions opensearchpy/helpers/signer.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ class RequestsAWSV4SignerAuth(requests.auth.AuthBase):

def __init__(self, credentials, region, service: str = "es") -> None: # type: ignore
self.signer = AWSV4Signer(credentials, region, service)
self.service = service # tools like LangChain rely on this, see https://github.com/opensearch-project/opensearch-py/issues/600

def __call__(self, request): # type: ignore
return self._sign_request(request) # type: ignore
Expand Down Expand Up @@ -133,6 +134,7 @@ class AWSV4SignerAuth(RequestsAWSV4SignerAuth):
class Urllib3AWSV4SignerAuth(Callable): # type: ignore
def __init__(self, credentials, region, service: str = "es") -> None: # type: ignore
self.signer = AWSV4Signer(credentials, region, service)
self.service = service # tools like LangChain rely on this, see https://github.com/opensearch-project/opensearch-py/issues/600

def __call__(self, method: str, url: str, body: Any) -> Dict[str, str]:
return self.signer.sign(method, url, body)
Original file line number Diff line number Diff line change
Expand Up @@ -460,6 +460,7 @@ def test_aws_signer_as_http_auth(self) -> None:
from opensearchpy.helpers.signer import RequestsAWSV4SignerAuth

auth = RequestsAWSV4SignerAuth(self.mock_session(), region)
self.assertEqual(auth.service, "es")
con = RequestsHttpConnection(http_auth=auth)
prepared_request = requests.Request("GET", "http://localhost").prepare()
auth(prepared_request)
Expand All @@ -478,6 +479,7 @@ def test_aws_signer_when_service_is_specified(self) -> None:
from opensearchpy.helpers.signer import RequestsAWSV4SignerAuth

auth = RequestsAWSV4SignerAuth(self.mock_session(), region, service)
self.assertEqual(auth.service, service)
con = RequestsHttpConnection(http_auth=auth)
prepared_request = requests.Request("GET", "http://localhost").prepare()
auth(prepared_request)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def test_aws_signer_as_http_auth_adds_headers(self, mock_open: Any) -> None:
from opensearchpy.helpers.signer import Urllib3AWSV4SignerAuth

auth = Urllib3AWSV4SignerAuth(self.mock_session(), "us-west-2")
self.assertEqual(auth.service, "es")
con = Urllib3HttpConnection(http_auth=auth, headers={"x": "y"})
con.perform_request("GET", "/")
self.assertEqual(mock_open.call_count, 1)
Expand Down Expand Up @@ -249,6 +250,7 @@ def test_aws_signer_when_service_is_specified(self) -> None:
from opensearchpy.helpers.signer import Urllib3AWSV4SignerAuth

auth = Urllib3AWSV4SignerAuth(self.mock_session(), region, service)
self.assertEqual(auth.service, service)
headers = auth("GET", "http://localhost", None)
self.assertIn("Authorization", headers)
self.assertIn("X-Amz-Date", headers)
Expand Down
Loading