Skip to content

Pass endpoint_id and path_parts to BaseClient #69

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

Merged
merged 7 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
7 changes: 7 additions & 0 deletions docs/sphinx/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ Enrich Policies
Event Query Language (EQL)
--------------------------

.. autoclass:: EqlClient
:members:


ES|QL
-----

.. autoclass:: EqlClient
:members:

Expand Down
406 changes: 339 additions & 67 deletions elasticsearch_serverless/_async/client/__init__.py

Large diffs are not rendered by default.

12 changes: 11 additions & 1 deletion elasticsearch_serverless/_async/client/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,8 @@ async def perform_request(
params: Optional[Mapping[str, Any]] = None,
headers: Optional[Mapping[str, str]] = None,
body: Optional[Any] = None,
endpoint_id: Optional[str] = None,
path_parts: Optional[Mapping[str, Any]] = None,
) -> ApiResponse[Any]:
if headers:
request_headers = self._headers.copy()
Expand Down Expand Up @@ -251,9 +253,17 @@ async def perform_request(
params: Optional[Mapping[str, Any]] = None,
headers: Optional[Mapping[str, str]] = None,
body: Optional[Any] = None,
endpoint_id: Optional[str] = None,
path_parts: Optional[Mapping[str, Any]] = None,
) -> ApiResponse[Any]:
# Use the internal clients .perform_request() implementation
# so we take advantage of their transport options.
return await self._client.perform_request(
method, path, params=params, headers=headers, body=body
method,
path,
params=params,
headers=headers,
body=body,
endpoint_id=endpoint_id,
path_parts=path_parts,
)
43 changes: 35 additions & 8 deletions elasticsearch_serverless/_async/client/async_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ async def delete(
"""
if id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'id'")
__path = f"/_async_search/{_quote(id)}"
__path_parts: t.Dict[str, str] = {"id": _quote(id)}
__path = f'/_async_search/{__path_parts["id"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
Expand All @@ -60,7 +61,12 @@ async def delete(
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"DELETE", __path, params=__query, headers=__headers
"DELETE",
__path,
params=__query,
headers=__headers,
endpoint_id="async_search.delete",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand Down Expand Up @@ -104,7 +110,8 @@ async def get(
"""
if id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'id'")
__path = f"/_async_search/{_quote(id)}"
__path_parts: t.Dict[str, str] = {"id": _quote(id)}
__path = f'/_async_search/{__path_parts["id"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
Expand All @@ -122,7 +129,12 @@ async def get(
__query["wait_for_completion_timeout"] = wait_for_completion_timeout
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"GET", __path, params=__query, headers=__headers
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="async_search.get",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand All @@ -147,7 +159,8 @@ async def status(
"""
if id in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'id'")
__path = f"/_async_search/status/{_quote(id)}"
__path_parts: t.Dict[str, str] = {"id": _quote(id)}
__path = f'/_async_search/status/{__path_parts["id"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
Expand All @@ -159,7 +172,12 @@ async def status(
__query["pretty"] = pretty
__headers = {"accept": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"GET", __path, params=__query, headers=__headers
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="async_search.status",
path_parts=__path_parts,
)

@_rewrite_parameters(
Expand Down Expand Up @@ -443,9 +461,12 @@ async def submit(
up to a certain timeout. When the async search completes within the timeout,
the response won’t include the ID as the results are not stored in the cluster.
"""
__path_parts: t.Dict[str, str]
if index not in SKIP_IN_PATH:
__path = f"/{_quote(index)}/_async_search"
__path_parts = {"index": _quote(index)}
__path = f'/{__path_parts["index"]}/_async_search'
else:
__path_parts = {}
__path = "/_async_search"
__query: t.Dict[str, t.Any] = {}
__body: t.Dict[str, t.Any] = body if body is not None else {}
Expand Down Expand Up @@ -605,5 +626,11 @@ async def submit(
if __body is not None:
__headers["content-type"] = "application/json"
return await self.perform_request( # type: ignore[return-value]
"POST", __path, params=__query, headers=__headers, body=__body
"POST",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="async_search.submit",
path_parts=__path_parts,
)
Loading