diff --git a/CHANGELOG.md b/CHANGELOG.md index f86c5795..b5e2edf8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Added - Added option to pass custom headers to 'AWSV4SignerAsyncAuth' ([863](https://github.com/opensearch-project/opensearch-py/pull/863)) - Added sync and async sample that uses `search_after` parameter ([859](https://github.com/opensearch-project/opensearch-py/pull/859)) +- Added support for `trust_env` to `AsyncHttpConnection` ([886](https://github.com/opensearch-project/opensearch-py/pull/886)) + ### Updated APIs ### Changed - Small refactor of AWS Signer classes for both sync and async clients ([866](https://github.com/opensearch-project/opensearch-py/pull/866)) diff --git a/opensearchpy/connection/http_async.py b/opensearchpy/connection/http_async.py index 0f3f8004..1c2e24b6 100644 --- a/opensearchpy/connection/http_async.py +++ b/opensearchpy/connection/http_async.py @@ -54,6 +54,7 @@ def __init__( http_compress: Optional[bool] = None, opaque_id: Optional[str] = None, loop: Any = None, + trust_env: Optional[bool] = False, **kwargs: Any, ) -> None: self.headers = {} @@ -65,6 +66,7 @@ def __init__( headers=headers, http_compress=http_compress, opaque_id=opaque_id, + trust_env=trust_env, **kwargs, ) @@ -290,6 +292,7 @@ async def _create_aiohttp_session(self) -> Any: connector=aiohttp.TCPConnector( limit=self._limit, use_dns_cache=True, ssl=self._ssl_context ), + trust_env=self._trust_env, ) diff --git a/test_opensearchpy/test_async/test_http_connection.py b/test_opensearchpy/test_async/test_http_connection.py index 8568a6f8..ba01b1eb 100644 --- a/test_opensearchpy/test_async/test_http_connection.py +++ b/test_opensearchpy/test_async/test_http_connection.py @@ -135,3 +135,15 @@ def auth_fn(*args: Any, **kwargs: Any) -> Any: ), fingerprint=None, ) + + @pytest.mark.asyncio # type: ignore + async def test_trust_env_default_off(self) -> None: + conn = AsyncHttpConnection(loop=get_running_loop()) + await conn._create_aiohttp_session() + assert not conn.session.trust_env + + @pytest.mark.asyncio # type: ignore + async def test_trust_env_on(self) -> None: + conn = AsyncHttpConnection(loop=get_running_loop(), trust_env=True) + await conn._create_aiohttp_session() + assert conn.session.trust_env