Skip to content

Commit

Permalink
Pass endpoint_id and path_parts to transport (#2457)
Browse files Browse the repository at this point in the history
* Accept endpoint_id/path_parts in base clients

* Run code generation

(cherry picked from commit 45518b0)
  • Loading branch information
pquentin committed Mar 11, 2024
1 parent 985b0fe commit b3ff53d
Show file tree
Hide file tree
Showing 83 changed files with 8,101 additions and 1,623 deletions.
5 changes: 3 additions & 2 deletions dev-requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
elastic-transport>=8.0.0b1, <9
# TODO switch back to elastic-transport>=8,<9 between elastic-transport release and elasticsearch-py release
elastic-transport @ git+https://github.com/elastic/elastic-transport-python
requests>=2, <3
aiohttp
pytest
Expand Down Expand Up @@ -28,4 +29,4 @@ protobuf<4; python_version<="3.7"
# Override Read the Docs default (sphinx<2 and sphinx-rtd-theme<0.5)
sphinx>2
sphinx-rtd-theme>0.5
sphinx-autodoc-typehints
sphinx-autodoc-typehints
485 changes: 404 additions & 81 deletions elasticsearch/_async/client/__init__.py

Large diffs are not rendered by default.

14 changes: 13 additions & 1 deletion elasticsearch/_async/client/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,8 @@ async def perform_request(
params: Optional[Mapping[str, Any]] = None,
headers: Optional[Mapping[str, str]] = None,
body: Optional[Any] = None,
endpoint_id: Union[DefaultType, str] = DEFAULT,
path_parts: Union[DefaultType, Mapping[str, Any]] = DEFAULT,
) -> ApiResponse[Any]:
if headers:
request_headers = self._headers.copy()
Expand Down Expand Up @@ -292,6 +294,8 @@ def mimetype_header_to_compat(header: str) -> None:
retry_on_status=self._retry_on_status,
retry_on_timeout=self._retry_on_timeout,
client_meta=self._client_meta,
endpoint_id=endpoint_id,
path_parts=path_parts,
)

# HEAD with a 404 is returned as a normal response
Expand Down Expand Up @@ -383,9 +387,17 @@ async def perform_request(
params: Optional[Mapping[str, Any]] = None,
headers: Optional[Mapping[str, str]] = None,
body: Optional[Any] = None,
endpoint_id: Union[DefaultType, str] = DEFAULT,
path_parts: Union[DefaultType, Mapping[str, Any]] = DEFAULT,
) -> 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,
)
44 changes: 36 additions & 8 deletions elasticsearch/_async/client/async_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@


class AsyncSearchClient(NamespacedClient):

@_rewrite_parameters()
async def delete(
self,
Expand All @@ -44,7 +45,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 @@ -56,7 +58,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 @@ -98,7 +105,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 @@ -116,7 +124,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 @@ -139,7 +152,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 @@ -151,7 +165,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 @@ -427,9 +446,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 @@ -589,5 +611,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,
)
40 changes: 33 additions & 7 deletions elasticsearch/_async/client/autoscaling.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@


class AutoscalingClient(NamespacedClient):

@_rewrite_parameters()
async def delete_autoscaling_policy(
self,
Expand All @@ -44,7 +45,8 @@ async def delete_autoscaling_policy(
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path = f"/_autoscaling/policy/{_quote(name)}"
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
__path = f'/_autoscaling/policy/{__path_parts["name"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
Expand All @@ -56,7 +58,12 @@ async def delete_autoscaling_policy(
__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="autoscaling.delete_autoscaling_policy",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand All @@ -74,6 +81,7 @@ async def get_autoscaling_capacity(
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.12/autoscaling-get-autoscaling-capacity.html>`_
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_autoscaling/capacity"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
Expand All @@ -86,7 +94,12 @@ async def get_autoscaling_capacity(
__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="autoscaling.get_autoscaling_capacity",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand All @@ -109,7 +122,8 @@ async def get_autoscaling_policy(
"""
if name in SKIP_IN_PATH:
raise ValueError("Empty value passed for parameter 'name'")
__path = f"/_autoscaling/policy/{_quote(name)}"
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
__path = f'/_autoscaling/policy/{__path_parts["name"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
Expand All @@ -121,7 +135,12 @@ async def get_autoscaling_policy(
__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="autoscaling.get_autoscaling_policy",
path_parts=__path_parts,
)

@_rewrite_parameters(
Expand Down Expand Up @@ -155,7 +174,8 @@ async def put_autoscaling_policy(
)
elif policy is not None and body is not None:
raise ValueError("Cannot set both 'policy' and 'body'")
__path = f"/_autoscaling/policy/{_quote(name)}"
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
__path = f'/_autoscaling/policy/{__path_parts["name"]}'
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
__query["error_trace"] = error_trace
Expand All @@ -168,5 +188,11 @@ async def put_autoscaling_policy(
__body = policy if policy is not None else body
__headers = {"accept": "application/json", "content-type": "application/json"}
return await self.perform_request( # type: ignore[return-value]
"PUT", __path, params=__query, headers=__headers, body=__body
"PUT",
__path,
params=__query,
headers=__headers,
body=__body,
endpoint_id="autoscaling.put_autoscaling_policy",
path_parts=__path_parts,
)
Loading

0 comments on commit b3ff53d

Please sign in to comment.