Skip to content

Commit

Permalink
Merge branch 'main' into fix/compatibility_matrix
Browse files Browse the repository at this point in the history
  • Loading branch information
dblock authored Jan 2, 2023
2 parents 2d333b7 + cfb2cf7 commit 58947a7
Show file tree
Hide file tree
Showing 14 changed files with 542 additions and 8 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
- Added overload decorators to helpers-actions.pyi-"bulk" ([#239](https://github.com/opensearch-project/opensearch-py/pull/239))
- Document Keberos authenticaion ([214](https://github.com/opensearch-project/opensearch-py/pull/214))
- Add release workflows ([#240](https://github.com/opensearch-project/opensearch-py/pull/240))
- Added new OpenSearch versions and updated compatibility matrix ([#257](https://github.com/opensearch-project/opensearch-py/pull/257))
- Added SigV4 support for Async Opensearch Client ([#254](https://github.com/opensearch-project/opensearch-py/pull/254))
- Compatibility with OpenSearch 2.1.0 - 2.4.1 ([#257](https://github.com/opensearch-project/opensearch-py/pull/257))
### Changed
- Updated getting started to user guide ([#233](https://github.com/opensearch-project/opensearch-py/pull/233))
- Updated CA certificate handling to check OpenSSL environment variables before defaulting to certifi ([#196](https://github.com/opensearch-project/opensearch-py/pull/196))
Expand Down
52 changes: 49 additions & 3 deletions USER_GUIDE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
- [User guide of OpenSearch Python Client](#user-guide-of-opensearch-python-client)
- [User guide of OpenSearch Python client](#user-guide-of-opensearch-python-client)
- [Setup](#setup)
- [Example](#example)
- [Creating a client](#creating-a-client)
Expand All @@ -9,8 +9,8 @@
- [Searching for a document](#searching-for-a-document)
- [Deleting a document](#deleting-a-document)
- [Deleting an index](#deleting-an-index)
- [Making API Calls](#making-api-calls)
- [Point in Time API](#point-in-time-api)
- [Making API calls](#making-api-calls)
- [Point in time API](#point-in-time-api)
- [Using plugins](#using-plugins)
- [Alerting plugin](#alerting-plugin)
- [**Searching for monitors**](#searching-for-monitors)
Expand All @@ -22,6 +22,7 @@
- [Using different authentication methods](#using-different-authentication-methods)
- [Using IAM credentials](#using-iam-credentials)
- [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 Kerberos](#using-kerberos)

# User guide of OpenSearch Python client
Expand Down Expand Up @@ -439,6 +440,51 @@ print('\nSearch results:')
print(response)
```

## Using IAM authentication with an async client

Make sure to use the `AsyncHttpConnection` connection class with the async `AWSV4SignerAsyncAuth` signer.

```python
from opensearchpy import OpenSearch, AsyncHttpConnection, AWSV4SignerAsyncAuth
import boto3

host = '' # cluster endpoint, for example: my-test-domain.us-east-1.es.amazonaws.com
region = 'us-west-2'
credentials = boto3.Session().get_credentials()
auth = AWSV4SignerAsyncAuth(credentials, region)
index_name = 'python-test-index3'

client = OpenSearch(
hosts = [{'host': host, 'port': 443}],
http_auth = auth,
use_ssl = True,
verify_certs = True,
connection_class = AsyncHttpConnection
)

async def search():
q = 'miller'
query = {
'size': 5,
'query': {
'multi_match': {
'query': q,
'fields': ['title^2', 'director']
}
}
}

response = await client.search(
body = query,
index = index_name
)

print('\nSearch results:')
print(response)

search()
```
=======
### Using Kerberos

There are several python packages that provide Kerberos support over HTTP connections, such as [requests-kerberos](http://pypi.org/project/requests-kerberos) and [requests-gssapi](https://pypi.org/project/requests-gssapi). The following example shows how to setup the authentication. Note that some of the parameters, such as `mutual_authentication` might depend on the server settings.
Expand Down
6 changes: 5 additions & 1 deletion opensearchpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
SSLError,
TransportError,
)
from .helpers import AWSV4SignerAuth
from .helpers import AWSV4SignerAsyncAuth, AWSV4SignerAuth
from .serializer import JSONSerializer
from .transport import Transport

Expand All @@ -79,6 +79,7 @@
"JSONSerializer",
"Connection",
"RequestsHttpConnection",
"AsyncHttpConnection",
"Urllib3HttpConnection",
"ImproperlyConfigured",
"OpenSearchException",
Expand All @@ -95,6 +96,7 @@
"OpenSearchWarning",
"OpenSearchDeprecationWarning",
"AWSV4SignerAuth",
"AWSV4SignerAsyncAuth",
]

try:
Expand All @@ -105,12 +107,14 @@
from ._async.client import AsyncOpenSearch
from ._async.http_aiohttp import AIOHttpConnection, AsyncConnection
from ._async.transport import AsyncTransport
from .connection import AsyncHttpConnection

__all__ += [
"AIOHttpConnection",
"AsyncConnection",
"AsyncTransport",
"AsyncOpenSearch",
"AsyncHttpConnection",
]
except (ImportError, SyntaxError):
pass
2 changes: 2 additions & 0 deletions opensearchpy/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import sys
from typing import Tuple

from .client import OpenSearch as OpenSearch
from .connection import AsyncHttpConnection as AsyncHttpConnection
from .connection import Connection as Connection
from .connection import RequestsHttpConnection as RequestsHttpConnection
from .connection import Urllib3HttpConnection as Urllib3HttpConnection
Expand Down Expand Up @@ -57,6 +58,7 @@ try:
from ._async.client import AsyncOpenSearch as AsyncOpenSearch
from ._async.http_aiohttp import AIOHttpConnection as AIOHttpConnection
from ._async.transport import AsyncTransport as AsyncTransport
from .helpers import AWSV4SignerAsyncAuth as AWSV4SignerAsyncAuth
from .helpers import AWSV4SignerAuth as AWSV4SignerAuth
except (ImportError, SyntaxError):
pass
Expand Down
15 changes: 15 additions & 0 deletions opensearchpy/connection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
# under the License.


import sys

from .base import Connection
from .http_requests import RequestsHttpConnection
from .http_urllib3 import Urllib3HttpConnection, create_ssl_context
Expand All @@ -35,3 +37,16 @@
"Urllib3HttpConnection",
"create_ssl_context",
]

try:
# Asyncio only supported on Python 3.6+
if sys.version_info < (3, 6):
raise ImportError

from .http_async import AsyncHttpConnection

__all__ += [
"AsyncHttpConnection",
]
except (ImportError, SyntaxError):
pass
1 change: 1 addition & 0 deletions opensearchpy/connection/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
# under the License.

from .base import Connection as Connection
from .http_async import AsyncHttpConnection as AsyncHttpConnection
from .http_requests import RequestsHttpConnection as RequestsHttpConnection
from .http_urllib3 import Urllib3HttpConnection as Urllib3HttpConnection
from .http_urllib3 import create_ssl_context as create_ssl_context
Loading

0 comments on commit 58947a7

Please sign in to comment.