Fix Amazon OpenSearch Serverless integration with LangChain. (#603)

Signed-off-by: dblock <[email protected]>
This commit is contained in:
Daniel (dB.) Doubrovkine
2023-11-17 16:09:19 -05:00
committed by GitHub
parent c66e1e37be
commit 7509a15ef3
4 changed files with 7 additions and 0 deletions
+1
View File
@@ -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]
+2
View File
@@ -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
@@ -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)
@@ -460,6 +460,7 @@ class TestRequestsHttpConnection(TestCase):
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)
@@ -478,6 +479,7 @@ class TestRequestsHttpConnection(TestCase):
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)
@@ -192,6 +192,7 @@ class TestUrllib3HttpConnection(TestCase):
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)
@@ -249,6 +250,7 @@ class TestUrllib3HttpConnection(TestCase):
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)