Skip to content

Commit 592ad69

Browse files
authored
[Backport 8.13] Pass endpoint_id and path_parts to transport (#2457) (#2468)
* 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) * Run code generation
1 parent 58b1a1c commit 592ad69

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

+8081
-1635
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: 35 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ async def delete(
4545
"""
4646
if id in SKIP_IN_PATH:
4747
raise ValueError("Empty value passed for parameter 'id'")
48-
__path = f"/_async_search/{_quote(id)}"
48+
__path_parts: t.Dict[str, str] = {"id": _quote(id)}
49+
__path = f'/_async_search/{__path_parts["id"]}'
4950
__query: t.Dict[str, t.Any] = {}
5051
if error_trace is not None:
5152
__query["error_trace"] = error_trace
@@ -57,7 +58,12 @@ async def delete(
5758
__query["pretty"] = pretty
5859
__headers = {"accept": "application/json"}
5960
return await self.perform_request( # type: ignore[return-value]
60-
"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,
6167
)
6268

6369
@_rewrite_parameters()
@@ -99,7 +105,8 @@ async def get(
99105
"""
100106
if id in SKIP_IN_PATH:
101107
raise ValueError("Empty value passed for parameter 'id'")
102-
__path = f"/_async_search/{_quote(id)}"
108+
__path_parts: t.Dict[str, str] = {"id": _quote(id)}
109+
__path = f'/_async_search/{__path_parts["id"]}'
103110
__query: t.Dict[str, t.Any] = {}
104111
if error_trace is not None:
105112
__query["error_trace"] = error_trace
@@ -117,7 +124,12 @@ async def get(
117124
__query["wait_for_completion_timeout"] = wait_for_completion_timeout
118125
__headers = {"accept": "application/json"}
119126
return await self.perform_request( # type: ignore[return-value]
120-
"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,
121133
)
122134

123135
@_rewrite_parameters()
@@ -140,7 +152,8 @@ async def status(
140152
"""
141153
if id in SKIP_IN_PATH:
142154
raise ValueError("Empty value passed for parameter 'id'")
143-
__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"]}'
144157
__query: t.Dict[str, t.Any] = {}
145158
if error_trace is not None:
146159
__query["error_trace"] = error_trace
@@ -152,7 +165,12 @@ async def status(
152165
__query["pretty"] = pretty
153166
__headers = {"accept": "application/json"}
154167
return await self.perform_request( # type: ignore[return-value]
155-
"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,
156174
)
157175

158176
@_rewrite_parameters(
@@ -428,9 +446,12 @@ async def submit(
428446
up to a certain timeout. When the async search completes within the timeout,
429447
the response won’t include the ID as the results are not stored in the cluster.
430448
"""
449+
__path_parts: t.Dict[str, str]
431450
if index not in SKIP_IN_PATH:
432-
__path = f"/{_quote(index)}/_async_search"
451+
__path_parts = {"index": _quote(index)}
452+
__path = f'/{__path_parts["index"]}/_async_search'
433453
else:
454+
__path_parts = {}
434455
__path = "/_async_search"
435456
__query: t.Dict[str, t.Any] = {}
436457
__body: t.Dict[str, t.Any] = body if body is not None else {}
@@ -590,5 +611,11 @@ async def submit(
590611
if __body is not None:
591612
__headers["content-type"] = "application/json"
592613
return await self.perform_request( # type: ignore[return-value]
593-
"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,
594621
)

elasticsearch/_async/client/autoscaling.py

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ async def delete_autoscaling_policy(
4545
"""
4646
if name in SKIP_IN_PATH:
4747
raise ValueError("Empty value passed for parameter 'name'")
48-
__path = f"/_autoscaling/policy/{_quote(name)}"
48+
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
49+
__path = f'/_autoscaling/policy/{__path_parts["name"]}'
4950
__query: t.Dict[str, t.Any] = {}
5051
if error_trace is not None:
5152
__query["error_trace"] = error_trace
@@ -57,7 +58,12 @@ async def delete_autoscaling_policy(
5758
__query["pretty"] = pretty
5859
__headers = {"accept": "application/json"}
5960
return await self.perform_request( # type: ignore[return-value]
60-
"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,
6167
)
6268

6369
@_rewrite_parameters()
@@ -75,6 +81,7 @@ async def get_autoscaling_capacity(
7581
7682
`<https://www.elastic.co/guide/en/elasticsearch/reference/8.13/autoscaling-get-autoscaling-capacity.html>`_
7783
"""
84+
__path_parts: t.Dict[str, str] = {}
7885
__path = "/_autoscaling/capacity"
7986
__query: t.Dict[str, t.Any] = {}
8087
if error_trace is not None:
@@ -87,7 +94,12 @@ async def get_autoscaling_capacity(
8794
__query["pretty"] = pretty
8895
__headers = {"accept": "application/json"}
8996
return await self.perform_request( # type: ignore[return-value]
90-
"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,
91103
)
92104

93105
@_rewrite_parameters()
@@ -110,7 +122,8 @@ async def get_autoscaling_policy(
110122
"""
111123
if name in SKIP_IN_PATH:
112124
raise ValueError("Empty value passed for parameter 'name'")
113-
__path = f"/_autoscaling/policy/{_quote(name)}"
125+
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
126+
__path = f'/_autoscaling/policy/{__path_parts["name"]}'
114127
__query: t.Dict[str, t.Any] = {}
115128
if error_trace is not None:
116129
__query["error_trace"] = error_trace
@@ -122,7 +135,12 @@ async def get_autoscaling_policy(
122135
__query["pretty"] = pretty
123136
__headers = {"accept": "application/json"}
124137
return await self.perform_request( # type: ignore[return-value]
125-
"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,
126144
)
127145

128146
@_rewrite_parameters(
@@ -156,7 +174,8 @@ async def put_autoscaling_policy(
156174
)
157175
elif policy is not None and body is not None:
158176
raise ValueError("Cannot set both 'policy' and 'body'")
159-
__path = f"/_autoscaling/policy/{_quote(name)}"
177+
__path_parts: t.Dict[str, str] = {"name": _quote(name)}
178+
__path = f'/_autoscaling/policy/{__path_parts["name"]}'
160179
__query: t.Dict[str, t.Any] = {}
161180
if error_trace is not None:
162181
__query["error_trace"] = error_trace
@@ -169,5 +188,11 @@ async def put_autoscaling_policy(
169188
__body = policy if policy is not None else body
170189
__headers = {"accept": "application/json", "content-type": "application/json"}
171190
return await self.perform_request( # type: ignore[return-value]
172-
"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,
173198
)

0 commit comments

Comments
 (0)