Skip to content

Commit

Permalink
Updated APIs to match other clients and opensearch openapi spec (#502)
Browse files Browse the repository at this point in the history
Signed-off-by: saimedhi <saimedhi@amazon.com>
  • Loading branch information
saimedhi authored Sep 26, 2023
1 parent 69750e8 commit c6c7df5
Show file tree
Hide file tree
Showing 17 changed files with 786 additions and 127 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
## [Unreleased]
### Added
- Added generating imports and headers to API generator ([#467](https://github.com/opensearch-project/opensearch-py/pull/467))
- Added point-in-time APIs (create_pit, delete_pit, delete_all_pits, get_all_pits) and Security Client APIs (health and update_audit_configuration) ([#502](https://github.com/opensearch-project/opensearch-py/pull/502))
### Changed
### Deprecated
- Deprecated point-in-time APIs (list_all_point_in_time, create_point_in_time, delete_point_in_time) and Security Client APIs (health_check and update_audit_config) ([#502](https://github.com/opensearch-project/opensearch-py/pull/502))
### Removed
### Fixed
### Security
Expand Down
89 changes: 52 additions & 37 deletions opensearchpy/_async/client/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,12 @@ def default(self, obj):
"""

from ._patch import (
create_point_in_time,
delete_point_in_time,
list_all_point_in_time,
)

def __init__(self, hosts=None, transport_class=AsyncTransport, **kwargs):
"""
:arg hosts: list of nodes, or a single node, we should connect to.
Expand Down Expand Up @@ -1955,64 +1961,73 @@ async def get_script_languages(self, params=None, headers=None):
"GET", "/_script_language", params=params, headers=headers
)

@query_params()
async def list_all_point_in_time(self, params=None, headers=None):
@query_params(
"allow_partial_pit_creation",
"expand_wildcards",
"keep_alive",
"preference",
"routing",
)
async def create_pit(self, index, params=None, headers=None):
"""
Returns the list of point in times which are alive
Creates point in time context.
:arg index: Comma-separated list of indices; use `_all` or empty
string to perform the operation on all indices.
:arg allow_partial_pit_creation: Allow if point in time can be
created with partial failures.
:arg expand_wildcards: Whether to expand wildcard expression to
concrete indices that are open, closed or both. Valid choices: all,
open, closed, hidden, none
:arg keep_alive: Specify the keep alive for point in time.
:arg preference: Specify the node or shard the operation should
be performed on.
:arg routing: Comma-separated list of specific routing values.
"""
if index in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'index'.")

return await self.transport.perform_request(
"GET",
_make_path("_search", "point_in_time", "_all"),
"POST",
_make_path(index, "_search", "point_in_time"),
params=params,
headers=headers,
)

@query_params()
async def delete_point_in_time(
self, body=None, all=False, params=None, headers=None
):
async def delete_all_pits(self, params=None, headers=None):
"""
Delete a point in time
Deletes all active point in time searches.
:arg body: a point-in-time id to delete
:arg all: set it to `True` to delete all alive point in time.
"""
path = (
_make_path("_search", "point_in_time", "_all")
if all
else _make_path("_search", "point_in_time")
)
return await self.transport.perform_request(
"DELETE", path, params=params, headers=headers, body=body
"DELETE", "/_search/point_in_time/_all", params=params, headers=headers
)

@query_params(
"expand_wildcards", "ignore_unavailable", "keep_alive", "preference", "routing"
)
async def create_point_in_time(self, index=None, params=None, headers=None):
@query_params()
async def delete_pit(self, body=None, params=None, headers=None):
"""
Create a point in time that can be used in subsequent searches
Deletes one or more point in time searches based on the IDs passed.
:arg index: A comma-separated list of index names to create point
in time; use `_all` or empty string to perform the operation on all
indices
:arg expand_wildcards: Whether to expand wildcard expression to
concrete indices that are open, closed or both. Valid choices: open,
closed, hidden, none, all Default: open
:arg ignore_unavailable: Whether specified concrete indices
should be ignored when unavailable (missing or closed)
:arg keep_alive: Specific the time to live for the point in time
:arg preference: Specify the node or shard the operation should
be performed on (default: random)
:arg routing: Specific routing value
:arg body: a point-in-time id to delete
"""
return await self.transport.perform_request(
"POST",
_make_path(index, "_search", "point_in_time"),
"DELETE",
"/_search/point_in_time",
params=params,
headers=headers,
body=body,
)

@query_params()
async def get_all_pits(self, params=None, headers=None):
"""
Lists all active point in time searches.
"""
return await self.transport.perform_request(
"GET", "/_search/point_in_time/_all", params=params, headers=headers
)

@query_params()
Expand Down
35 changes: 25 additions & 10 deletions opensearchpy/_async/client/__init__.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,29 @@ class AsyncOpenSearch(object):
params: Optional[MutableMapping[str, Any]] = ...,
headers: Optional[MutableMapping[str, str]] = ...,
) -> Any: ...
async def list_all_point_in_time(
async def create_pit(
self,
index: Any,
*,
allow_partial_pit_creation: Optional[Any] = ...,
expand_wildcards: Optional[Any] = ...,
keep_alive: Optional[Any] = ...,
preference: Optional[Any] = ...,
routing: Optional[Any] = ...,
pretty: Optional[bool] = ...,
human: Optional[bool] = ...,
error_trace: Optional[bool] = ...,
format: Optional[str] = ...,
filter_path: Optional[Union[str, Collection[str]]] = ...,
request_timeout: Optional[Union[int, float]] = ...,
ignore: Optional[Union[int, Collection[int]]] = ...,
opaque_id: Optional[str] = ...,
http_auth: Optional[Union[str, Tuple[str, str]]] = ...,
api_key: Optional[Union[str, Tuple[str, str]]] = ...,
params: Optional[MutableMapping[str, Any]] = ...,
headers: Optional[MutableMapping[str, str]] = ...,
) -> Any: ...
async def delete_all_pits(
self,
*,
pretty: Optional[bool] = ...,
Expand All @@ -1073,11 +1095,10 @@ class AsyncOpenSearch(object):
params: Optional[MutableMapping[str, Any]] = ...,
headers: Optional[MutableMapping[str, str]] = ...,
) -> Any: ...
async def delete_point_in_time(
async def delete_pit(
self,
*,
body: Optional[Any] = ...,
all: Optional[bool] = ...,
pretty: Optional[bool] = ...,
human: Optional[bool] = ...,
error_trace: Optional[bool] = ...,
Expand All @@ -1091,15 +1112,9 @@ class AsyncOpenSearch(object):
params: Optional[MutableMapping[str, Any]] = ...,
headers: Optional[MutableMapping[str, str]] = ...,
) -> Any: ...
async def create_point_in_time(
async def get_all_pits(
self,
*,
index: Optional[Any] = ...,
expand_wildcards: Optional[Any] = ...,
ignore_unavailable: Optional[Any] = ...,
keep_alive: Optional[Any] = ...,
preference: Optional[Any] = ...,
routing: Optional[Any] = ...,
pretty: Optional[bool] = ...,
human: Optional[bool] = ...,
error_trace: Optional[bool] = ...,
Expand Down
135 changes: 135 additions & 0 deletions opensearchpy/_async/client/_patch.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
# SPDX-License-Identifier: Apache-2.0
#
# The OpenSearch Contributors require contributions made to
# this file be licensed under the Apache-2.0 license or a
# compatible open source license.
#
# Modifications Copyright OpenSearch Contributors. See
# GitHub history for details.

import warnings

from .utils import SKIP_IN_PATH, query_params


@query_params()
async def list_all_point_in_time(self, params=None, headers=None):
"""
Returns the list of active point in times searches
.. warning::
This API will be removed in a future version
Use 'get_all_pits' API instead.
"""
warnings.warn(
"The 'list_all_point_in_time' API is deprecated and will be removed in a future version. Use 'get_all_pits' API instead.",
DeprecationWarning,
)

return await self.get_all_pits(params=params, headers=headers)


@query_params(
"expand_wildcards", "ignore_unavailable", "keep_alive", "preference", "routing"
)
async def create_point_in_time(self, index, params=None, headers=None):
"""
Create a point in time that can be used in subsequent searches
:arg index: A comma-separated list of index names to open point
in time; use `_all` or empty string to perform the operation on all
indices
:arg expand_wildcards: Whether to expand wildcard expression to
concrete indices that are open, closed or both. Valid choices: open,
closed, hidden, none, all Default: open
:arg ignore_unavailable: Whether specified concrete indices
should be ignored when unavailable (missing or closed)
:arg keep_alive: Specific the time to live for the point in time
:arg preference: Specify the node or shard the operation should
be performed on (default: random)
:arg routing: Specific routing value
.. warning::
This API will be removed in a future version
Use 'create_pit' API instead.
"""
warnings.warn(
"The 'create_point_in_time' API is deprecated and will be removed in a future version. Use 'create_pit' API instead.",
DeprecationWarning,
)

return await self.create_pit(index=index, params=params, headers=headers)


@query_params()
async def delete_point_in_time(self, body=None, all=False, params=None, headers=None):
"""
Delete a point in time
:arg body: a point-in-time id to delete
:arg all: set it to `True` to delete all alive point in time.
.. warning::
This API will be removed in a future version
Use 'delete_all_pits' or 'delete_pit' API instead.
"""
warnings.warn(
"The 'delete_point_in_time' API is deprecated and will be removed in a future version. Use 'delete_all_pits' or 'delete_pit' API instead.",
DeprecationWarning,
)

if all:
return await self.delete_all_pits(params=params, headers=headers)
else:
return await self.delete_pit(body=body, params=params, headers=headers)


@query_params()
async def health_check(self, params=None, headers=None):
"""
Checks to see if the Security plugin is up and running.
.. warning::
This API will be removed in a future version
Use 'health' API instead.
"""
warnings.warn(
"The 'health_check' API in security client is deprecated and will be removed in a future version. Use 'health' API instead.",
DeprecationWarning,
)

return await self.health(params=params, headers=headers)


@query_params()
async def update_audit_config(self, body, params=None, headers=None):
"""
A PUT call updates the audit configuration.
.. warning::
This API will be removed in a future version
Use 'update_audit_configuration' API instead.
"""
warnings.warn(
"The 'update_audit_config' API in security client is deprecated and will be removed in a future version. Use 'update_audit_configuration' API instead.",
DeprecationWarning,
)

if body in SKIP_IN_PATH:
raise ValueError("Empty value passed for a required argument 'body'.")

return await self.update_audit_configuration(
params=params, headers=headers, body=body
)
Loading

0 comments on commit c6c7df5

Please sign in to comment.