Skip to content

Commit b3ff53d

Browse files
committed
Pass endpoint_id and path_parts to transport (#2457)
* Accept endpoint_id/path_parts in base clients * Run code generation (cherry picked from commit 45518b0)
1 parent 985b0fe commit b3ff53d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+8101
-1623
lines changed

dev-requirements.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
elastic-transport>=8.0.0b1, <9
1+
# TODO switch back to elastic-transport>=8,<9 between elastic-transport release and elasticsearch-py release
2+
elastic-transport @ git+https://github.com/elastic/elastic-transport-python
23
requests>=2, <3
34
aiohttp
45
pytest
@@ -28,4 +29,4 @@ protobuf<4; python_version<="3.7"
2829
# Override Read the Docs default (sphinx<2 and sphinx-rtd-theme<0.5)
2930
sphinx>2
3031
sphinx-rtd-theme>0.5
31-
sphinx-autodoc-typehints
32+
sphinx-autodoc-typehints

elasticsearch/_async/client/__init__.py

Lines changed: 404 additions & 81 deletions
Large diffs are not rendered by default.

elasticsearch/_async/client/_base.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,8 @@ async def perform_request(
257257
params: Optional[Mapping[str, Any]] = None,
258258
headers: Optional[Mapping[str, str]] = None,
259259
body: Optional[Any] = None,
260+
endpoint_id: Union[DefaultType, str] = DEFAULT,
261+
path_parts: Union[DefaultType, Mapping[str, Any]] = DEFAULT,
260262
) -> ApiResponse[Any]:
261263
if headers:
262264
request_headers = self._headers.copy()
@@ -292,6 +294,8 @@ def mimetype_header_to_compat(header: str) -> None:
292294
retry_on_status=self._retry_on_status,
293295
retry_on_timeout=self._retry_on_timeout,
294296
client_meta=self._client_meta,
297+
endpoint_id=endpoint_id,
298+
path_parts=path_parts,
295299
)
296300

297301
# HEAD with a 404 is returned as a normal response
@@ -383,9 +387,17 @@ async def perform_request(
383387
params: Optional[Mapping[str, Any]] = None,
384388
headers: Optional[Mapping[str, str]] = None,
385389
body: Optional[Any] = None,
390+
endpoint_id: Union[DefaultType, str] = DEFAULT,
391+
path_parts: Union[DefaultType, Mapping[str, Any]] = DEFAULT,
386392
) -> ApiResponse[Any]:
387393
# Use the internal clients .perform_request() implementation
388394
# so we take advantage of their transport options.
389395
return await self._client.perform_request(
390-
method, path, params=params, headers=headers, body=body
396+
method,
397+
path,
398+
params=params,
399+
headers=headers,
400+
body=body,
401+
endpoint_id=endpoint_id,
402+
path_parts=path_parts,
391403
)

elasticsearch/_async/client/async_search.py

Lines changed: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525

2626
class AsyncSearchClient(NamespacedClient):
27+
2728
@_rewrite_parameters()
2829
async def delete(
2930
self,
@@ -44,7 +45,8 @@ async def delete(
4445
"""
4546
if id in SKIP_IN_PATH:
4647
raise ValueError("Empty value passed for parameter 'id'")
47-
__path = f"/_async_search/{_quote(id)}"
48+
__path_parts: t.Dict[str, str] = {"id": _quote(id)}
49+
__path = f'/_async_search/{__path_parts["id"]}'
4850
__query: t.Dict[str, t.Any] = {}
4951
if error_trace is not None:
5052
__query["error_trace"] = error_trace
@@ -56,7 +58,12 @@ async def delete(
5658
__query["pretty"] = pretty
5759
__headers = {"accept": "application/json"}
5860
return await self.perform_request( # type: ignore[return-value]
59-
"DELETE", __path, params=__query, headers=__headers
61+
"DELETE",
62+
__path,
63+
params=__query,
64+
headers=__headers,
65+
endpoint_id="async_search.delete",
66+
path_parts=__path_parts,
6067
)
6168

6269
@_rewrite_parameters()
@@ -98,7 +105,8 @@ async def get(
98105
"""
99106
if id in SKIP_IN_PATH:
100107
raise ValueError("Empty value passed for parameter 'id'")
101-
__path = f"/_async_search/{_quote(id)}"
108+
__path_parts: t.Dict[str, str] = {"id": _quote(id)}
109+
__path = f'/_async_search/{__path_parts["id"]}'
102110
__query: t.Dict[str, t.Any] = {}
103111
if error_trace is not None:
104112
__query["error_trace"] = error_trace
@@ -116,7 +124,12 @@ async def get(
116124
__query["wait_for_completion_timeout"] = wait_for_completion_timeout
117125
__headers = {"accept": "application/json"}
118126
return await self.perform_request( # type: ignore[return-value]
119-
"GET", __path, params=__query, headers=__headers
127+
"GET",
128+
__path,
129+
params=__query,
130+
headers=__headers,
131+
endpoint_id="async_search.get",
132+
path_parts=__path_parts,
120133
)
121134

122135
@_rewrite_parameters()
@@ -139,7 +152,8 @@ async def status(
139152
"""
140153
if id in SKIP_IN_PATH:
141154
raise ValueError("Empty value passed for parameter 'id'")
142-
__path = f"/_async_search/status/{_quote(id)}"
155+
__path_parts: t.Dict[str, str] = {"id": _quote(id)}
156+
__path = f'/_async_search/status/{__path_parts["id"]}'
143157
__query: t.Dict[str, t.Any] = {}
144158
if error_trace is not None:
145159
__query["error_trace"] = error_trace
@@ -151,7 +165,12 @@ async def status(
151165
__query["pretty"] = pretty
152166
__headers = {"accept": "application/json"}
153167
return await self.perform_request( # type: ignore[return-value]
154-
"GET", __path, params=__query, headers=__headers
168+
"GET",
169+
__path,
170+
params=__query,
171+
headers=__headers,
172+
endpoint_id="async_search.status",
173+
path_parts=__path_parts,
155174
)
156175

157176
@_rewrite_parameters(
@@ -427,9 +446,12 @@ async def submit(
427446
up to a certain timeout. When the async search completes within the timeout,
428447
the response won’t include the ID as the results are not stored in the cluster.
429448
"""
449+
__path_parts: t.Dict[str, str]
430450
if index not in SKIP_IN_PATH:
431-
__path = f"/{_quote(index)}/_async_search"
451+
__path_parts = {"index": _quote(index)}
452+
__path = f'/{__path_parts["index"]}/_async_search'
432453
else:
454+
__path_parts = {}
433455
__path = "/_async_search"
434456
__query: t.Dict[str, t.Any] = {}
435457
__body: t.Dict[str, t.Any] = body if body is not None else {}
@@ -589,5 +611,11 @@ async def submit(
589611
if __body is not None:
590612
__headers["content-type"] = "application/json"
591613
return await self.perform_request( # type: ignore[return-value]
592-
"POST", __path, params=__query, headers=__headers, body=__body
614+
"POST",
615+
__path,
616+
params=__query,
617+
headers=__headers,
618+
body=__body,
619+
endpoint_id="async_search.submit",
620+
path_parts=__path_parts,
593621
)

elasticsearch/_async/client/autoscaling.py

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525

2626
class AutoscalingClient(NamespacedClient):
27+
2728
@_rewrite_parameters()
2829
async def delete_autoscaling_policy(
2930
self,
@@ -44,7 +45,8 @@ async def delete_autoscaling_policy(
4445
"""
4546
if name in SKIP_IN_PATH:
4647
raise ValueError("Empty value passed for parameter 'name'")
47-
__path = f"/_autoscaling/policy/{_quote(name)}"
48+
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
49+
__path = f'/_autoscaling/policy/{__path_parts["name"]}'
4850
__query: t.Dict[str, t.Any] = {}
4951
if error_trace is not None:
5052
__query["error_trace"] = error_trace
@@ -56,7 +58,12 @@ async def delete_autoscaling_policy(
5658
__query["pretty"] = pretty
5759
__headers = {"accept": "application/json"}
5860
return await self.perform_request( # type: ignore[return-value]
59-
"DELETE", __path, params=__query, headers=__headers
61+
"DELETE",
62+
__path,
63+
params=__query,
64+
headers=__headers,
65+
endpoint_id="autoscaling.delete_autoscaling_policy",
66+
path_parts=__path_parts,
6067
)
6168

6269
@_rewrite_parameters()
@@ -74,6 +81,7 @@ async def get_autoscaling_capacity(
7481
7582
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.12/autoscaling-get-autoscaling-capacity.html>`_
7683
"""
84+
__path_parts: t.Dict[str, str] = {}
7785
__path = "/_autoscaling/capacity"
7886
__query: t.Dict[str, t.Any] = {}
7987
if error_trace is not None:
@@ -86,7 +94,12 @@ async def get_autoscaling_capacity(
8694
__query["pretty"] = pretty
8795
__headers = {"accept": "application/json"}
8896
return await self.perform_request( # type: ignore[return-value]
89-
"GET", __path, params=__query, headers=__headers
97+
"GET",
98+
__path,
99+
params=__query,
100+
headers=__headers,
101+
endpoint_id="autoscaling.get_autoscaling_capacity",
102+
path_parts=__path_parts,
90103
)
91104

92105
@_rewrite_parameters()
@@ -109,7 +122,8 @@ async def get_autoscaling_policy(
109122
"""
110123
if name in SKIP_IN_PATH:
111124
raise ValueError("Empty value passed for parameter 'name'")
112-
__path = f"/_autoscaling/policy/{_quote(name)}"
125+
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
126+
__path = f'/_autoscaling/policy/{__path_parts["name"]}'
113127
__query: t.Dict[str, t.Any] = {}
114128
if error_trace is not None:
115129
__query["error_trace"] = error_trace
@@ -121,7 +135,12 @@ async def get_autoscaling_policy(
121135
__query["pretty"] = pretty
122136
__headers = {"accept": "application/json"}
123137
return await self.perform_request( # type: ignore[return-value]
124-
"GET", __path, params=__query, headers=__headers
138+
"GET",
139+
__path,
140+
params=__query,
141+
headers=__headers,
142+
endpoint_id="autoscaling.get_autoscaling_policy",
143+
path_parts=__path_parts,
125144
)
126145

127146
@_rewrite_parameters(
@@ -155,7 +174,8 @@ async def put_autoscaling_policy(
155174
)
156175
elif policy is not None and body is not None:
157176
raise ValueError("Cannot set both 'policy' and 'body'")
158-
__path = f"/_autoscaling/policy/{_quote(name)}"
177+
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
178+
__path = f'/_autoscaling/policy/{__path_parts["name"]}'
159179
__query: t.Dict[str, t.Any] = {}
160180
if error_trace is not None:
161181
__query["error_trace"] = error_trace
@@ -168,5 +188,11 @@ async def put_autoscaling_policy(
168188
__body = policy if policy is not None else body
169189
__headers = {"accept": "application/json", "content-type": "application/json"}
170190
return await self.perform_request( # type: ignore[return-value]
171-
"PUT", __path, params=__query, headers=__headers, body=__body
191+
"PUT",
192+
__path,
193+
params=__query,
194+
headers=__headers,
195+
body=__body,
196+
endpoint_id="autoscaling.put_autoscaling_policy",
197+
path_parts=__path_parts,
172198
)

0 commit comments

Comments
 (0)