[7.x] Forward auth parameters to APIs in scan helpers

Co-authored-by: Seth Michael Larson <[email protected]>
This commit is contained in:
github-actions[bot]
2021-07-01 16:56:23 -05:00
committed by GitHub
co-authored by Seth Michael Larson
parent 0bfac34b88
commit 29f6a1ec42
4 changed files with 198 additions and 0 deletions
+15
View File
@@ -338,6 +338,20 @@ async def async_scan(
query = query.copy() if query else {}
query["sort"] = "_doc"
# Grab options that should be propagated to every
# API call within this helper instead of just 'search()'
transport_kwargs = {}
for key in ("headers", "api_key", "http_auth"):
if key in kwargs:
transport_kwargs[key] = kwargs[key]
# If the user is using 'scroll_kwargs' we want
# to propagate there too, but to not break backwards
# compatibility we'll not override anything already given.
if scroll_kwargs is not None and transport_kwargs:
for key, val in transport_kwargs.items():
scroll_kwargs.setdefault(key, val)
# initial search
resp = await client.search(
body=query, scroll=scroll, size=size, request_timeout=request_timeout, **kwargs
@@ -382,6 +396,7 @@ async def async_scan(
if scroll_id and clear_scroll:
await client.clear_scroll(
body={"scroll_id": [scroll_id]},
**transport_kwargs,
ignore=(404,),
params={"__elastic_client_meta": (("h", "s"),)},
)