Allow passing trust_env to aiohttp.ClientSession (#438)
Fixes #368 Signed-off-by: Michael Oliver <[email protected]>
This commit is contained in:
@@ -14,6 +14,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
|
|||||||
- Enhanced YAML test runner to use OpenSearch rest-api-spec YAML tests ([#414](https://github.com/opensearch-project/opensearch-py/pull/414)
|
- Enhanced YAML test runner to use OpenSearch rest-api-spec YAML tests ([#414](https://github.com/opensearch-project/opensearch-py/pull/414)
|
||||||
- Added `Search#collapse` ([#409](https://github.com/opensearch-project/opensearch-py/issues/409))
|
- Added `Search#collapse` ([#409](https://github.com/opensearch-project/opensearch-py/issues/409))
|
||||||
- Added support for the ISM API ([#398](https://github.com/opensearch-project/opensearch-py/pull/398))
|
- Added support for the ISM API ([#398](https://github.com/opensearch-project/opensearch-py/pull/398))
|
||||||
|
- Added `trust_env` to `AIOHttpConnection` ([#398](https://github.com/opensearch-project/opensearch-py/pull/438))
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
- Upgrading pytest-asyncio to latest version - 0.21.0 ([#339](https://github.com/opensearch-project/opensearch-py/pull/339))
|
- Upgrading pytest-asyncio to latest version - 0.21.0 ([#339](https://github.com/opensearch-project/opensearch-py/pull/339))
|
||||||
- Fixed flaky CI tests by replacing httpbin with a simple http_server ([#395](https://github.com/opensearch-project/opensearch-py/pull/395))
|
- Fixed flaky CI tests by replacing httpbin with a simple http_server ([#395](https://github.com/opensearch-project/opensearch-py/pull/395))
|
||||||
|
|||||||
@@ -35,6 +35,7 @@
|
|||||||
- [Pre-requisites to use `AWSV4SignerAuth`](#pre-requisites-to-use-awsv4signerauth)
|
- [Pre-requisites to use `AWSV4SignerAuth`](#pre-requisites-to-use-awsv4signerauth)
|
||||||
- [Using IAM authentication with an async client](#using-iam-authentication-with-an-async-client)
|
- [Using IAM authentication with an async client](#using-iam-authentication-with-an-async-client)
|
||||||
- [Using Kerberos](#using-kerberos)
|
- [Using Kerberos](#using-kerberos)
|
||||||
|
- [Using environment settings for proxy configuration](#using-environment-settings-for-proxy-configuration)
|
||||||
|
|
||||||
# User guide of OpenSearch Python client
|
# User guide of OpenSearch Python client
|
||||||
|
|
||||||
@@ -686,3 +687,33 @@ client = OpenSearch(
|
|||||||
|
|
||||||
health = client.cluster.health()
|
health = client.cluster.health()
|
||||||
```
|
```
|
||||||
|
|
||||||
|
## Using environment settings for proxy configuration
|
||||||
|
|
||||||
|
Tell connection to get proxy information from `HTTP_PROXY` / `HTTPS_PROXY` environment variables or `~/.netrc` file if present.
|
||||||
|
|
||||||
|
```python
|
||||||
|
from opensearchpy import OpenSearch, RequestsHttpConnection
|
||||||
|
|
||||||
|
|
||||||
|
OpenSearch(
|
||||||
|
hosts=["htps://..."],
|
||||||
|
use_ssl=True,
|
||||||
|
verify_certs=True,
|
||||||
|
connection_class=RequestsHttpConnection,
|
||||||
|
trust_env=True,
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
```python
|
||||||
|
from opensearchpy import AsyncOpenSearch, AIOHttpConnection
|
||||||
|
|
||||||
|
client = AsyncOpenSearch(
|
||||||
|
hosts=["htps://..."],
|
||||||
|
use_ssl=True,
|
||||||
|
verify_certs=True,
|
||||||
|
connection_class=AIOHttpConnection,
|
||||||
|
trust_env=True,
|
||||||
|
)
|
||||||
|
```
|
||||||
|
|||||||
@@ -91,6 +91,7 @@ class AIOHttpConnection(AsyncConnection):
|
|||||||
http_compress=None,
|
http_compress=None,
|
||||||
opaque_id=None,
|
opaque_id=None,
|
||||||
loop=None,
|
loop=None,
|
||||||
|
trust_env=False,
|
||||||
**kwargs
|
**kwargs
|
||||||
):
|
):
|
||||||
"""
|
"""
|
||||||
@@ -219,6 +220,7 @@ class AIOHttpConnection(AsyncConnection):
|
|||||||
self._limit = maxsize
|
self._limit = maxsize
|
||||||
self._http_auth = http_auth
|
self._http_auth = http_auth
|
||||||
self._ssl_context = ssl_context
|
self._ssl_context = ssl_context
|
||||||
|
self._trust_env = trust_env
|
||||||
|
|
||||||
async def perform_request(
|
async def perform_request(
|
||||||
self, method, url, params=None, body=None, timeout=None, ignore=(), headers=None
|
self, method, url, params=None, body=None, timeout=None, ignore=(), headers=None
|
||||||
@@ -367,6 +369,7 @@ class AIOHttpConnection(AsyncConnection):
|
|||||||
connector=aiohttp.TCPConnector(
|
connector=aiohttp.TCPConnector(
|
||||||
limit=self._limit, use_dns_cache=True, ssl=self._ssl_context
|
limit=self._limit, use_dns_cache=True, ssl=self._ssl_context
|
||||||
),
|
),
|
||||||
|
trust_env=self._trust_env,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -66,5 +66,6 @@ class AIOHttpConnection(AsyncConnection):
|
|||||||
http_compress: Optional[bool] = ...,
|
http_compress: Optional[bool] = ...,
|
||||||
opaque_id: Optional[str] = ...,
|
opaque_id: Optional[str] = ...,
|
||||||
loop: Any = ...,
|
loop: Any = ...,
|
||||||
|
trust_env: bool = ...,
|
||||||
**kwargs: Any
|
**kwargs: Any
|
||||||
) -> None: ...
|
) -> None: ...
|
||||||
|
|||||||
@@ -274,6 +274,20 @@ class TestAIOHttpConnection:
|
|||||||
AIOHttpConnection(use_ssl=True, verify_certs=False)
|
AIOHttpConnection(use_ssl=True, verify_certs=False)
|
||||||
load_verify_locations.assert_not_called()
|
load_verify_locations.assert_not_called()
|
||||||
|
|
||||||
|
async def test_trust_env(self):
|
||||||
|
con = AIOHttpConnection(trust_env=True)
|
||||||
|
await con._create_aiohttp_session()
|
||||||
|
|
||||||
|
assert con._trust_env is True
|
||||||
|
assert con.session.trust_env is True
|
||||||
|
|
||||||
|
async def test_trust_env_default_value_is_false(self):
|
||||||
|
con = AIOHttpConnection()
|
||||||
|
await con._create_aiohttp_session()
|
||||||
|
|
||||||
|
assert con._trust_env is False
|
||||||
|
assert con.session.trust_env is False
|
||||||
|
|
||||||
@patch("opensearchpy.connection.base.logger")
|
@patch("opensearchpy.connection.base.logger")
|
||||||
async def test_uncompressed_body_logged(self, logger):
|
async def test_uncompressed_body_logged(self, logger):
|
||||||
con = await self._get_mock_connection(connection_params={"http_compress": True})
|
con = await self._get_mock_connection(connection_params={"http_compress": True})
|
||||||
|
|||||||
Reference in New Issue
Block a user