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 all 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
404 changes: 337 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,
)
116 changes: 97 additions & 19 deletions elasticsearch_serverless/_async/client/cat.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,12 @@ async def aliases(
a suffix to the column name.
:param v: When set to `true` will enable verbose output.
"""
__path_parts: t.Dict[str, str]
if name not in SKIP_IN_PATH:
__path = f"/_cat/aliases/{_quote(name)}"
__path_parts = {"name": _quote(name)}
__path = f'/_cat/aliases/{__path_parts["name"]}'
else:
__path_parts = {}
__path = "/_cat/aliases"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
Expand Down Expand Up @@ -111,7 +114,12 @@ async def aliases(
__query["v"] = v
__headers = {"accept": "text/plain,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="cat.aliases",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand Down Expand Up @@ -159,9 +167,12 @@ async def component_templates(
a suffix to the column name.
:param v: When set to `true` will enable verbose output.
"""
__path_parts: t.Dict[str, str]
if name not in SKIP_IN_PATH:
__path = f"/_cat/component_templates/{_quote(name)}"
__path_parts = {"name": _quote(name)}
__path = f'/_cat/component_templates/{__path_parts["name"]}'
else:
__path_parts = {}
__path = "/_cat/component_templates"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
Expand All @@ -188,7 +199,12 @@ async def component_templates(
__query["v"] = v
__headers = {"accept": "text/plain,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="cat.component_templates",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand Down Expand Up @@ -238,9 +254,12 @@ async def count(
a suffix to the column name.
:param v: When set to `true` will enable verbose output.
"""
__path_parts: t.Dict[str, str]
if index not in SKIP_IN_PATH:
__path = f"/_cat/count/{_quote(index)}"
__path_parts = {"index": _quote(index)}
__path = f'/_cat/count/{__path_parts["index"]}'
else:
__path_parts = {}
__path = "/_cat/count"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
Expand All @@ -267,7 +286,12 @@ async def count(
__query["v"] = v
__headers = {"accept": "text/plain,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="cat.count",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand Down Expand Up @@ -308,6 +332,7 @@ async def help(
a suffix to the column name.
:param v: When set to `true` will enable verbose output.
"""
__path_parts: t.Dict[str, str] = {}
__path = "/_cat"
__query: t.Dict[str, t.Any] = {}
if error_trace is not None:
Expand All @@ -334,7 +359,12 @@ async def help(
__query["v"] = v
__headers = {"accept": "text/plain"}
return await self.perform_request( # type: ignore[return-value]
"GET", __path, params=__query, headers=__headers
"GET",
__path,
params=__query,
headers=__headers,
endpoint_id="cat.help",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand Down Expand Up @@ -413,9 +443,12 @@ async def indices(
:param time: The unit used to display time values.
:param v: When set to `true` will enable verbose output.
"""
__path_parts: t.Dict[str, str]
if index not in SKIP_IN_PATH:
__path = f"/_cat/indices/{_quote(index)}"
__path_parts = {"index": _quote(index)}
__path = f'/_cat/indices/{__path_parts["index"]}'
else:
__path_parts = {}
__path = "/_cat/indices"
__query: t.Dict[str, t.Any] = {}
if bytes is not None:
Expand Down Expand Up @@ -454,7 +487,12 @@ async def indices(
__query["v"] = v
__headers = {"accept": "text/plain,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="cat.indices",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand Down Expand Up @@ -534,9 +572,12 @@ async def ml_data_frame_analytics(
:param time: Unit used to display time values.
:param v: When set to `true` will enable verbose output.
"""
__path_parts: t.Dict[str, str]
if id not in SKIP_IN_PATH:
__path = f"/_cat/ml/data_frame/analytics/{_quote(id)}"
__path_parts = {"id": _quote(id)}
__path = f'/_cat/ml/data_frame/analytics/{__path_parts["id"]}'
else:
__path_parts = {}
__path = "/_cat/ml/data_frame/analytics"
__query: t.Dict[str, t.Any] = {}
if allow_no_match is not None:
Expand Down Expand Up @@ -569,7 +610,12 @@ async def ml_data_frame_analytics(
__query["v"] = v
__headers = {"accept": "text/plain,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="cat.ml_data_frame_analytics",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand Down Expand Up @@ -655,9 +701,12 @@ async def ml_datafeeds(
:param time: The unit used to display time values.
:param v: When set to `true` will enable verbose output.
"""
__path_parts: t.Dict[str, str]
if datafeed_id not in SKIP_IN_PATH:
__path = f"/_cat/ml/datafeeds/{_quote(datafeed_id)}"
__path_parts = {"datafeed_id": _quote(datafeed_id)}
__path = f'/_cat/ml/datafeeds/{__path_parts["datafeed_id"]}'
else:
__path_parts = {}
__path = "/_cat/ml/datafeeds"
__query: t.Dict[str, t.Any] = {}
if allow_no_match is not None:
Expand Down Expand Up @@ -688,7 +737,12 @@ async def ml_datafeeds(
__query["v"] = v
__headers = {"accept": "text/plain,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="cat.ml_datafeeds",
path_parts=__path_parts,
)

@_rewrite_parameters()
Expand Down Expand Up @@ -778,9 +832,12 @@ async def ml_jobs(
:param time: The unit used to display time values.
:param v: When set to `true` will enable verbose output.
"""
__path_parts: t.Dict[str, str]
if job_id not in SKIP_IN_PATH:
__path = f"/_cat/ml/anomaly_detectors/{_quote(job_id)}"
__path_parts = {"job_id": _quote(job_id)}
__path = f'/_cat/ml/anomaly_detectors/{__path_parts["job_id"]}'
else:
__path_parts = {}
__path = "/_cat/ml/anomaly_detectors"
__query: t.Dict[str, t.Any] = {}
if allow_no_match is not None:
Expand Down Expand Up @@ -813,7 +870,12 @@ async def ml_jobs(
__query["v"] = v
__headers = {"accept": "text/plain,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="cat.ml_jobs",
path_parts=__path_parts,
)

@_rewrite_parameters(
Expand Down Expand Up @@ -902,9 +964,12 @@ async def ml_trained_models(
:param size: The maximum number of transforms to display.
:param v: When set to `true` will enable verbose output.
"""
__path_parts: t.Dict[str, str]
if model_id not in SKIP_IN_PATH:
__path = f"/_cat/ml/trained_models/{_quote(model_id)}"
__path_parts = {"model_id": _quote(model_id)}
__path = f'/_cat/ml/trained_models/{__path_parts["model_id"]}'
else:
__path_parts = {}
__path = "/_cat/ml/trained_models"
__query: t.Dict[str, t.Any] = {}
if allow_no_match is not None:
Expand Down Expand Up @@ -939,7 +1004,12 @@ async def ml_trained_models(
__query["v"] = v
__headers = {"accept": "text/plain,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="cat.ml_trained_models",
path_parts=__path_parts,
)

@_rewrite_parameters(
Expand Down Expand Up @@ -1030,9 +1100,12 @@ async def transforms(
:param time: The unit used to display time values.
:param v: When set to `true` will enable verbose output.
"""
__path_parts: t.Dict[str, str]
if transform_id not in SKIP_IN_PATH:
__path = f"/_cat/transforms/{_quote(transform_id)}"
__path_parts = {"transform_id": _quote(transform_id)}
__path = f'/_cat/transforms/{__path_parts["transform_id"]}'
else:
__path_parts = {}
__path = "/_cat/transforms"
__query: t.Dict[str, t.Any] = {}
if allow_no_match is not None:
Expand Down Expand Up @@ -1067,5 +1140,10 @@ async def transforms(
__query["v"] = v
__headers = {"accept": "text/plain,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="cat.transforms",
path_parts=__path_parts,
)
Loading
Loading