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

Support Callable as http_auth type in AIOHttpConnection #892

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
16 changes: 12 additions & 4 deletions opensearchpy/_async/http_aiohttp.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
import os
import ssl
import warnings
from typing import Any, Collection, Mapping, Optional, Union
from typing import Any, Callable, Collection, Mapping, Optional, Union

import urllib3

Expand Down Expand Up @@ -146,9 +146,14 @@
)

if http_auth is not None:
if isinstance(http_auth, (tuple, list)):
http_auth = ":".join(http_auth)
self.headers.update(urllib3.make_headers(basic_auth=http_auth))
if isinstance(http_auth, Callable): # type: ignore
pass

Check warning on line 150 in opensearchpy/_async/http_aiohttp.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/_async/http_aiohttp.py#L150

Added line #L150 was not covered by tests
elif isinstance(http_auth, (tuple, list)):
self.headers.update(
urllib3.make_headers(basic_auth=":".join(http_auth))
)
else:
self.headers.update(urllib3.make_headers(basic_auth=http_auth))

# if providing an SSL context, raise error if any other SSL related flag is used
if ssl_context and (
Expand Down Expand Up @@ -285,6 +290,9 @@
if headers:
req_headers.update(headers)

if isinstance(self._http_auth, Callable): # type: ignore
req_headers.update(self._http_auth(method, str(url), body))

Check warning on line 294 in opensearchpy/_async/http_aiohttp.py

View check run for this annotation

Codecov / codecov/patch

opensearchpy/_async/http_aiohttp.py#L294

Added line #L294 was not covered by tests

if self.http_compress and body:
body = self._gzip_compress(body)
req_headers["content-encoding"] = "gzip"
Expand Down
Loading