Skip to content

Commit f06d442

Browse files
committed
support Callable as http_auth type
Signed-off-by: Satoshi Kashima <[email protected]>
1 parent 7336f51 commit f06d442

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

opensearchpy/_async/http_aiohttp.py

+12-4
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
import os
3030
import ssl
3131
import warnings
32-
from typing import Any, Collection, Mapping, Optional, Union
32+
from typing import Any, Callable, Collection, Mapping, Optional, Union
3333

3434
import urllib3
3535

@@ -146,9 +146,14 @@ def __init__(
146146
)
147147

148148
if http_auth is not None:
149-
if isinstance(http_auth, (tuple, list)):
150-
http_auth = ":".join(http_auth)
151-
self.headers.update(urllib3.make_headers(basic_auth=http_auth))
149+
if isinstance(http_auth, Callable): # type: ignore
150+
pass
151+
elif isinstance(http_auth, (tuple, list)):
152+
self.headers.update(
153+
urllib3.make_headers(basic_auth=":".join(http_auth))
154+
)
155+
else:
156+
self.headers.update(urllib3.make_headers(basic_auth=http_auth))
152157

153158
# if providing an SSL context, raise error if any other SSL related flag is used
154159
if ssl_context and (
@@ -285,6 +290,9 @@ async def perform_request(
285290
if headers:
286291
req_headers.update(headers)
287292

293+
if isinstance(self._http_auth, Callable): # type: ignore
294+
req_headers.update(self._http_auth(method, str(url), body))
295+
288296
if self.http_compress and body:
289297
body = self._gzip_compress(body)
290298
req_headers["content-encoding"] = "gzip"

0 commit comments

Comments
 (0)