From d4e4d6d95764f3301ac45385db62bf5e44e7a62a Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Mon, 4 Nov 2024 09:46:42 -0500 Subject: [PATCH] Updated opensearch-php to reflect the latest OpenSearch API spec (2024-11-01) (#235) Signed-off-by: GitHub Co-authored-by: dblock --- CHANGELOG.md | 1 + src/OpenSearch/Client.php | 14 ++ .../Endpoints/Wlm/CreateQueryGroup.php | 55 ++++++++ .../Endpoints/Wlm/DeleteQueryGroup.php | 62 +++++++++ .../Endpoints/Wlm/GetQueryGroup.php | 61 +++++++++ .../Endpoints/Wlm/UpdateQueryGroup.php | 72 ++++++++++ src/OpenSearch/Namespaces/WlmNamespace.php | 124 ++++++++++++++++++ 7 files changed, 389 insertions(+) create mode 100644 src/OpenSearch/Endpoints/Wlm/CreateQueryGroup.php create mode 100644 src/OpenSearch/Endpoints/Wlm/DeleteQueryGroup.php create mode 100644 src/OpenSearch/Endpoints/Wlm/GetQueryGroup.php create mode 100644 src/OpenSearch/Endpoints/Wlm/UpdateQueryGroup.php create mode 100644 src/OpenSearch/Namespaces/WlmNamespace.php diff --git a/CHANGELOG.md b/CHANGELOG.md index d09907259..f425e5106 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ### Fixed - Fixed PHP 8.4 deprecations ### Updated APIs +- Updated opensearch-php APIs to reflect [opensearch-api-specification@07e329e](https://github.com/opensearch-project/opensearch-api-specification/commit/07e329e8d01fd0576de6a0a3c35412fd5a9163db) - Updated opensearch-php APIs to reflect [opensearch-api-specification@1db1840](https://github.com/opensearch-project/opensearch-api-specification/commit/1db184063a463c5180a2cc824b1efc1aeebfd5eb) - Updated opensearch-php APIs to reflect [opensearch-api-specification@cb320b5](https://github.com/opensearch-project/opensearch-api-specification/commit/cb320b5482551c4f28afa26ff0d1653332699722) ### Security diff --git a/src/OpenSearch/Client.php b/src/OpenSearch/Client.php index 9c0746364..411ea8f5a 100644 --- a/src/OpenSearch/Client.php +++ b/src/OpenSearch/Client.php @@ -55,6 +55,7 @@ use OpenSearch\Namespaces\SslNamespace; use OpenSearch\Namespaces\TasksNamespace; use OpenSearch\Namespaces\TransformsNamespace; +use OpenSearch\Namespaces\WlmNamespace; /** * Class Client @@ -230,6 +231,11 @@ class Client */ protected $transforms; + /** + * @var WlmNamespace + */ + protected $wlm; + /** * Client constructor @@ -271,6 +277,7 @@ public function __construct(Transport $transport, callable $endpoint, array $reg $this->ssl = new SslNamespace($transport, $endpoint); $this->tasks = new TasksNamespace($transport, $endpoint); $this->transforms = new TransformsNamespace($transport, $endpoint); + $this->wlm = new WlmNamespace($transport, $endpoint); $this->registeredNamespaces = $registeredNamespaces; } @@ -1942,6 +1949,13 @@ public function transforms(): TransformsNamespace { return $this->transforms; } + /** + * Returns the wlm namespace + */ + public function wlm(): WlmNamespace + { + return $this->wlm; + } /** * Catchall for registered namespaces diff --git a/src/OpenSearch/Endpoints/Wlm/CreateQueryGroup.php b/src/OpenSearch/Endpoints/Wlm/CreateQueryGroup.php new file mode 100644 index 000000000..9dd6bcbe0 --- /dev/null +++ b/src/OpenSearch/Endpoints/Wlm/CreateQueryGroup.php @@ -0,0 +1,55 @@ +body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Wlm/DeleteQueryGroup.php b/src/OpenSearch/Endpoints/Wlm/DeleteQueryGroup.php new file mode 100644 index 000000000..a5a6bdf9c --- /dev/null +++ b/src/OpenSearch/Endpoints/Wlm/DeleteQueryGroup.php @@ -0,0 +1,62 @@ +name ?? null; + if (isset($name)) { + return "/_wlm/query_group/$name"; + } + throw new RuntimeException('Missing parameter for the endpoint wlm.delete_query_group'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'DELETE'; + } + + public function setName($name): DeleteQueryGroup + { + if (isset($name) !== true) { + return $this; + } + $this->name = $name; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Wlm/GetQueryGroup.php b/src/OpenSearch/Endpoints/Wlm/GetQueryGroup.php new file mode 100644 index 000000000..506c83c58 --- /dev/null +++ b/src/OpenSearch/Endpoints/Wlm/GetQueryGroup.php @@ -0,0 +1,61 @@ +name ?? null; + if (isset($name)) { + return "/_wlm/query_group/$name"; + } + return "/_wlm/query_group"; + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'GET'; + } + + public function setName($name): GetQueryGroup + { + if (isset($name) !== true) { + return $this; + } + $this->name = $name; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Wlm/UpdateQueryGroup.php b/src/OpenSearch/Endpoints/Wlm/UpdateQueryGroup.php new file mode 100644 index 000000000..beb335f1a --- /dev/null +++ b/src/OpenSearch/Endpoints/Wlm/UpdateQueryGroup.php @@ -0,0 +1,72 @@ +name ?? null; + if (isset($name)) { + return "/_wlm/query_group/$name"; + } + throw new RuntimeException('Missing parameter for the endpoint wlm.update_query_group'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'PUT'; + } + + public function setBody($body): UpdateQueryGroup + { + if (isset($body) !== true) { + return $this; + } + $this->body = $body; + + return $this; + } + + public function setName($name): UpdateQueryGroup + { + if (isset($name) !== true) { + return $this; + } + $this->name = $name; + + return $this; + } +} diff --git a/src/OpenSearch/Namespaces/WlmNamespace.php b/src/OpenSearch/Namespaces/WlmNamespace.php new file mode 100644 index 000000000..220fe0262 --- /dev/null +++ b/src/OpenSearch/Namespaces/WlmNamespace.php @@ -0,0 +1,124 @@ +extractArgument($params, 'body'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Wlm\CreateQueryGroup'); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + /** + * Deletes the specified QueryGroup. + * + * $params['name'] = (string) QueryGroup name. + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. + * $params['human'] = (boolean) Whether to return human readable values for statistics. + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. + * $params['source'] = (string) The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests. + * $params['filter_path'] = (any) Used to reduce the response. This parameter takes a comma-separated list of filters. It supports using wildcards to match any field or part of a field’s name. You can also exclude fields with "-". + * + * @param array $params Associative array of parameters + * @return array + */ + public function deleteQueryGroup(array $params = []) + { + $name = $this->extractArgument($params, 'name'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Wlm\DeleteQueryGroup'); + $endpoint->setParams($params); + $endpoint->setName($name); + + return $this->performRequest($endpoint); + } + /** + * Gets the specified QueryGroup or get all if no name is provided. + * + * $params['name'] = (string) QueryGroup name. + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. + * $params['human'] = (boolean) Whether to return human readable values for statistics. + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. + * $params['source'] = (string) The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests. + * $params['filter_path'] = (any) Used to reduce the response. This parameter takes a comma-separated list of filters. It supports using wildcards to match any field or part of a field’s name. You can also exclude fields with "-". + * + * @param array $params Associative array of parameters + * @return array + */ + public function getQueryGroup(array $params = []) + { + $name = $this->extractArgument($params, 'name'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Wlm\GetQueryGroup'); + $endpoint->setParams($params); + $endpoint->setName($name); + + return $this->performRequest($endpoint); + } + /** + * Updates the specified query group. + * + * $params['name'] = (string) QueryGroup name. + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. + * $params['human'] = (boolean) Whether to return human readable values for statistics. + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. + * $params['source'] = (string) The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests. + * $params['filter_path'] = (any) Used to reduce the response. This parameter takes a comma-separated list of filters. It supports using wildcards to match any field or part of a field’s name. You can also exclude fields with "-". + * + * @param array $params Associative array of parameters + * @return array + */ + public function updateQueryGroup(array $params = []) + { + $name = $this->extractArgument($params, 'name'); + $body = $this->extractArgument($params, 'body'); + + $endpointBuilder = $this->endpoints; + $endpoint = $endpointBuilder('Wlm\UpdateQueryGroup'); + $endpoint->setParams($params); + $endpoint->setName($name); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } +}