From 6ed03016e13d979c80508bcc2f137f6d99d6dc5e Mon Sep 17 00:00:00 2001 From: Kim Pepper Date: Fri, 10 Jan 2025 01:19:59 +1100 Subject: [PATCH] Restore exception behavior for backwards compatibility (#245) * Fix ML tests Signed-off-by: Kim Pepper * Fix Security tests Signed-off-by: Kim Pepper * Updates SQL namespace tests Signed-off-by: Kim Pepper * Re-add support for legacy exceptions Signed-off-by: Kim Pepper * Handle exception in boolean request wrapper Signed-off-by: Kim Pepper * Avoid empty() Signed-off-by: Kim Pepper * Generate API Signed-off-by: Kim Pepper --------- Signed-off-by: Kim Pepper --- CHANGELOG.md | 6 +- docker-compose.yml | 9 + phpunit.xml.dist | 4 + src/OpenSearch/Client.php | 181 +++++-- .../Endpoints/AsynchronousSearch/Delete.php | 7 +- .../Endpoints/AsynchronousSearch/Get.php | 7 +- .../Endpoints/AsynchronousSearch/Search.php | 2 +- src/OpenSearch/Endpoints/Bulk.php | 24 +- src/OpenSearch/Endpoints/BulkStream.php | 24 +- src/OpenSearch/Endpoints/Cat/PitSegments.php | 2 +- src/OpenSearch/Endpoints/Cat/Templates.php | 2 +- src/OpenSearch/Endpoints/ClearScroll.php | 2 +- .../Endpoints/Cluster/AllocationExplain.php | 2 +- .../Cluster/DeleteComponentTemplate.php | 2 +- .../Cluster/DeleteWeightedRouting.php | 2 +- .../Cluster/ExistsComponentTemplate.php | 2 +- .../Cluster/GetComponentTemplate.php | 1 + .../Cluster/GetDecommissionAwareness.php | 2 +- .../Endpoints/Cluster/GetWeightedRouting.php | 2 +- .../Cluster/PutComponentTemplate.php | 4 +- .../Cluster/PutDecommissionAwareness.php | 4 +- .../Endpoints/Cluster/PutSettings.php | 2 +- .../Endpoints/Cluster/PutWeightedRouting.php | 4 +- src/OpenSearch/Endpoints/Cluster/Reroute.php | 2 +- src/OpenSearch/Endpoints/Count.php | 2 +- src/OpenSearch/Endpoints/Create.php | 15 +- src/OpenSearch/Endpoints/CreatePit.php | 7 +- .../DanglingIndices/DeleteDanglingIndex.php | 2 +- .../DanglingIndices/ImportDanglingIndex.php | 2 +- src/OpenSearch/Endpoints/Delete.php | 13 +- src/OpenSearch/Endpoints/DeleteByQuery.php | 9 +- .../Endpoints/DeleteByQueryRethrottle.php | 9 +- src/OpenSearch/Endpoints/DeletePit.php | 2 +- src/OpenSearch/Endpoints/DeleteScript.php | 7 +- src/OpenSearch/Endpoints/Exists.php | 13 +- src/OpenSearch/Endpoints/ExistsSource.php | 13 +- src/OpenSearch/Endpoints/Explain.php | 15 +- src/OpenSearch/Endpoints/FieldCaps.php | 2 +- .../Endpoints/FlowFramework/Create.php | 2 +- .../Endpoints/FlowFramework/Delete.php | 2 +- .../Endpoints/FlowFramework/Deprovision.php | 2 +- .../Endpoints/FlowFramework/Get.php | 2 +- .../Endpoints/FlowFramework/GetStatus.php | 2 +- .../Endpoints/FlowFramework/Provision.php | 4 +- .../Endpoints/FlowFramework/Search.php | 2 +- .../Endpoints/FlowFramework/SearchState.php | 2 +- .../Endpoints/FlowFramework/Update.php | 4 +- src/OpenSearch/Endpoints/Get.php | 13 +- src/OpenSearch/Endpoints/GetScript.php | 7 +- src/OpenSearch/Endpoints/GetSource.php | 13 +- src/OpenSearch/Endpoints/Index.php | 8 +- src/OpenSearch/Endpoints/Indices/AddBlock.php | 2 +- src/OpenSearch/Endpoints/Indices/Analyze.php | 2 +- .../Endpoints/Indices/CloneIndices.php | 4 +- src/OpenSearch/Endpoints/Indices/Create.php | 2 +- .../Endpoints/Indices/CreateDataStream.php | 4 +- .../Endpoints/Indices/DeleteAlias.php | 13 +- .../Endpoints/Indices/DeleteIndexTemplate.php | 2 +- .../Endpoints/Indices/DeleteTemplate.php | 2 +- .../Endpoints/Indices/ExistsAlias.php | 6 +- .../Endpoints/Indices/ExistsIndexTemplate.php | 2 +- .../Endpoints/Indices/GetFieldMapping.php | 6 +- src/OpenSearch/Endpoints/Indices/PutAlias.php | 4 +- .../Endpoints/Indices/PutIndexTemplate.php | 4 +- .../Endpoints/Indices/PutMapping.php | 2 +- .../Endpoints/Indices/PutSettings.php | 2 +- .../Endpoints/Indices/PutTemplate.php | 4 +- src/OpenSearch/Endpoints/Indices/Rollover.php | 12 +- src/OpenSearch/Endpoints/Indices/Shrink.php | 4 +- .../Indices/SimulateIndexTemplate.php | 4 +- .../Endpoints/Indices/SimulateTemplate.php | 4 +- src/OpenSearch/Endpoints/Indices/Split.php | 4 +- .../Endpoints/Indices/UpdateAliases.php | 2 +- src/OpenSearch/Endpoints/Indices/Upgrade.php | 10 - .../Endpoints/Indices/ValidateQuery.php | 2 +- .../Endpoints/Ingest/PutPipeline.php | 2 +- src/OpenSearch/Endpoints/Ingest/Simulate.php | 2 +- src/OpenSearch/Endpoints/Ism/AddPolicy.php | 2 +- src/OpenSearch/Endpoints/Ism/ChangePolicy.php | 2 +- src/OpenSearch/Endpoints/Ism/DeletePolicy.php | 9 +- src/OpenSearch/Endpoints/Ism/ExistsPolicy.php | 9 +- .../Endpoints/Ism/ExplainPolicy.php | 2 +- src/OpenSearch/Endpoints/Ism/GetPolicy.php | 9 +- src/OpenSearch/Endpoints/Ism/PutPolicies.php | 2 +- src/OpenSearch/Endpoints/Ism/PutPolicy.php | 11 +- .../Endpoints/Ism/RefreshSearchAnalyzers.php | 7 +- src/OpenSearch/Endpoints/Ism/RetryIndex.php | 2 +- src/OpenSearch/Endpoints/Knn/DeleteModel.php | 2 +- src/OpenSearch/Endpoints/Knn/GetModel.php | 2 +- src/OpenSearch/Endpoints/Knn/SearchModels.php | 2 +- src/OpenSearch/Endpoints/Knn/TrainModel.php | 4 +- src/OpenSearch/Endpoints/Knn/Warmup.php | 7 +- src/OpenSearch/Endpoints/MTermVectors.php | 2 +- src/OpenSearch/Endpoints/Mget.php | 2 +- .../Endpoints/Ml/CreateConnector.php | 2 +- src/OpenSearch/Endpoints/Ml/CreateMemory.php | 55 ++ src/OpenSearch/Endpoints/Ml/CreateMessage.php | 72 +++ src/OpenSearch/Endpoints/Ml/DeleteAgent.php | 2 +- .../Endpoints/Ml/DeleteConnector.php | 2 +- src/OpenSearch/Endpoints/Ml/DeleteMemory.php | 62 +++ src/OpenSearch/Endpoints/Ml/DeleteTask.php | 2 +- src/OpenSearch/Endpoints/Ml/DeployModel.php | 2 +- src/OpenSearch/Endpoints/Ml/GetConnector.php | 47 +- src/OpenSearch/Endpoints/Ml/GetMemory.php | 71 +++ src/OpenSearch/Endpoints/Ml/GetMessage.php | 77 +++ .../Endpoints/Ml/GetMessageTraces.php | 62 +++ src/OpenSearch/Endpoints/Ml/GetModelGroup.php | 2 +- src/OpenSearch/Endpoints/Ml/Predict.php | 67 ++- .../Endpoints/Ml/RegisterAgents.php | 2 +- src/OpenSearch/Endpoints/Ml/RegisterModel.php | 2 +- .../Endpoints/Ml/RegisterModelGroup.php | 2 +- .../Endpoints/Ml/SearchConnectors.php | 55 ++ src/OpenSearch/Endpoints/Ml/SearchMemory.php | 55 ++ src/OpenSearch/Endpoints/Ml/SearchMessage.php | 72 +++ .../Endpoints/Ml/SearchModelGroup.php | 55 ++ src/OpenSearch/Endpoints/Ml/SearchModels.php | 2 +- src/OpenSearch/Endpoints/Ml/Train.php | 72 +++ src/OpenSearch/Endpoints/Ml/TrainPredict.php | 72 +++ src/OpenSearch/Endpoints/Ml/UndeployModel.php | 2 +- .../Endpoints/Ml/UpdateConnector.php | 72 +++ src/OpenSearch/Endpoints/Ml/UpdateMemory.php | 72 +++ src/OpenSearch/Endpoints/Ml/UpdateMessage.php | 72 +++ .../Endpoints/Ml/UpdateModelGroup.php | 56 +- src/OpenSearch/Endpoints/Msearch.php | 24 +- src/OpenSearch/Endpoints/MsearchTemplate.php | 24 +- src/OpenSearch/Endpoints/Nodes/Info.php | 2 +- .../Endpoints/Nodes/ReloadSecureSettings.php | 2 +- .../Endpoints/Notifications/CreateConfig.php | 2 +- .../Endpoints/Notifications/DeleteConfig.php | 2 +- .../Endpoints/Notifications/GetConfig.php | 2 +- .../Endpoints/Notifications/GetConfigs.php | 2 +- .../Endpoints/Notifications/SendTest.php | 2 +- .../Endpoints/Notifications/UpdateConfig.php | 4 +- .../Endpoints/Observability/CreateObject.php | 2 +- .../Endpoints/Observability/DeleteObject.php | 2 +- .../Endpoints/Observability/GetObject.php | 2 +- .../Endpoints/Observability/UpdateObject.php | 4 +- src/OpenSearch/Endpoints/Ppl/Explain.php | 2 +- src/OpenSearch/Endpoints/Ppl/PostStats.php | 2 +- src/OpenSearch/Endpoints/Ppl/Query.php | 2 +- src/OpenSearch/Endpoints/PutScript.php | 10 +- .../Endpoints/Query/DatasourceDelete.php | 2 +- .../Endpoints/Query/DatasourceRetrieve.php | 2 +- .../Endpoints/Query/DatasourcesCreate.php | 2 +- .../Endpoints/Query/DatasourcesUpdate.php | 2 +- src/OpenSearch/Endpoints/RankEval.php | 2 +- src/OpenSearch/Endpoints/Reindex.php | 2 +- .../Endpoints/ReindexRethrottle.php | 9 +- .../Endpoints/RemoteStore/Restore.php | 2 +- .../Endpoints/RenderSearchTemplate.php | 2 +- .../Replication/CreateReplicationRule.php | 2 +- .../Replication/DeleteReplicationRule.php | 2 +- .../Endpoints/Replication/Pause.php | 2 +- .../Endpoints/Replication/Resume.php | 2 +- .../Endpoints/Replication/Start.php | 2 +- src/OpenSearch/Endpoints/Replication/Stop.php | 2 +- .../Endpoints/Replication/UpdateSettings.php | 2 +- src/OpenSearch/Endpoints/Rollups/Delete.php | 7 +- src/OpenSearch/Endpoints/Rollups/Explain.php | 7 +- src/OpenSearch/Endpoints/Rollups/Get.php | 7 +- src/OpenSearch/Endpoints/Rollups/Put.php | 9 +- src/OpenSearch/Endpoints/Rollups/Start.php | 7 +- src/OpenSearch/Endpoints/Rollups/Stop.php | 7 +- .../Endpoints/ScriptsPainlessExecute.php | 2 +- src/OpenSearch/Endpoints/Scroll.php | 4 +- src/OpenSearch/Endpoints/Search.php | 2 +- .../Endpoints/SearchPipeline/Put.php | 2 +- src/OpenSearch/Endpoints/SearchShards.php | 2 +- src/OpenSearch/Endpoints/SearchTemplate.php | 2 +- .../Endpoints/Security/ChangePassword.php | 2 +- .../Security/ConfigUpgradePerform.php | 2 +- .../Endpoints/Security/CreateActionGroup.php | 11 +- .../Endpoints/Security/CreateAllowlist.php | 2 +- .../Endpoints/Security/CreateRole.php | 11 +- .../Endpoints/Security/CreateRoleMapping.php | 11 +- .../Endpoints/Security/CreateTenant.php | 11 +- .../Security/CreateUpdateTenancyConfig.php | 2 +- .../Endpoints/Security/CreateUser.php | 11 +- .../Endpoints/Security/CreateUserLegacy.php | 11 +- .../Endpoints/Security/DeleteActionGroup.php | 9 +- .../Security/DeleteDistinguishedName.php | 9 +- .../Endpoints/Security/DeleteRole.php | 9 +- .../Endpoints/Security/DeleteRoleMapping.php | 9 +- .../Endpoints/Security/DeleteTenant.php | 9 +- .../Endpoints/Security/DeleteUser.php | 9 +- .../Endpoints/Security/DeleteUserLegacy.php | 9 +- .../Endpoints/Security/GenerateOboToken.php | 2 +- .../Endpoints/Security/GenerateUserToken.php | 9 +- .../Security/GenerateUserTokenLegacy.php | 9 +- .../Endpoints/Security/GetActionGroup.php | 9 +- .../Security/GetDistinguishedName.php | 9 +- .../Security/GetNodeCertificates.php | 2 +- src/OpenSearch/Endpoints/Security/GetRole.php | 9 +- .../Endpoints/Security/GetRoleMapping.php | 9 +- .../Endpoints/Security/GetTenant.php | 9 +- src/OpenSearch/Endpoints/Security/GetUser.php | 9 +- .../Endpoints/Security/GetUserLegacy.php | 9 +- .../Endpoints/Security/PatchActionGroup.php | 11 +- .../Endpoints/Security/PatchActionGroups.php | 2 +- .../Endpoints/Security/PatchAllowlist.php | 2 +- .../Security/PatchAuditConfiguration.php | 2 +- .../Endpoints/Security/PatchConfiguration.php | 2 +- .../Security/PatchDistinguishedName.php | 11 +- .../Security/PatchDistinguishedNames.php | 2 +- .../Endpoints/Security/PatchRole.php | 11 +- .../Endpoints/Security/PatchRoleMapping.php | 11 +- .../Endpoints/Security/PatchRoleMappings.php | 2 +- .../Endpoints/Security/PatchRoles.php | 2 +- .../Endpoints/Security/PatchTenant.php | 11 +- .../Endpoints/Security/PatchTenants.php | 2 +- .../Endpoints/Security/PatchUser.php | 11 +- .../Endpoints/Security/PatchUsers.php | 2 +- .../Security/UpdateAuditConfiguration.php | 2 +- .../Security/UpdateConfiguration.php | 2 +- .../Security/UpdateDistinguishedName.php | 11 +- src/OpenSearch/Endpoints/Sm/CreatePolicy.php | 4 +- src/OpenSearch/Endpoints/Sm/DeletePolicy.php | 2 +- src/OpenSearch/Endpoints/Sm/ExplainPolicy.php | 2 +- src/OpenSearch/Endpoints/Sm/GetPolicy.php | 2 +- src/OpenSearch/Endpoints/Sm/StartPolicy.php | 2 +- src/OpenSearch/Endpoints/Sm/StopPolicy.php | 2 +- src/OpenSearch/Endpoints/Sm/UpdatePolicy.php | 4 +- .../Endpoints/Snapshot/CleanupRepository.php | 2 +- .../Endpoints/Snapshot/CloneSnapshot.php | 8 +- src/OpenSearch/Endpoints/Snapshot/Create.php | 6 +- .../Endpoints/Snapshot/CreateRepository.php | 4 +- src/OpenSearch/Endpoints/Snapshot/Delete.php | 4 +- src/OpenSearch/Endpoints/Snapshot/Get.php | 2 +- src/OpenSearch/Endpoints/Snapshot/Restore.php | 6 +- src/OpenSearch/Endpoints/Snapshot/Status.php | 2 +- .../Endpoints/Snapshot/VerifyRepository.php | 2 +- src/OpenSearch/Endpoints/Sql/Close.php | 2 +- src/OpenSearch/Endpoints/Sql/Explain.php | 2 +- src/OpenSearch/Endpoints/Sql/PostStats.php | 2 +- src/OpenSearch/Endpoints/Sql/Query.php | 2 +- src/OpenSearch/Endpoints/Sql/Settings.php | 2 +- src/OpenSearch/Endpoints/Tasks/Cancel.php | 2 +- src/OpenSearch/Endpoints/Tasks/Get.php | 2 +- src/OpenSearch/Endpoints/TermVectors.php | 8 +- .../Endpoints/Transforms/Preview.php | 2 +- src/OpenSearch/Endpoints/Transforms/Put.php | 2 +- src/OpenSearch/Endpoints/Update.php | 15 +- src/OpenSearch/Endpoints/UpdateByQuery.php | 9 +- .../Endpoints/UpdateByQueryRethrottle.php | 9 +- .../Endpoints/Wlm/CreateQueryGroup.php | 2 +- .../Endpoints/Wlm/DeleteQueryGroup.php | 2 +- .../Endpoints/Wlm/GetQueryGroup.php | 2 +- .../Endpoints/Wlm/UpdateQueryGroup.php | 4 +- .../AsynchronousSearchNamespace.php | 2 - .../Namespaces/BooleanRequestWrapper.php | 19 +- src/OpenSearch/Namespaces/CatNamespace.php | 348 +++++++------ .../Namespaces/ClusterNamespace.php | 3 +- .../Namespaces/DanglingIndicesNamespace.php | 2 - .../Namespaces/FlowFrameworkNamespace.php | 2 - .../Namespaces/IndicesNamespace.php | 14 +- src/OpenSearch/Namespaces/IngestNamespace.php | 2 - .../Namespaces/InsightsNamespace.php | 2 - src/OpenSearch/Namespaces/IsmNamespace.php | 4 +- src/OpenSearch/Namespaces/KnnNamespace.php | 2 - src/OpenSearch/Namespaces/ListNamespace.php | 10 +- src/OpenSearch/Namespaces/MlNamespace.php | 392 +++++++++++++- src/OpenSearch/Namespaces/NodesNamespace.php | 2 - .../Namespaces/NotificationsNamespace.php | 2 - .../Namespaces/ObservabilityNamespace.php | 2 - src/OpenSearch/Namespaces/PplNamespace.php | 2 - src/OpenSearch/Namespaces/QueryNamespace.php | 2 - .../Namespaces/RemoteStoreNamespace.php | 2 - .../Namespaces/ReplicationNamespace.php | 2 - .../Namespaces/RollupsNamespace.php | 2 - .../Namespaces/SearchPipelineNamespace.php | 2 - .../Namespaces/SecurityNamespace.php | 2 - src/OpenSearch/Namespaces/SmNamespace.php | 2 - .../Namespaces/SnapshotNamespace.php | 2 - src/OpenSearch/Namespaces/SqlNamespace.php | 2 - src/OpenSearch/Namespaces/TasksNamespace.php | 2 - .../Namespaces/TransformsNamespace.php | 2 - src/OpenSearch/Namespaces/WlmNamespace.php | 2 - tests/ClientBuilderTest.php | 3 + tests/ClientIntegrationTest.php | 160 +++--- tests/ClientTest.php | 3 - tests/LegacyClientIntegrationTest.php | 195 +++++++ ...gNamespaceTest.php => MlNamespaceTest.php} | 233 ++++----- tests/Namespaces/SecurityNamespaceTest.php | 477 ++++++++---------- tests/Namespaces/SqlNamespaceTest.php | 75 ++- tests/RegisteredNamespaceTest.php | 2 +- util/EndpointProxies/ml/getConnectorProxy.php | 2 + util/EndpointProxies/ml/predictProxy.php | 11 +- .../ml/updateModelGroupProxy.php | 2 + util/template/client-class | 139 ++++- util/template/required-part | 8 +- 290 files changed, 3141 insertions(+), 1480 deletions(-) create mode 100644 docker-compose.yml create mode 100644 src/OpenSearch/Endpoints/Ml/CreateMemory.php create mode 100644 src/OpenSearch/Endpoints/Ml/CreateMessage.php create mode 100644 src/OpenSearch/Endpoints/Ml/DeleteMemory.php create mode 100644 src/OpenSearch/Endpoints/Ml/GetMemory.php create mode 100644 src/OpenSearch/Endpoints/Ml/GetMessage.php create mode 100644 src/OpenSearch/Endpoints/Ml/GetMessageTraces.php create mode 100644 src/OpenSearch/Endpoints/Ml/SearchConnectors.php create mode 100644 src/OpenSearch/Endpoints/Ml/SearchMemory.php create mode 100644 src/OpenSearch/Endpoints/Ml/SearchMessage.php create mode 100644 src/OpenSearch/Endpoints/Ml/SearchModelGroup.php create mode 100644 src/OpenSearch/Endpoints/Ml/Train.php create mode 100644 src/OpenSearch/Endpoints/Ml/TrainPredict.php create mode 100644 src/OpenSearch/Endpoints/Ml/UpdateConnector.php create mode 100644 src/OpenSearch/Endpoints/Ml/UpdateMemory.php create mode 100644 src/OpenSearch/Endpoints/Ml/UpdateMessage.php create mode 100644 tests/LegacyClientIntegrationTest.php rename tests/Namespaces/{MachineLearningNamespaceTest.php => MlNamespaceTest.php} (63%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 03039ea8..aaf992ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Added workflow for automated API update using OpenSearch API specification ([#209](https://github.com/opensearch-project/opensearch-php/pull/209)) - Added samples ([#218](https://github.com/opensearch-project/opensearch-php/pull/218)) - Added support for PHP 8.3 and 8.4 ([#229](https://github.com/opensearch-project/opensearch-php/pull/229)) +- Added a Docker Compose config file for local development. ### Changed - Switched to PSR Interfaces - Increased PHP min version to 8.1 @@ -15,13 +16,16 @@ Inspired from [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) - Changed fluent setters to return static ### Deprecated - Passing a callable to \OpenSearch\ClientBuilder::setEndpoint() is deprecated and replaced with passing an EndpointFactory to \OpenSearch\ClientBuilder::setEndpointFactory() ([#237](https://github.com/opensearch-project/opensearch-php/pull/237)) -- Connections, Connection pools and Selectors are deprecated. Use a PSR HTTP Client that supports retries instead. +- Connections, Connection pools and Selectors are deprecated. Use a PSR HTTP Client that supports retries instead. +- Throwing exceptions for different HTTP status codes is deprecated. Use the response object to check the status code instead. ### Removed - Removed support for PHP 7.3, 7.4 and 8.0. - Removed support for async requests which were never actually working. ### Fixed - Fixed PHP 8.4 deprecations +- Fixed outdated tests ### Updated APIs +- Updated opensearch-php APIs to reflect [opensearch-api-specification@2395cb4](https://github.com/opensearch-project/opensearch-api-specification/commit/2395cb472ec5581656aac184f7b20548cd5b06ac) - Updated opensearch-php APIs to reflect [opensearch-api-specification@ebe0f8a](https://github.com/opensearch-project/opensearch-api-specification/commit/ebe0f8a885f7db7e882d160c101055a5aa70a707) - Updated opensearch-php APIs to reflect [opensearch-api-specification@398481e](https://github.com/opensearch-project/opensearch-api-specification/commit/398481e5bd1cc590d947c35379c47096f2114f00) - Updated opensearch-php APIs to reflect [opensearch-api-specification@6bb1fed](https://github.com/opensearch-project/opensearch-api-specification/commit/6bb1fed0a2c7cf094a5ecfdb01f0306a4b9f8eba) diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..efb341a3 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,9 @@ +services: + opensearch: + image: opensearchproject/opensearch:2 + ports: + - 9200:9200 + environment: + - discovery.type=single-node + - plugins.security.disabled=true + - OPENSEARCH_INITIAL_ADMIN_PASSWORD=myStrongPassword123! diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 86ac7d34..0597623e 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,9 @@ + + + + ./src/ diff --git a/src/OpenSearch/Client.php b/src/OpenSearch/Client.php index ae6cbb29..8c107f20 100644 --- a/src/OpenSearch/Client.php +++ b/src/OpenSearch/Client.php @@ -21,11 +21,20 @@ namespace OpenSearch; -use OpenSearch\Common\Exceptions\BadMethodCallException; -use OpenSearch\Common\Exceptions\NoNodesAvailableException; +use OpenSearch\Common\Exceptions\BadRequest400Exception; +use OpenSearch\Common\Exceptions\Conflict409Exception; +use OpenSearch\Common\Exceptions\Forbidden403Exception; +use OpenSearch\Common\Exceptions\Missing404Exception; +use OpenSearch\Common\Exceptions\NoDocumentsToGetException; +use OpenSearch\Common\Exceptions\NoShardAvailableException; +use OpenSearch\Common\Exceptions\RequestTimeout408Exception; +use OpenSearch\Common\Exceptions\RoutingMissingException; +use OpenSearch\Common\Exceptions\ScriptLangNotSupportedException; +use OpenSearch\Common\Exceptions\ServerErrorResponseException; +use OpenSearch\Common\Exceptions\Unauthorized401Exception; use OpenSearch\Endpoints\AbstractEndpoint; -use OpenSearch\Namespaces\NamespaceBuilderInterface; use OpenSearch\Namespaces\BooleanRequestWrapper; +use OpenSearch\Namespaces\NamespaceBuilderInterface; use OpenSearch\Namespaces\AsyncSearchNamespace; use OpenSearch\Namespaces\AsynchronousSearchNamespace; use OpenSearch\Namespaces\CatNamespace; @@ -59,7 +68,6 @@ use OpenSearch\Namespaces\TasksNamespace; use OpenSearch\Namespaces\TransformsNamespace; use OpenSearch\Namespaces\WlmNamespace; -use OpenSearch\Traits\DeprecatedPropertyTrait; /** * Class Client @@ -72,6 +80,8 @@ class Client /** * @var Transport + * + * @deprecated in 2.3.2 and will be removed in 3.0.0. */ public $transport; @@ -96,6 +106,11 @@ class Client */ protected $registeredNamespaces = []; + /** + * @deprecated in 2.3.2 and will be removed in 3.0.0. + */ + private bool $throwExceptions = false; + /** * @var AsyncSearchNamespace */ @@ -262,15 +277,21 @@ class Client protected $wlm; + /** * Client constructor * - * @param \OpenSearch\TransportInterface|\OpenSearch\Transport $transport + * @param TransportInterface|Transport $transport * @param callable|EndpointFactoryInterface $endpointFactory * @param NamespaceBuilderInterface[] $registeredNamespaces - */ - public function __construct(TransportInterface|Transport $transport, callable|EndpointFactoryInterface $endpointFactory, array $registeredNamespaces) - { + * @param bool $throwExceptions + */ + public function __construct( + TransportInterface|Transport $transport, + callable|EndpointFactoryInterface $endpointFactory, + array $registeredNamespaces, + bool $throwExceptions = false, + ) { if (!$transport instanceof TransportInterface) { @trigger_error('Passing an instance of \OpenSearch\Transport to ' . __METHOD__ . '() is deprecated in 2.3.2 and will be removed in 3.0.0. Pass an instance of \OpenSearch\TransportInterface instead.', E_USER_DEPRECATED); $this->transport = $transport; @@ -290,6 +311,13 @@ public function __construct(TransportInterface|Transport $transport, callable|En } $this->endpoints = $endpoints; $this->endpointFactory = $endpointFactory; + if ($throwExceptions === true) { + @trigger_error( + 'The $throwExceptions parameter is deprecated in 2.4.0 and will be removed in 3.0.0. Check the response \'status_code\' instead', + E_USER_DEPRECATED + ); + $this->throwExceptions = true; + } $this->asyncSearch = new AsyncSearchNamespace($transport, $this->endpointFactory); $this->asynchronousSearch = new AsynchronousSearchNamespace($transport, $this->endpointFactory); $this->cat = new CatNamespace($transport, $this->endpointFactory); @@ -726,7 +754,7 @@ public function exists(array $params = []): bool $endpoint->setId($id); $endpoint->setIndex($index); - return BooleanRequestWrapper::performRequest($endpoint, $this->transport); + return BooleanRequestWrapper::sendRequest($endpoint, $this->httpTransport); } /** @@ -765,7 +793,7 @@ public function existsSource(array $params = []): bool $endpoint->setId($id); $endpoint->setIndex($index); - return BooleanRequestWrapper::performRequest($endpoint, $this->transport); + return BooleanRequestWrapper::sendRequest($endpoint, $this->httpTransport); } /** @@ -1222,7 +1250,7 @@ public function ping(array $params = []): bool $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ping::class); $endpoint->setParams($params); - return BooleanRequestWrapper::performRequest($endpoint, $this->transport); + return BooleanRequestWrapper::sendRequest($endpoint, $this->httpTransport); } /** @@ -1322,7 +1350,7 @@ public function reindex(array $params = []) } /** - * Changes the number of requests per second for a particular Reindex operation. + * Changes the number of requests per second for a particular reindex operation. * * $params['task_id'] = (string) Identifier for the task. (Required) * $params['requests_per_second'] = (number) The throttle for this request in sub-requests per second. @@ -1408,7 +1436,6 @@ public function scriptsPainlessExecute(array $params = []) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) * $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 "-". - * $params['body'] = (array) The scroll ID if not passed by URL or query parameter. * * @param array $params Associative array of parameters * @return array @@ -2040,14 +2067,14 @@ protected function getEndpointFactory(): EndpointFactoryInterface * Catchall for registered namespaces * * @return object - * @throws BadMethodCallException if the namespace cannot be found + * @throws \BadMethodCallException if the namespace cannot be found */ public function __call(string $name, array $arguments) { if (isset($this->registeredNamespaces[$name])) { return $this->registeredNamespaces[$name]; } - throw new BadMethodCallException("Namespace [$name] not found"); + throw new \BadMethodCallException("Namespace [$name] not found"); } /** @@ -2070,37 +2097,131 @@ public function extractArgument(array &$params, string $arg) } /** - * Sends a raw request to the cluster - * @return array|string|null - * @throws \Exception + * Send a raw request to the cluster. + * + * @throws \Psr\Http\Client\ClientExceptionInterface + * @throws \OpenSearch\Common\Exceptions\OpenSearchException */ - public function request(string $method, string $uri, array $attributes = []): array|string|null - { + public function request( + string $method, + string $uri, + array $attributes = [] + ): array|string|null { $params = $attributes['params'] ?? []; $body = $attributes['body'] ?? null; $options = $attributes['options'] ?? []; - return $this->httpTransport->sendRequest($method, $uri, $params, $body, $options['headers'] ?? []); + $response = $this->httpTransport->sendRequest($method, $uri, $params, $body, $options['headers'] ?? []); + + // @todo: Remove this in the next major release. + // Throw legacy exceptions. + if ($this->throwExceptions) { + if (isset($response['status']) && $response['status'] >= 400) { + $this->throwLegacyException($response); + } + } + + return $response; } /** - * Sends a request for the given endpoint. - * - * @param \OpenSearch\Endpoints\AbstractEndpoint $endpoint - * - * @return array|string|null + * Send a request for an endpoint. * - * @throws \Exception + * @throws \Psr\Http\Client\ClientExceptionInterface + * @throws \OpenSearch\Common\Exceptions\OpenSearchException */ private function performRequest(AbstractEndpoint $endpoint): array|string|null { - $options = $endpoint->getOptions(); - return $this->httpTransport->sendRequest( + $response = $this->httpTransport->sendRequest( $endpoint->getMethod(), $endpoint->getURI(), $endpoint->getParams(), $endpoint->getBody(), - $options['headers'] ?? [] + $endpoint->getOptions() ); + + // @todo: Remove this in the next major release. + // Throw legacy exceptions. + if ($this->throwExceptions) { + if (isset($response['status']) && $response['status'] >= 400) { + $this->throwLegacyException($response); + } + } + + return $response; } + + /** + * Throw legacy exceptions. + * + * @param array $response + * + * @throws \OpenSearch\Common\Exceptions\OpenSearchException + */ + private function throwLegacyException(array $response): void + { + if ($response['status'] >= 400 && $response['status'] < 500) { + $this->throwLegacyClientException($response); + } + if ($response['status'] >= 500) { + $this->throwLegacyServerException($response); + } + } + + /** + * Throw legacy client exceptions based on status code. + * + * @throws \OpenSearch\Common\Exceptions\OpenSearchException + */ + private function throwLegacyClientException($response): void + { + $statusCode = $response['status_code']; + $responseBody = $this->convertBodyToString($response['body'], $statusCode); + throw match ($statusCode) { + 401 => new Unauthorized401Exception($responseBody, $statusCode), + 403 => new Forbidden403Exception($responseBody, $statusCode), + 404 => new Missing404Exception($responseBody, $statusCode), + 409 => new Conflict409Exception($responseBody, $statusCode), + 400 => (str_contains($responseBody, 'script_lang not supported')) + ? new ScriptLangNotSupportedException($responseBody . $statusCode) + : new BadRequest400Exception($responseBody, $statusCode), + 408 => new RequestTimeout408Exception($responseBody, $statusCode), + default => new BadRequest400Exception($responseBody, $statusCode), + }; + } + + /** + * Throw legacy server exceptions based on status code. + * + * @throws \OpenSearch\Common\Exceptions\OpenSearchException + */ + private function throwLegacyServerException($response): void + { + $statusCode = $response['status_code']; + $error = $response['body']['error'] ?? []; + $reason = $error['reason'] ?? 'undefined reason'; + $type = $error['type'] ?? 'undefined type'; + $errorMessage = "$type: $reason"; + $responseBody = $this->convertBodyToString($response['body'], $statusCode); + + $exception = new ServerErrorResponseException($responseBody, $statusCode); + if ($statusCode === 500) { + if (str_contains($responseBody, "RoutingMissingException")) { + $exception = new RoutingMissingException($errorMessage, $statusCode); + } elseif (preg_match('/ActionRequestValidationException.+ no documents to get/', $responseBody) === 1) { + $exception = new NoDocumentsToGetException($errorMessage, $statusCode); + } elseif (str_contains($responseBody, 'NoShardAvailableActionException')) { + $exception = new NoShardAvailableException($errorMessage, $statusCode); + } + } + throw $exception; + } + + private function convertBodyToString(mixed $body, int $statusCode): string + { + return empty($body) + ? "Unknown $statusCode error from OpenSearch" + : (is_string($body) ? $body : json_encode($body)); + } + } diff --git a/src/OpenSearch/Endpoints/AsynchronousSearch/Delete.php b/src/OpenSearch/Endpoints/AsynchronousSearch/Delete.php index fe63dc31..e5aab23a 100644 --- a/src/OpenSearch/Endpoints/AsynchronousSearch/Delete.php +++ b/src/OpenSearch/Endpoints/AsynchronousSearch/Delete.php @@ -25,12 +25,11 @@ class Delete extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for delete' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for delete'); } $id = $this->id; + return "/_plugins/_asynchronous_search/$id"; } diff --git a/src/OpenSearch/Endpoints/AsynchronousSearch/Get.php b/src/OpenSearch/Endpoints/AsynchronousSearch/Get.php index 6caa77b1..c2e32e94 100644 --- a/src/OpenSearch/Endpoints/AsynchronousSearch/Get.php +++ b/src/OpenSearch/Endpoints/AsynchronousSearch/Get.php @@ -25,12 +25,11 @@ class Get extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for get' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for get'); } $id = $this->id; + return "/_plugins/_asynchronous_search/$id"; } diff --git a/src/OpenSearch/Endpoints/AsynchronousSearch/Search.php b/src/OpenSearch/Endpoints/AsynchronousSearch/Search.php index 1d3e4372..c0f8bc1f 100644 --- a/src/OpenSearch/Endpoints/AsynchronousSearch/Search.php +++ b/src/OpenSearch/Endpoints/AsynchronousSearch/Search.php @@ -49,7 +49,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Bulk.php b/src/OpenSearch/Endpoints/Bulk.php index 65b2c16f..6f01cb1f 100644 --- a/src/OpenSearch/Endpoints/Bulk.php +++ b/src/OpenSearch/Endpoints/Bulk.php @@ -70,23 +70,25 @@ public function getMethod(): string return 'POST'; } - public function setBody($body): static + public function setBody(string|iterable|null $body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } - if (is_array($body) === true || $body instanceof Traversable) { - foreach ($body as $item) { - $this->body .= $this->serializer->serialize($item) . "\n"; + + if (is_string($body)) { + if (!str_ends_with($body, "\n")) { + $body .= "\n"; } - } elseif (is_string($body)) { $this->body = $body; - if (substr($body, -1) != "\n") { - $this->body .= "\n"; - } - } else { - throw new InvalidArgumentException("Body must be an array, traversable object or string"); + return $this; } + + // Must be an iterable. + foreach ($body as $item) { + $this->body .= $this->serializer->serialize($item) . "\n"; + } + return $this; } diff --git a/src/OpenSearch/Endpoints/BulkStream.php b/src/OpenSearch/Endpoints/BulkStream.php index daa7c721..4759e2a0 100644 --- a/src/OpenSearch/Endpoints/BulkStream.php +++ b/src/OpenSearch/Endpoints/BulkStream.php @@ -66,23 +66,25 @@ public function getMethod(): string return 'PUT'; } - public function setBody($body): static + public function setBody(string|iterable|null $body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } - if (is_array($body) === true || $body instanceof Traversable) { - foreach ($body as $item) { - $this->body .= $this->serializer->serialize($item) . "\n"; + + if (is_string($body)) { + if (!str_ends_with($body, "\n")) { + $body .= "\n"; } - } elseif (is_string($body)) { $this->body = $body; - if (substr($body, -1) != "\n") { - $this->body .= "\n"; - } - } else { - throw new InvalidArgumentException("Body must be an array, traversable object or string"); + return $this; } + + // Must be an iterable. + foreach ($body as $item) { + $this->body .= $this->serializer->serialize($item) . "\n"; + } + return $this; } diff --git a/src/OpenSearch/Endpoints/Cat/PitSegments.php b/src/OpenSearch/Endpoints/Cat/PitSegments.php index f8aa23f8..c4646ff0 100644 --- a/src/OpenSearch/Endpoints/Cat/PitSegments.php +++ b/src/OpenSearch/Endpoints/Cat/PitSegments.php @@ -51,7 +51,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Cat/Templates.php b/src/OpenSearch/Endpoints/Cat/Templates.php index 116c05f6..563f4c49 100644 --- a/src/OpenSearch/Endpoints/Cat/Templates.php +++ b/src/OpenSearch/Endpoints/Cat/Templates.php @@ -65,7 +65,7 @@ public function getMethod(): string public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/ClearScroll.php b/src/OpenSearch/Endpoints/ClearScroll.php index e00ae70a..93ea6faf 100644 --- a/src/OpenSearch/Endpoints/ClearScroll.php +++ b/src/OpenSearch/Endpoints/ClearScroll.php @@ -61,7 +61,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Cluster/AllocationExplain.php b/src/OpenSearch/Endpoints/Cluster/AllocationExplain.php index 0605f258..c25d7f88 100644 --- a/src/OpenSearch/Endpoints/Cluster/AllocationExplain.php +++ b/src/OpenSearch/Endpoints/Cluster/AllocationExplain.php @@ -53,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Cluster/DeleteComponentTemplate.php b/src/OpenSearch/Endpoints/Cluster/DeleteComponentTemplate.php index 09dbd056..f146f3ab 100644 --- a/src/OpenSearch/Endpoints/Cluster/DeleteComponentTemplate.php +++ b/src/OpenSearch/Endpoints/Cluster/DeleteComponentTemplate.php @@ -61,7 +61,7 @@ public function getMethod(): string public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/Cluster/DeleteWeightedRouting.php b/src/OpenSearch/Endpoints/Cluster/DeleteWeightedRouting.php index a91cb531..e98df561 100644 --- a/src/OpenSearch/Endpoints/Cluster/DeleteWeightedRouting.php +++ b/src/OpenSearch/Endpoints/Cluster/DeleteWeightedRouting.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Cluster/ExistsComponentTemplate.php b/src/OpenSearch/Endpoints/Cluster/ExistsComponentTemplate.php index 84ab4173..a3daa82d 100644 --- a/src/OpenSearch/Endpoints/Cluster/ExistsComponentTemplate.php +++ b/src/OpenSearch/Endpoints/Cluster/ExistsComponentTemplate.php @@ -61,7 +61,7 @@ public function getMethod(): string public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/Cluster/GetComponentTemplate.php b/src/OpenSearch/Endpoints/Cluster/GetComponentTemplate.php index 0d490517..2c2f79b7 100644 --- a/src/OpenSearch/Endpoints/Cluster/GetComponentTemplate.php +++ b/src/OpenSearch/Endpoints/Cluster/GetComponentTemplate.php @@ -43,6 +43,7 @@ public function getParamWhitelist(): array { return [ 'cluster_manager_timeout', + 'flat_settings', 'local', 'master_timeout', 'pretty', diff --git a/src/OpenSearch/Endpoints/Cluster/GetDecommissionAwareness.php b/src/OpenSearch/Endpoints/Cluster/GetDecommissionAwareness.php index 4b0569b2..487c4662 100644 --- a/src/OpenSearch/Endpoints/Cluster/GetDecommissionAwareness.php +++ b/src/OpenSearch/Endpoints/Cluster/GetDecommissionAwareness.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setAwarenessAttributeName($awareness_attribute_name): static { - if (isset($awareness_attribute_name) !== true) { + if (is_null($awareness_attribute_name)) { return $this; } $this->awareness_attribute_name = $awareness_attribute_name; diff --git a/src/OpenSearch/Endpoints/Cluster/GetWeightedRouting.php b/src/OpenSearch/Endpoints/Cluster/GetWeightedRouting.php index dd42bd43..4252925c 100644 --- a/src/OpenSearch/Endpoints/Cluster/GetWeightedRouting.php +++ b/src/OpenSearch/Endpoints/Cluster/GetWeightedRouting.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setAttribute($attribute): static { - if (isset($attribute) !== true) { + if (is_null($attribute)) { return $this; } $this->attribute = $attribute; diff --git a/src/OpenSearch/Endpoints/Cluster/PutComponentTemplate.php b/src/OpenSearch/Endpoints/Cluster/PutComponentTemplate.php index 86a69816..3a31ac1a 100644 --- a/src/OpenSearch/Endpoints/Cluster/PutComponentTemplate.php +++ b/src/OpenSearch/Endpoints/Cluster/PutComponentTemplate.php @@ -62,7 +62,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -72,7 +72,7 @@ public function setBody($body): static public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/Cluster/PutDecommissionAwareness.php b/src/OpenSearch/Endpoints/Cluster/PutDecommissionAwareness.php index 71385600..763ad48b 100644 --- a/src/OpenSearch/Endpoints/Cluster/PutDecommissionAwareness.php +++ b/src/OpenSearch/Endpoints/Cluster/PutDecommissionAwareness.php @@ -54,7 +54,7 @@ public function getMethod(): string public function setAwarenessAttributeName($awareness_attribute_name): static { - if (isset($awareness_attribute_name) !== true) { + if (is_null($awareness_attribute_name)) { return $this; } $this->awareness_attribute_name = $awareness_attribute_name; @@ -64,7 +64,7 @@ public function setAwarenessAttributeName($awareness_attribute_name): static public function setAwarenessAttributeValue($awareness_attribute_value): static { - if (isset($awareness_attribute_value) !== true) { + if (is_null($awareness_attribute_value)) { return $this; } $this->awareness_attribute_value = $awareness_attribute_value; diff --git a/src/OpenSearch/Endpoints/Cluster/PutSettings.php b/src/OpenSearch/Endpoints/Cluster/PutSettings.php index adc67a56..5d435ad1 100644 --- a/src/OpenSearch/Endpoints/Cluster/PutSettings.php +++ b/src/OpenSearch/Endpoints/Cluster/PutSettings.php @@ -55,7 +55,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Cluster/PutWeightedRouting.php b/src/OpenSearch/Endpoints/Cluster/PutWeightedRouting.php index 4c707f66..bdacd829 100644 --- a/src/OpenSearch/Endpoints/Cluster/PutWeightedRouting.php +++ b/src/OpenSearch/Endpoints/Cluster/PutWeightedRouting.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -62,7 +62,7 @@ public function setBody($body): static public function setAttribute($attribute): static { - if (isset($attribute) !== true) { + if (is_null($attribute)) { return $this; } $this->attribute = $attribute; diff --git a/src/OpenSearch/Endpoints/Cluster/Reroute.php b/src/OpenSearch/Endpoints/Cluster/Reroute.php index 52246917..ef6bcd28 100644 --- a/src/OpenSearch/Endpoints/Cluster/Reroute.php +++ b/src/OpenSearch/Endpoints/Cluster/Reroute.php @@ -58,7 +58,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Count.php b/src/OpenSearch/Endpoints/Count.php index b83201db..b26c4bfe 100644 --- a/src/OpenSearch/Endpoints/Count.php +++ b/src/OpenSearch/Endpoints/Count.php @@ -69,7 +69,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Create.php b/src/OpenSearch/Endpoints/Create.php index 28dac6ad..c079d42c 100644 --- a/src/OpenSearch/Endpoints/Create.php +++ b/src/OpenSearch/Endpoints/Create.php @@ -31,18 +31,15 @@ class Create extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for create' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for create'); } $id = $this->id; - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for create' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for create'); } $index = $this->index; + return "/$index/_create/$id"; } @@ -71,7 +68,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/CreatePit.php b/src/OpenSearch/Endpoints/CreatePit.php index 5bebbb45..a872aee5 100644 --- a/src/OpenSearch/Endpoints/CreatePit.php +++ b/src/OpenSearch/Endpoints/CreatePit.php @@ -25,12 +25,11 @@ class CreatePit extends AbstractEndpoint { public function getURI(): string { - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for create_pit' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for create_pit'); } $index = $this->index; + return "/$index/_search/point_in_time"; } diff --git a/src/OpenSearch/Endpoints/DanglingIndices/DeleteDanglingIndex.php b/src/OpenSearch/Endpoints/DanglingIndices/DeleteDanglingIndex.php index 7e9a82c7..36823fd2 100644 --- a/src/OpenSearch/Endpoints/DanglingIndices/DeleteDanglingIndex.php +++ b/src/OpenSearch/Endpoints/DanglingIndices/DeleteDanglingIndex.php @@ -62,7 +62,7 @@ public function getMethod(): string public function setIndexUuid($index_uuid): static { - if (isset($index_uuid) !== true) { + if (is_null($index_uuid)) { return $this; } $this->index_uuid = $index_uuid; diff --git a/src/OpenSearch/Endpoints/DanglingIndices/ImportDanglingIndex.php b/src/OpenSearch/Endpoints/DanglingIndices/ImportDanglingIndex.php index 59550796..24552663 100644 --- a/src/OpenSearch/Endpoints/DanglingIndices/ImportDanglingIndex.php +++ b/src/OpenSearch/Endpoints/DanglingIndices/ImportDanglingIndex.php @@ -62,7 +62,7 @@ public function getMethod(): string public function setIndexUuid($index_uuid): static { - if (isset($index_uuid) !== true) { + if (is_null($index_uuid)) { return $this; } $this->index_uuid = $index_uuid; diff --git a/src/OpenSearch/Endpoints/Delete.php b/src/OpenSearch/Endpoints/Delete.php index 8ef0db8d..7593b5f7 100644 --- a/src/OpenSearch/Endpoints/Delete.php +++ b/src/OpenSearch/Endpoints/Delete.php @@ -31,18 +31,15 @@ class Delete extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for delete' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for delete'); } $id = $this->id; - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for delete' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for delete'); } $index = $this->index; + return "/$index/_doc/$id"; } diff --git a/src/OpenSearch/Endpoints/DeleteByQuery.php b/src/OpenSearch/Endpoints/DeleteByQuery.php index f01f07cf..3f10e0c6 100644 --- a/src/OpenSearch/Endpoints/DeleteByQuery.php +++ b/src/OpenSearch/Endpoints/DeleteByQuery.php @@ -31,12 +31,11 @@ class DeleteByQuery extends AbstractEndpoint { public function getURI(): string { - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for delete_by_query' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for delete_by_query'); } $index = $this->index; + return "/$index/_delete_by_query"; } @@ -91,7 +90,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/DeleteByQueryRethrottle.php b/src/OpenSearch/Endpoints/DeleteByQueryRethrottle.php index 05a53021..dc33c4f5 100644 --- a/src/OpenSearch/Endpoints/DeleteByQueryRethrottle.php +++ b/src/OpenSearch/Endpoints/DeleteByQueryRethrottle.php @@ -33,12 +33,11 @@ class DeleteByQueryRethrottle extends AbstractEndpoint public function getURI(): string { - if (isset($this->task_id) !== true) { - throw new RuntimeException( - 'task_id is required for delete_by_query_rethrottle' - ); + if (!isset($this->task_id) || $this->task_id === '') { + throw new RuntimeException('task_id is required for delete_by_query_rethrottle'); } $task_id = $this->task_id; + return "/_delete_by_query/$task_id/_rethrottle"; } @@ -61,7 +60,7 @@ public function getMethod(): string public function setTaskId($task_id): static { - if (isset($task_id) !== true) { + if (is_null($task_id)) { return $this; } $this->task_id = $task_id; diff --git a/src/OpenSearch/Endpoints/DeletePit.php b/src/OpenSearch/Endpoints/DeletePit.php index eca44019..5c629554 100644 --- a/src/OpenSearch/Endpoints/DeletePit.php +++ b/src/OpenSearch/Endpoints/DeletePit.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/DeleteScript.php b/src/OpenSearch/Endpoints/DeleteScript.php index 36d3bfd7..d7ff9e4d 100644 --- a/src/OpenSearch/Endpoints/DeleteScript.php +++ b/src/OpenSearch/Endpoints/DeleteScript.php @@ -31,12 +31,11 @@ class DeleteScript extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for delete_script' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for delete_script'); } $id = $this->id; + return "/_scripts/$id"; } diff --git a/src/OpenSearch/Endpoints/Exists.php b/src/OpenSearch/Endpoints/Exists.php index be7f3a4c..48bab9ac 100644 --- a/src/OpenSearch/Endpoints/Exists.php +++ b/src/OpenSearch/Endpoints/Exists.php @@ -31,18 +31,15 @@ class Exists extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for exists' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for exists'); } $id = $this->id; - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for exists' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for exists'); } $index = $this->index; + return "/$index/_doc/$id"; } diff --git a/src/OpenSearch/Endpoints/ExistsSource.php b/src/OpenSearch/Endpoints/ExistsSource.php index 7d2b9e7f..e80455b4 100644 --- a/src/OpenSearch/Endpoints/ExistsSource.php +++ b/src/OpenSearch/Endpoints/ExistsSource.php @@ -31,18 +31,15 @@ class ExistsSource extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for exists_source' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for exists_source'); } $id = $this->id; - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for exists_source' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for exists_source'); } $index = $this->index; + return "/$index/_source/$id"; } diff --git a/src/OpenSearch/Endpoints/Explain.php b/src/OpenSearch/Endpoints/Explain.php index 9241ef83..3f86eaf5 100644 --- a/src/OpenSearch/Endpoints/Explain.php +++ b/src/OpenSearch/Endpoints/Explain.php @@ -31,18 +31,15 @@ class Explain extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for explain' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for explain'); } $id = $this->id; - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for explain' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for explain'); } $index = $this->index; + return "/$index/_explain/$id"; } @@ -76,7 +73,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/FieldCaps.php b/src/OpenSearch/Endpoints/FieldCaps.php index d6f22027..92d830ee 100644 --- a/src/OpenSearch/Endpoints/FieldCaps.php +++ b/src/OpenSearch/Endpoints/FieldCaps.php @@ -60,7 +60,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/FlowFramework/Create.php b/src/OpenSearch/Endpoints/FlowFramework/Create.php index 60fbac84..f4f037ea 100644 --- a/src/OpenSearch/Endpoints/FlowFramework/Create.php +++ b/src/OpenSearch/Endpoints/FlowFramework/Create.php @@ -50,7 +50,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/FlowFramework/Delete.php b/src/OpenSearch/Endpoints/FlowFramework/Delete.php index c1a75384..4dd4d0c3 100644 --- a/src/OpenSearch/Endpoints/FlowFramework/Delete.php +++ b/src/OpenSearch/Endpoints/FlowFramework/Delete.php @@ -53,7 +53,7 @@ public function getMethod(): string public function setWorkflowId($workflow_id): static { - if (isset($workflow_id) !== true) { + if (is_null($workflow_id)) { return $this; } $this->workflow_id = $workflow_id; diff --git a/src/OpenSearch/Endpoints/FlowFramework/Deprovision.php b/src/OpenSearch/Endpoints/FlowFramework/Deprovision.php index c9ef2db1..f8acb704 100644 --- a/src/OpenSearch/Endpoints/FlowFramework/Deprovision.php +++ b/src/OpenSearch/Endpoints/FlowFramework/Deprovision.php @@ -53,7 +53,7 @@ public function getMethod(): string public function setWorkflowId($workflow_id): static { - if (isset($workflow_id) !== true) { + if (is_null($workflow_id)) { return $this; } $this->workflow_id = $workflow_id; diff --git a/src/OpenSearch/Endpoints/FlowFramework/Get.php b/src/OpenSearch/Endpoints/FlowFramework/Get.php index 09226a2f..96d43622 100644 --- a/src/OpenSearch/Endpoints/FlowFramework/Get.php +++ b/src/OpenSearch/Endpoints/FlowFramework/Get.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setWorkflowId($workflow_id): static { - if (isset($workflow_id) !== true) { + if (is_null($workflow_id)) { return $this; } $this->workflow_id = $workflow_id; diff --git a/src/OpenSearch/Endpoints/FlowFramework/GetStatus.php b/src/OpenSearch/Endpoints/FlowFramework/GetStatus.php index 9576306f..6d17ab7d 100644 --- a/src/OpenSearch/Endpoints/FlowFramework/GetStatus.php +++ b/src/OpenSearch/Endpoints/FlowFramework/GetStatus.php @@ -53,7 +53,7 @@ public function getMethod(): string public function setWorkflowId($workflow_id): static { - if (isset($workflow_id) !== true) { + if (is_null($workflow_id)) { return $this; } $this->workflow_id = $workflow_id; diff --git a/src/OpenSearch/Endpoints/FlowFramework/Provision.php b/src/OpenSearch/Endpoints/FlowFramework/Provision.php index 9ee121c8..27c85138 100644 --- a/src/OpenSearch/Endpoints/FlowFramework/Provision.php +++ b/src/OpenSearch/Endpoints/FlowFramework/Provision.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -62,7 +62,7 @@ public function setBody($body): static public function setWorkflowId($workflow_id): static { - if (isset($workflow_id) !== true) { + if (is_null($workflow_id)) { return $this; } $this->workflow_id = $workflow_id; diff --git a/src/OpenSearch/Endpoints/FlowFramework/Search.php b/src/OpenSearch/Endpoints/FlowFramework/Search.php index 353287d8..b4f6b998 100644 --- a/src/OpenSearch/Endpoints/FlowFramework/Search.php +++ b/src/OpenSearch/Endpoints/FlowFramework/Search.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/FlowFramework/SearchState.php b/src/OpenSearch/Endpoints/FlowFramework/SearchState.php index d1ee9c7e..e6d0b813 100644 --- a/src/OpenSearch/Endpoints/FlowFramework/SearchState.php +++ b/src/OpenSearch/Endpoints/FlowFramework/SearchState.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/FlowFramework/Update.php b/src/OpenSearch/Endpoints/FlowFramework/Update.php index 73fa0e12..16233f8b 100644 --- a/src/OpenSearch/Endpoints/FlowFramework/Update.php +++ b/src/OpenSearch/Endpoints/FlowFramework/Update.php @@ -57,7 +57,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -67,7 +67,7 @@ public function setBody($body): static public function setWorkflowId($workflow_id): static { - if (isset($workflow_id) !== true) { + if (is_null($workflow_id)) { return $this; } $this->workflow_id = $workflow_id; diff --git a/src/OpenSearch/Endpoints/Get.php b/src/OpenSearch/Endpoints/Get.php index dce7661a..d5c4bb30 100644 --- a/src/OpenSearch/Endpoints/Get.php +++ b/src/OpenSearch/Endpoints/Get.php @@ -31,18 +31,15 @@ class Get extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for get' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for get'); } $id = $this->id; - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for get' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for get'); } $index = $this->index; + return "/$index/_doc/$id"; } diff --git a/src/OpenSearch/Endpoints/GetScript.php b/src/OpenSearch/Endpoints/GetScript.php index eb9ee4ad..aa1e871b 100644 --- a/src/OpenSearch/Endpoints/GetScript.php +++ b/src/OpenSearch/Endpoints/GetScript.php @@ -31,12 +31,11 @@ class GetScript extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for get_script' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for get_script'); } $id = $this->id; + return "/_scripts/$id"; } diff --git a/src/OpenSearch/Endpoints/GetSource.php b/src/OpenSearch/Endpoints/GetSource.php index 5ee7df93..d99afe3e 100644 --- a/src/OpenSearch/Endpoints/GetSource.php +++ b/src/OpenSearch/Endpoints/GetSource.php @@ -31,18 +31,15 @@ class GetSource extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for get_source' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for get_source'); } $id = $this->id; - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for get_source' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for get_source'); } $index = $this->index; + return "/$index/_source/$id"; } diff --git a/src/OpenSearch/Endpoints/Index.php b/src/OpenSearch/Endpoints/Index.php index 48ad123c..64f0a3ea 100644 --- a/src/OpenSearch/Endpoints/Index.php +++ b/src/OpenSearch/Endpoints/Index.php @@ -31,10 +31,8 @@ class Index extends AbstractEndpoint { public function getURI(): string { - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for index' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for index'); } $index = $this->index; $id = $this->id ?? null; @@ -73,7 +71,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Indices/AddBlock.php b/src/OpenSearch/Endpoints/Indices/AddBlock.php index 867c0788..e797fd35 100644 --- a/src/OpenSearch/Endpoints/Indices/AddBlock.php +++ b/src/OpenSearch/Endpoints/Indices/AddBlock.php @@ -65,7 +65,7 @@ public function getMethod(): string public function setBlock($block): static { - if (isset($block) !== true) { + if (is_null($block)) { return $this; } $this->block = $block; diff --git a/src/OpenSearch/Endpoints/Indices/Analyze.php b/src/OpenSearch/Endpoints/Indices/Analyze.php index 63f6612a..1325039c 100644 --- a/src/OpenSearch/Endpoints/Indices/Analyze.php +++ b/src/OpenSearch/Endpoints/Indices/Analyze.php @@ -56,7 +56,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Indices/CloneIndices.php b/src/OpenSearch/Endpoints/Indices/CloneIndices.php index dd92e534..8717637f 100644 --- a/src/OpenSearch/Endpoints/Indices/CloneIndices.php +++ b/src/OpenSearch/Endpoints/Indices/CloneIndices.php @@ -65,7 +65,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -75,7 +75,7 @@ public function setBody($body): static public function setTarget($target): static { - if (isset($target) !== true) { + if (is_null($target)) { return $this; } $this->target = $target; diff --git a/src/OpenSearch/Endpoints/Indices/Create.php b/src/OpenSearch/Endpoints/Indices/Create.php index e0336b80..3bcdafd5 100644 --- a/src/OpenSearch/Endpoints/Indices/Create.php +++ b/src/OpenSearch/Endpoints/Indices/Create.php @@ -60,7 +60,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Indices/CreateDataStream.php b/src/OpenSearch/Endpoints/Indices/CreateDataStream.php index 97a98880..3440922c 100644 --- a/src/OpenSearch/Endpoints/Indices/CreateDataStream.php +++ b/src/OpenSearch/Endpoints/Indices/CreateDataStream.php @@ -58,7 +58,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -68,7 +68,7 @@ public function setBody($body): static public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/Indices/DeleteAlias.php b/src/OpenSearch/Endpoints/Indices/DeleteAlias.php index 7829f215..4a09ce15 100644 --- a/src/OpenSearch/Endpoints/Indices/DeleteAlias.php +++ b/src/OpenSearch/Endpoints/Indices/DeleteAlias.php @@ -33,18 +33,15 @@ class DeleteAlias extends AbstractEndpoint public function getURI(): string { - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for delete_alias' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for delete_alias'); } $index = $this->index; - if (isset($this->name) !== true) { - throw new RuntimeException( - 'name is required for delete_alias' - ); + if (!isset($this->name) || $this->name === '') { + throw new RuntimeException('name is required for delete_alias'); } $name = $this->name; + return "/$index/_alias/$name"; } diff --git a/src/OpenSearch/Endpoints/Indices/DeleteIndexTemplate.php b/src/OpenSearch/Endpoints/Indices/DeleteIndexTemplate.php index a4013a1e..7f3c0ccc 100644 --- a/src/OpenSearch/Endpoints/Indices/DeleteIndexTemplate.php +++ b/src/OpenSearch/Endpoints/Indices/DeleteIndexTemplate.php @@ -61,7 +61,7 @@ public function getMethod(): string public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/Indices/DeleteTemplate.php b/src/OpenSearch/Endpoints/Indices/DeleteTemplate.php index f1137aa0..9f322665 100644 --- a/src/OpenSearch/Endpoints/Indices/DeleteTemplate.php +++ b/src/OpenSearch/Endpoints/Indices/DeleteTemplate.php @@ -61,7 +61,7 @@ public function getMethod(): string public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/Indices/ExistsAlias.php b/src/OpenSearch/Endpoints/Indices/ExistsAlias.php index e8a7fe6e..874943f5 100644 --- a/src/OpenSearch/Endpoints/Indices/ExistsAlias.php +++ b/src/OpenSearch/Endpoints/Indices/ExistsAlias.php @@ -33,10 +33,8 @@ class ExistsAlias extends AbstractEndpoint public function getURI(): string { - if (isset($this->name) !== true) { - throw new RuntimeException( - 'name is required for exists_alias' - ); + if (!isset($this->name) || $this->name === '') { + throw new RuntimeException('name is required for exists_alias'); } $name = $this->name; $index = $this->index ?? null; diff --git a/src/OpenSearch/Endpoints/Indices/ExistsIndexTemplate.php b/src/OpenSearch/Endpoints/Indices/ExistsIndexTemplate.php index e2a57d27..43b26f25 100644 --- a/src/OpenSearch/Endpoints/Indices/ExistsIndexTemplate.php +++ b/src/OpenSearch/Endpoints/Indices/ExistsIndexTemplate.php @@ -62,7 +62,7 @@ public function getMethod(): string public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/Indices/GetFieldMapping.php b/src/OpenSearch/Endpoints/Indices/GetFieldMapping.php index fe2575a8..856e27c9 100644 --- a/src/OpenSearch/Endpoints/Indices/GetFieldMapping.php +++ b/src/OpenSearch/Endpoints/Indices/GetFieldMapping.php @@ -33,10 +33,8 @@ class GetFieldMapping extends AbstractEndpoint public function getURI(): string { - if (isset($this->fields) !== true) { - throw new RuntimeException( - 'fields is required for get_field_mapping' - ); + if (!isset($this->fields) || $this->fields === '') { + throw new RuntimeException('fields is required for get_field_mapping'); } $fields = $this->fields; $index = $this->index ?? null; diff --git a/src/OpenSearch/Endpoints/Indices/PutAlias.php b/src/OpenSearch/Endpoints/Indices/PutAlias.php index eeb8bd5c..c50586f3 100644 --- a/src/OpenSearch/Endpoints/Indices/PutAlias.php +++ b/src/OpenSearch/Endpoints/Indices/PutAlias.php @@ -67,7 +67,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -77,7 +77,7 @@ public function setBody($body): static public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/Indices/PutIndexTemplate.php b/src/OpenSearch/Endpoints/Indices/PutIndexTemplate.php index f263c7f7..ed18f13a 100644 --- a/src/OpenSearch/Endpoints/Indices/PutIndexTemplate.php +++ b/src/OpenSearch/Endpoints/Indices/PutIndexTemplate.php @@ -62,7 +62,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -72,7 +72,7 @@ public function setBody($body): static public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/Indices/PutMapping.php b/src/OpenSearch/Endpoints/Indices/PutMapping.php index b3f63626..0a107bde 100644 --- a/src/OpenSearch/Endpoints/Indices/PutMapping.php +++ b/src/OpenSearch/Endpoints/Indices/PutMapping.php @@ -63,7 +63,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Indices/PutSettings.php b/src/OpenSearch/Endpoints/Indices/PutSettings.php index 0f66696c..c927c63f 100644 --- a/src/OpenSearch/Endpoints/Indices/PutSettings.php +++ b/src/OpenSearch/Endpoints/Indices/PutSettings.php @@ -63,7 +63,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Indices/PutTemplate.php b/src/OpenSearch/Endpoints/Indices/PutTemplate.php index 666d67b3..e3253583 100644 --- a/src/OpenSearch/Endpoints/Indices/PutTemplate.php +++ b/src/OpenSearch/Endpoints/Indices/PutTemplate.php @@ -62,7 +62,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -72,7 +72,7 @@ public function setBody($body): static public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/Indices/Rollover.php b/src/OpenSearch/Endpoints/Indices/Rollover.php index 18c1519b..d867b9d2 100644 --- a/src/OpenSearch/Endpoints/Indices/Rollover.php +++ b/src/OpenSearch/Endpoints/Indices/Rollover.php @@ -34,10 +34,8 @@ class Rollover extends AbstractEndpoint public function getURI(): string { - if (isset($this->alias) !== true) { - throw new RuntimeException( - 'alias is required for rollover' - ); + if (!isset($this->alias) || $this->alias === '') { + throw new RuntimeException('alias is required for rollover'); } $alias = $this->alias; $new_index = $this->new_index ?? null; @@ -70,7 +68,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -80,7 +78,7 @@ public function setBody($body): static public function setAlias($alias): static { - if (isset($alias) !== true) { + if (is_null($alias)) { return $this; } $this->alias = $alias; @@ -90,7 +88,7 @@ public function setAlias($alias): static public function setNewIndex($new_index): static { - if (isset($new_index) !== true) { + if (is_null($new_index)) { return $this; } $this->new_index = $new_index; diff --git a/src/OpenSearch/Endpoints/Indices/Shrink.php b/src/OpenSearch/Endpoints/Indices/Shrink.php index c271712b..f1607bb6 100644 --- a/src/OpenSearch/Endpoints/Indices/Shrink.php +++ b/src/OpenSearch/Endpoints/Indices/Shrink.php @@ -66,7 +66,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -76,7 +76,7 @@ public function setBody($body): static public function setTarget($target): static { - if (isset($target) !== true) { + if (is_null($target)) { return $this; } $this->target = $target; diff --git a/src/OpenSearch/Endpoints/Indices/SimulateIndexTemplate.php b/src/OpenSearch/Endpoints/Indices/SimulateIndexTemplate.php index fcbff55a..1b5a7af7 100644 --- a/src/OpenSearch/Endpoints/Indices/SimulateIndexTemplate.php +++ b/src/OpenSearch/Endpoints/Indices/SimulateIndexTemplate.php @@ -60,7 +60,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -70,7 +70,7 @@ public function setBody($body): static public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/Indices/SimulateTemplate.php b/src/OpenSearch/Endpoints/Indices/SimulateTemplate.php index 16ec3a9d..578e388f 100644 --- a/src/OpenSearch/Endpoints/Indices/SimulateTemplate.php +++ b/src/OpenSearch/Endpoints/Indices/SimulateTemplate.php @@ -61,7 +61,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -71,7 +71,7 @@ public function setBody($body): static public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/Indices/Split.php b/src/OpenSearch/Endpoints/Indices/Split.php index 3fff81d3..366a6807 100644 --- a/src/OpenSearch/Endpoints/Indices/Split.php +++ b/src/OpenSearch/Endpoints/Indices/Split.php @@ -66,7 +66,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -76,7 +76,7 @@ public function setBody($body): static public function setTarget($target): static { - if (isset($target) !== true) { + if (is_null($target)) { return $this; } $this->target = $target; diff --git a/src/OpenSearch/Endpoints/Indices/UpdateAliases.php b/src/OpenSearch/Endpoints/Indices/UpdateAliases.php index d7dcbb9f..dc20cc23 100644 --- a/src/OpenSearch/Endpoints/Indices/UpdateAliases.php +++ b/src/OpenSearch/Endpoints/Indices/UpdateAliases.php @@ -54,7 +54,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Indices/Upgrade.php b/src/OpenSearch/Endpoints/Indices/Upgrade.php index 239c1e4b..3d6ae289 100644 --- a/src/OpenSearch/Endpoints/Indices/Upgrade.php +++ b/src/OpenSearch/Endpoints/Indices/Upgrade.php @@ -57,14 +57,4 @@ public function getMethod(): string { return 'POST'; } - - public function setBody($body): static - { - if (isset($body) !== true) { - return $this; - } - $this->body = $body; - - return $this; - } } diff --git a/src/OpenSearch/Endpoints/Indices/ValidateQuery.php b/src/OpenSearch/Endpoints/Indices/ValidateQuery.php index 008bebfe..ad3e643f 100644 --- a/src/OpenSearch/Endpoints/Indices/ValidateQuery.php +++ b/src/OpenSearch/Endpoints/Indices/ValidateQuery.php @@ -67,7 +67,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ingest/PutPipeline.php b/src/OpenSearch/Endpoints/Ingest/PutPipeline.php index 1a4cef43..f3fa18ad 100644 --- a/src/OpenSearch/Endpoints/Ingest/PutPipeline.php +++ b/src/OpenSearch/Endpoints/Ingest/PutPipeline.php @@ -59,7 +59,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ingest/Simulate.php b/src/OpenSearch/Endpoints/Ingest/Simulate.php index 44e3ba9d..9a774025 100644 --- a/src/OpenSearch/Endpoints/Ingest/Simulate.php +++ b/src/OpenSearch/Endpoints/Ingest/Simulate.php @@ -56,7 +56,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ism/AddPolicy.php b/src/OpenSearch/Endpoints/Ism/AddPolicy.php index 045768ab..b31e06b6 100644 --- a/src/OpenSearch/Endpoints/Ism/AddPolicy.php +++ b/src/OpenSearch/Endpoints/Ism/AddPolicy.php @@ -50,7 +50,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ism/ChangePolicy.php b/src/OpenSearch/Endpoints/Ism/ChangePolicy.php index 49dbb9d2..5424573b 100644 --- a/src/OpenSearch/Endpoints/Ism/ChangePolicy.php +++ b/src/OpenSearch/Endpoints/Ism/ChangePolicy.php @@ -50,7 +50,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ism/DeletePolicy.php b/src/OpenSearch/Endpoints/Ism/DeletePolicy.php index a30b2a25..cd1490b8 100644 --- a/src/OpenSearch/Endpoints/Ism/DeletePolicy.php +++ b/src/OpenSearch/Endpoints/Ism/DeletePolicy.php @@ -27,12 +27,11 @@ class DeletePolicy extends AbstractEndpoint public function getURI(): string { - if (isset($this->policy_id) !== true) { - throw new RuntimeException( - 'policy_id is required for delete_policy' - ); + if (!isset($this->policy_id) || $this->policy_id === '') { + throw new RuntimeException('policy_id is required for delete_policy'); } $policy_id = $this->policy_id; + return "/_plugins/_ism/policies/$policy_id"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setPolicyId($policy_id): static { - if (isset($policy_id) !== true) { + if (is_null($policy_id)) { return $this; } $this->policy_id = $policy_id; diff --git a/src/OpenSearch/Endpoints/Ism/ExistsPolicy.php b/src/OpenSearch/Endpoints/Ism/ExistsPolicy.php index 55ea59b5..95af9236 100644 --- a/src/OpenSearch/Endpoints/Ism/ExistsPolicy.php +++ b/src/OpenSearch/Endpoints/Ism/ExistsPolicy.php @@ -27,12 +27,11 @@ class ExistsPolicy extends AbstractEndpoint public function getURI(): string { - if (isset($this->policy_id) !== true) { - throw new RuntimeException( - 'policy_id is required for exists_policy' - ); + if (!isset($this->policy_id) || $this->policy_id === '') { + throw new RuntimeException('policy_id is required for exists_policy'); } $policy_id = $this->policy_id; + return "/_plugins/_ism/policies/$policy_id"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setPolicyId($policy_id): static { - if (isset($policy_id) !== true) { + if (is_null($policy_id)) { return $this; } $this->policy_id = $policy_id; diff --git a/src/OpenSearch/Endpoints/Ism/ExplainPolicy.php b/src/OpenSearch/Endpoints/Ism/ExplainPolicy.php index 35236df6..bc968077 100644 --- a/src/OpenSearch/Endpoints/Ism/ExplainPolicy.php +++ b/src/OpenSearch/Endpoints/Ism/ExplainPolicy.php @@ -49,7 +49,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ism/GetPolicy.php b/src/OpenSearch/Endpoints/Ism/GetPolicy.php index 469dc775..982b8c06 100644 --- a/src/OpenSearch/Endpoints/Ism/GetPolicy.php +++ b/src/OpenSearch/Endpoints/Ism/GetPolicy.php @@ -27,12 +27,11 @@ class GetPolicy extends AbstractEndpoint public function getURI(): string { - if (isset($this->policy_id) !== true) { - throw new RuntimeException( - 'policy_id is required for get_policy' - ); + if (!isset($this->policy_id) || $this->policy_id === '') { + throw new RuntimeException('policy_id is required for get_policy'); } $policy_id = $this->policy_id; + return "/_plugins/_ism/policies/$policy_id"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setPolicyId($policy_id): static { - if (isset($policy_id) !== true) { + if (is_null($policy_id)) { return $this; } $this->policy_id = $policy_id; diff --git a/src/OpenSearch/Endpoints/Ism/PutPolicies.php b/src/OpenSearch/Endpoints/Ism/PutPolicies.php index 5148d881..09ec3cd9 100644 --- a/src/OpenSearch/Endpoints/Ism/PutPolicies.php +++ b/src/OpenSearch/Endpoints/Ism/PutPolicies.php @@ -48,7 +48,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ism/PutPolicy.php b/src/OpenSearch/Endpoints/Ism/PutPolicy.php index e93b289b..e2a7f7a9 100644 --- a/src/OpenSearch/Endpoints/Ism/PutPolicy.php +++ b/src/OpenSearch/Endpoints/Ism/PutPolicy.php @@ -27,12 +27,11 @@ class PutPolicy extends AbstractEndpoint public function getURI(): string { - if (isset($this->policy_id) !== true) { - throw new RuntimeException( - 'policy_id is required for put_policy' - ); + if (!isset($this->policy_id) || $this->policy_id === '') { + throw new RuntimeException('policy_id is required for put_policy'); } $policy_id = $this->policy_id; + return "/_plugins/_ism/policies/$policy_id"; } @@ -56,7 +55,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -66,7 +65,7 @@ public function setBody($body): static public function setPolicyId($policy_id): static { - if (isset($policy_id) !== true) { + if (is_null($policy_id)) { return $this; } $this->policy_id = $policy_id; diff --git a/src/OpenSearch/Endpoints/Ism/RefreshSearchAnalyzers.php b/src/OpenSearch/Endpoints/Ism/RefreshSearchAnalyzers.php index 57ae3e51..7fff41ff 100644 --- a/src/OpenSearch/Endpoints/Ism/RefreshSearchAnalyzers.php +++ b/src/OpenSearch/Endpoints/Ism/RefreshSearchAnalyzers.php @@ -25,12 +25,11 @@ class RefreshSearchAnalyzers extends AbstractEndpoint { public function getURI(): string { - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for refresh_search_analyzers' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for refresh_search_analyzers'); } $index = $this->index; + return "/_plugins/_refresh_search_analyzers/$index"; } diff --git a/src/OpenSearch/Endpoints/Ism/RetryIndex.php b/src/OpenSearch/Endpoints/Ism/RetryIndex.php index 1056aab5..8744420a 100644 --- a/src/OpenSearch/Endpoints/Ism/RetryIndex.php +++ b/src/OpenSearch/Endpoints/Ism/RetryIndex.php @@ -50,7 +50,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Knn/DeleteModel.php b/src/OpenSearch/Endpoints/Knn/DeleteModel.php index f650a575..81069be4 100644 --- a/src/OpenSearch/Endpoints/Knn/DeleteModel.php +++ b/src/OpenSearch/Endpoints/Knn/DeleteModel.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setModelId($model_id): static { - if (isset($model_id) !== true) { + if (is_null($model_id)) { return $this; } $this->model_id = $model_id; diff --git a/src/OpenSearch/Endpoints/Knn/GetModel.php b/src/OpenSearch/Endpoints/Knn/GetModel.php index 410d884b..1ea80d2d 100644 --- a/src/OpenSearch/Endpoints/Knn/GetModel.php +++ b/src/OpenSearch/Endpoints/Knn/GetModel.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setModelId($model_id): static { - if (isset($model_id) !== true) { + if (is_null($model_id)) { return $this; } $this->model_id = $model_id; diff --git a/src/OpenSearch/Endpoints/Knn/SearchModels.php b/src/OpenSearch/Endpoints/Knn/SearchModels.php index cd25afc5..a190a829 100644 --- a/src/OpenSearch/Endpoints/Knn/SearchModels.php +++ b/src/OpenSearch/Endpoints/Knn/SearchModels.php @@ -87,7 +87,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Knn/TrainModel.php b/src/OpenSearch/Endpoints/Knn/TrainModel.php index cf4cbc3b..95908b1d 100644 --- a/src/OpenSearch/Endpoints/Knn/TrainModel.php +++ b/src/OpenSearch/Endpoints/Knn/TrainModel.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -62,7 +62,7 @@ public function setBody($body): static public function setModelId($model_id): static { - if (isset($model_id) !== true) { + if (is_null($model_id)) { return $this; } $this->model_id = $model_id; diff --git a/src/OpenSearch/Endpoints/Knn/Warmup.php b/src/OpenSearch/Endpoints/Knn/Warmup.php index 7251ae6b..9dcb24df 100644 --- a/src/OpenSearch/Endpoints/Knn/Warmup.php +++ b/src/OpenSearch/Endpoints/Knn/Warmup.php @@ -25,12 +25,11 @@ class Warmup extends AbstractEndpoint { public function getURI(): string { - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for warmup' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for warmup'); } $index = $this->index; + return "/_plugins/_knn/warmup/$index"; } diff --git a/src/OpenSearch/Endpoints/MTermVectors.php b/src/OpenSearch/Endpoints/MTermVectors.php index f76e0880..79190b17 100644 --- a/src/OpenSearch/Endpoints/MTermVectors.php +++ b/src/OpenSearch/Endpoints/MTermVectors.php @@ -67,7 +67,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Mget.php b/src/OpenSearch/Endpoints/Mget.php index edd7682f..652bba7c 100644 --- a/src/OpenSearch/Endpoints/Mget.php +++ b/src/OpenSearch/Endpoints/Mget.php @@ -63,7 +63,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ml/CreateConnector.php b/src/OpenSearch/Endpoints/Ml/CreateConnector.php index 887bf987..b7b8a46f 100644 --- a/src/OpenSearch/Endpoints/Ml/CreateConnector.php +++ b/src/OpenSearch/Endpoints/Ml/CreateConnector.php @@ -43,7 +43,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ml/CreateMemory.php b/src/OpenSearch/Endpoints/Ml/CreateMemory.php new file mode 100644 index 00000000..8f108666 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/CreateMemory.php @@ -0,0 +1,55 @@ +body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/CreateMessage.php b/src/OpenSearch/Endpoints/Ml/CreateMessage.php new file mode 100644 index 00000000..11d9dd6f --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/CreateMessage.php @@ -0,0 +1,72 @@ +memory_id ?? null; + if (isset($memory_id)) { + return "/_plugins/_ml/memory/$memory_id/messages"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.create_message'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'POST'; + } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } + + public function setMemoryId($memory_id): static + { + if (is_null($memory_id)) { + return $this; + } + $this->memory_id = $memory_id; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/DeleteAgent.php b/src/OpenSearch/Endpoints/Ml/DeleteAgent.php index fb8c4656..12a83214 100644 --- a/src/OpenSearch/Endpoints/Ml/DeleteAgent.php +++ b/src/OpenSearch/Endpoints/Ml/DeleteAgent.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setAgentId($agent_id): static { - if (isset($agent_id) !== true) { + if (is_null($agent_id)) { return $this; } $this->agent_id = $agent_id; diff --git a/src/OpenSearch/Endpoints/Ml/DeleteConnector.php b/src/OpenSearch/Endpoints/Ml/DeleteConnector.php index 6c28dd27..50006093 100644 --- a/src/OpenSearch/Endpoints/Ml/DeleteConnector.php +++ b/src/OpenSearch/Endpoints/Ml/DeleteConnector.php @@ -50,7 +50,7 @@ public function getMethod(): string public function setConnectorId($connector_id): static { - if (isset($connector_id) !== true) { + if (is_null($connector_id)) { return $this; } $this->connector_id = $connector_id; diff --git a/src/OpenSearch/Endpoints/Ml/DeleteMemory.php b/src/OpenSearch/Endpoints/Ml/DeleteMemory.php new file mode 100644 index 00000000..5ff1ff13 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/DeleteMemory.php @@ -0,0 +1,62 @@ +memory_id ?? null; + if (isset($memory_id)) { + return "/_plugins/_ml/memory/$memory_id"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.delete_memory'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'DELETE'; + } + + public function setMemoryId($memory_id): static + { + if (is_null($memory_id)) { + return $this; + } + $this->memory_id = $memory_id; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/DeleteTask.php b/src/OpenSearch/Endpoints/Ml/DeleteTask.php index cbff3d87..3d71256c 100644 --- a/src/OpenSearch/Endpoints/Ml/DeleteTask.php +++ b/src/OpenSearch/Endpoints/Ml/DeleteTask.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setTaskId($task_id): static { - if (isset($task_id) !== true) { + if (is_null($task_id)) { return $this; } $this->task_id = $task_id; diff --git a/src/OpenSearch/Endpoints/Ml/DeployModel.php b/src/OpenSearch/Endpoints/Ml/DeployModel.php index e69da694..51fc67ac 100644 --- a/src/OpenSearch/Endpoints/Ml/DeployModel.php +++ b/src/OpenSearch/Endpoints/Ml/DeployModel.php @@ -50,7 +50,7 @@ public function getMethod(): string public function setModelId($model_id): static { - if (isset($model_id) !== true) { + if (is_null($model_id)) { return $this; } $this->model_id = $model_id; diff --git a/src/OpenSearch/Endpoints/Ml/GetConnector.php b/src/OpenSearch/Endpoints/Ml/GetConnector.php index 9a612a63..ac9d1aba 100644 --- a/src/OpenSearch/Endpoints/Ml/GetConnector.php +++ b/src/OpenSearch/Endpoints/Ml/GetConnector.php @@ -16,36 +16,45 @@ use OpenSearch\Common\Exceptions\RuntimeException; use OpenSearch\Endpoints\AbstractEndpoint; +/** + * NOTE: This file is autogenerated using util/GenerateEndpoints.php + */ class GetConnector extends AbstractEndpoint { - /** - * @return string[] - */ - public function getParamWhitelist(): array - { - return []; - } + protected $connector_id; - /** - * @return string - */ public function getURI(): string { - if ($this->id) { - return "/_plugins/_ml/connectors/$this->id"; + $connector_id = $this->connector_id ?? null; + if (isset($connector_id)) { + return "/_plugins/_ml/connectors/$connector_id"; } + throw new RuntimeException('Missing parameter for the endpoint ml.get_connector'); + } - throw new RuntimeException( - 'id is required for get' - ); - + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; } - /** - * @return string - */ public function getMethod(): string { return 'GET'; } + + public function setConnectorId($connector_id): static + { + if (is_null($connector_id)) { + return $this; + } + $this->connector_id = $connector_id; + + return $this; + } } diff --git a/src/OpenSearch/Endpoints/Ml/GetMemory.php b/src/OpenSearch/Endpoints/Ml/GetMemory.php new file mode 100644 index 00000000..7fe40ef8 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/GetMemory.php @@ -0,0 +1,71 @@ +memory_id ?? null; + if (isset($memory_id)) { + return "/_plugins/_ml/memory/$memory_id"; + } + return "/_plugins/_ml/memory"; + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'GET'; + } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } + + public function setMemoryId($memory_id): static + { + if (is_null($memory_id)) { + return $this; + } + $this->memory_id = $memory_id; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/GetMessage.php b/src/OpenSearch/Endpoints/Ml/GetMessage.php new file mode 100644 index 00000000..d3b2a4ff --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/GetMessage.php @@ -0,0 +1,77 @@ +memory_id ?? null; + $message_id = $this->message_id ?? null; + if (isset($memory_id)) { + return "/_plugins/_ml/memory/$memory_id/messages"; + } + if (isset($message_id)) { + return "/_plugins/_ml/memory/message/$message_id"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.get_message'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'GET'; + } + + public function setMemoryId($memory_id): static + { + if (is_null($memory_id)) { + return $this; + } + $this->memory_id = $memory_id; + + return $this; + } + + public function setMessageId($message_id): static + { + if (is_null($message_id)) { + return $this; + } + $this->message_id = $message_id; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/GetMessageTraces.php b/src/OpenSearch/Endpoints/Ml/GetMessageTraces.php new file mode 100644 index 00000000..5698cb47 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/GetMessageTraces.php @@ -0,0 +1,62 @@ +message_id ?? null; + if (isset($message_id)) { + return "/_plugins/_ml/memory/message/$message_id/traces"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.get_message_traces'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'GET'; + } + + public function setMessageId($message_id): static + { + if (is_null($message_id)) { + return $this; + } + $this->message_id = $message_id; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/GetModelGroup.php b/src/OpenSearch/Endpoints/Ml/GetModelGroup.php index 989f9ae2..9a0ddbec 100644 --- a/src/OpenSearch/Endpoints/Ml/GetModelGroup.php +++ b/src/OpenSearch/Endpoints/Ml/GetModelGroup.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setModelGroupId($model_group_id): static { - if (isset($model_group_id) !== true) { + if (is_null($model_group_id)) { return $this; } $this->model_group_id = $model_group_id; diff --git a/src/OpenSearch/Endpoints/Ml/Predict.php b/src/OpenSearch/Endpoints/Ml/Predict.php index 034905f5..b9ce4e0b 100644 --- a/src/OpenSearch/Endpoints/Ml/Predict.php +++ b/src/OpenSearch/Endpoints/Ml/Predict.php @@ -16,36 +16,67 @@ use OpenSearch\Common\Exceptions\RuntimeException; use OpenSearch\Endpoints\AbstractEndpoint; +/** + * NOTE: This file is autogenerated using util/GenerateEndpoints.php + */ class Predict extends AbstractEndpoint { - /** - * @return string[] - */ + protected $algorithm_name; + protected $model_id; + + public function getURI(): string + { + $algorithm_name = $this->algorithm_name ?? null; + $model_id = $this->model_id ?? null; + if (isset($algorithm_name) && isset($model_id)) { + return "/_plugins/_ml/_predict/$algorithm_name/$model_id"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.predict'); + } + public function getParamWhitelist(): array { - return []; + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; } - /** - * @return string - */ - public function getURI(): string + public function getMethod(): string + { + return 'POST'; + } + + public function setBody($body): static { - if ($this->id) { - return "/_plugins/_ml/models/$this->id/_predict"; + if (is_null($body)) { + return $this; } + $this->body = $body; - throw new RuntimeException( - 'id is required for predict' - ); + return $this; + } + public function setAlgorithmName($algorithm_name): static + { + if (is_null($algorithm_name)) { + return $this; + } + $this->algorithm_name = $algorithm_name; + + return $this; } - /** - * @return string - */ - public function getMethod(): string + public function setModelId($model_id): static { - return 'POST'; + if (is_null($model_id)) { + return $this; + } + $this->model_id = $model_id; + + return $this; } } diff --git a/src/OpenSearch/Endpoints/Ml/RegisterAgents.php b/src/OpenSearch/Endpoints/Ml/RegisterAgents.php index 11051da1..cbfa9087 100644 --- a/src/OpenSearch/Endpoints/Ml/RegisterAgents.php +++ b/src/OpenSearch/Endpoints/Ml/RegisterAgents.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ml/RegisterModel.php b/src/OpenSearch/Endpoints/Ml/RegisterModel.php index 49824326..1cb23111 100644 --- a/src/OpenSearch/Endpoints/Ml/RegisterModel.php +++ b/src/OpenSearch/Endpoints/Ml/RegisterModel.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ml/RegisterModelGroup.php b/src/OpenSearch/Endpoints/Ml/RegisterModelGroup.php index ff4943ec..6058edec 100644 --- a/src/OpenSearch/Endpoints/Ml/RegisterModelGroup.php +++ b/src/OpenSearch/Endpoints/Ml/RegisterModelGroup.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ml/SearchConnectors.php b/src/OpenSearch/Endpoints/Ml/SearchConnectors.php new file mode 100644 index 00000000..b03ccf7c --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/SearchConnectors.php @@ -0,0 +1,55 @@ +body) ? 'POST' : 'GET'; + } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/SearchMemory.php b/src/OpenSearch/Endpoints/Ml/SearchMemory.php new file mode 100644 index 00000000..938b7ed4 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/SearchMemory.php @@ -0,0 +1,55 @@ +body) ? 'POST' : 'GET'; + } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/SearchMessage.php b/src/OpenSearch/Endpoints/Ml/SearchMessage.php new file mode 100644 index 00000000..101cf486 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/SearchMessage.php @@ -0,0 +1,72 @@ +memory_id ?? null; + if (isset($memory_id)) { + return "/_plugins/_ml/memory/$memory_id/_search"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.search_message'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return isset($this->body) ? 'POST' : 'GET'; + } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } + + public function setMemoryId($memory_id): static + { + if (is_null($memory_id)) { + return $this; + } + $this->memory_id = $memory_id; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/SearchModelGroup.php b/src/OpenSearch/Endpoints/Ml/SearchModelGroup.php new file mode 100644 index 00000000..68d8feca --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/SearchModelGroup.php @@ -0,0 +1,55 @@ +body) ? 'POST' : 'GET'; + } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/SearchModels.php b/src/OpenSearch/Endpoints/Ml/SearchModels.php index 84512e7c..25d7e06b 100644 --- a/src/OpenSearch/Endpoints/Ml/SearchModels.php +++ b/src/OpenSearch/Endpoints/Ml/SearchModels.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ml/Train.php b/src/OpenSearch/Endpoints/Ml/Train.php new file mode 100644 index 00000000..6273ac4d --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/Train.php @@ -0,0 +1,72 @@ +algorithm_name ?? null; + if (isset($algorithm_name)) { + return "/_plugins/_ml/_train/$algorithm_name"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.train'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'POST'; + } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } + + public function setAlgorithmName($algorithm_name): static + { + if (is_null($algorithm_name)) { + return $this; + } + $this->algorithm_name = $algorithm_name; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/TrainPredict.php b/src/OpenSearch/Endpoints/Ml/TrainPredict.php new file mode 100644 index 00000000..6c289bd2 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/TrainPredict.php @@ -0,0 +1,72 @@ +algorithm_name ?? null; + if (isset($algorithm_name)) { + return "/_plugins/_ml/_train_predict/$algorithm_name"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.train_predict'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'POST'; + } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } + + public function setAlgorithmName($algorithm_name): static + { + if (is_null($algorithm_name)) { + return $this; + } + $this->algorithm_name = $algorithm_name; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/UndeployModel.php b/src/OpenSearch/Endpoints/Ml/UndeployModel.php index 3aff2bad..313dba61 100644 --- a/src/OpenSearch/Endpoints/Ml/UndeployModel.php +++ b/src/OpenSearch/Endpoints/Ml/UndeployModel.php @@ -50,7 +50,7 @@ public function getMethod(): string public function setModelId($model_id): static { - if (isset($model_id) !== true) { + if (is_null($model_id)) { return $this; } $this->model_id = $model_id; diff --git a/src/OpenSearch/Endpoints/Ml/UpdateConnector.php b/src/OpenSearch/Endpoints/Ml/UpdateConnector.php new file mode 100644 index 00000000..ee530b8b --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/UpdateConnector.php @@ -0,0 +1,72 @@ +connector_id ?? null; + if (isset($connector_id)) { + return "/_plugins/_ml/connectors/$connector_id"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.update_connector'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'PUT'; + } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } + + public function setConnectorId($connector_id): static + { + if (is_null($connector_id)) { + return $this; + } + $this->connector_id = $connector_id; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/UpdateMemory.php b/src/OpenSearch/Endpoints/Ml/UpdateMemory.php new file mode 100644 index 00000000..a87d0f36 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/UpdateMemory.php @@ -0,0 +1,72 @@ +memory_id ?? null; + if (isset($memory_id)) { + return "/_plugins/_ml/memory/$memory_id"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.update_memory'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'PUT'; + } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } + + public function setMemoryId($memory_id): static + { + if (is_null($memory_id)) { + return $this; + } + $this->memory_id = $memory_id; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/UpdateMessage.php b/src/OpenSearch/Endpoints/Ml/UpdateMessage.php new file mode 100644 index 00000000..1cea2b63 --- /dev/null +++ b/src/OpenSearch/Endpoints/Ml/UpdateMessage.php @@ -0,0 +1,72 @@ +message_id ?? null; + if (isset($message_id)) { + return "/_plugins/_ml/memory/message/$message_id"; + } + throw new RuntimeException('Missing parameter for the endpoint ml.update_message'); + } + + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; + } + + public function getMethod(): string + { + return 'PUT'; + } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } + + public function setMessageId($message_id): static + { + if (is_null($message_id)) { + return $this; + } + $this->message_id = $message_id; + + return $this; + } +} diff --git a/src/OpenSearch/Endpoints/Ml/UpdateModelGroup.php b/src/OpenSearch/Endpoints/Ml/UpdateModelGroup.php index 48d3809c..9eb0b759 100644 --- a/src/OpenSearch/Endpoints/Ml/UpdateModelGroup.php +++ b/src/OpenSearch/Endpoints/Ml/UpdateModelGroup.php @@ -16,35 +16,55 @@ use OpenSearch\Common\Exceptions\RuntimeException; use OpenSearch\Endpoints\AbstractEndpoint; +/** + * NOTE: This file is autogenerated using util/GenerateEndpoints.php + */ class UpdateModelGroup extends AbstractEndpoint { - /** - * @return string[] - */ - public function getParamWhitelist(): array - { - return []; - } + protected $model_group_id; - /** - * @return string - */ public function getURI(): string { - if ($this->id) { - return "/_plugins/_ml/model_groups/$this->id"; + $model_group_id = $this->model_group_id ?? null; + if (isset($model_group_id)) { + return "/_plugins/_ml/model_groups/$model_group_id"; } + throw new RuntimeException('Missing parameter for the endpoint ml.update_model_group'); + } - throw new RuntimeException( - 'id is required for update' - ); + public function getParamWhitelist(): array + { + return [ + 'pretty', + 'human', + 'error_trace', + 'source', + 'filter_path' + ]; } - /** - * @return string - */ public function getMethod(): string { return 'PUT'; } + + public function setBody($body): static + { + if (is_null($body)) { + return $this; + } + $this->body = $body; + + return $this; + } + + public function setModelGroupId($model_group_id): static + { + if (is_null($model_group_id)) { + return $this; + } + $this->model_group_id = $model_group_id; + + return $this; + } } diff --git a/src/OpenSearch/Endpoints/Msearch.php b/src/OpenSearch/Endpoints/Msearch.php index a7e39285..3994ea29 100644 --- a/src/OpenSearch/Endpoints/Msearch.php +++ b/src/OpenSearch/Endpoints/Msearch.php @@ -68,23 +68,25 @@ public function getMethod(): string return isset($this->body) ? 'POST' : 'GET'; } - public function setBody($body): static + public function setBody(string|iterable|null $body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } - if (is_array($body) === true || $body instanceof Traversable) { - foreach ($body as $item) { - $this->body .= $this->serializer->serialize($item) . "\n"; + + if (is_string($body)) { + if (!str_ends_with($body, "\n")) { + $body .= "\n"; } - } elseif (is_string($body)) { $this->body = $body; - if (substr($body, -1) != "\n") { - $this->body .= "\n"; - } - } else { - throw new InvalidArgumentException("Body must be an array, traversable object or string"); + return $this; } + + // Must be an iterable. + foreach ($body as $item) { + $this->body .= $this->serializer->serialize($item) . "\n"; + } + return $this; } diff --git a/src/OpenSearch/Endpoints/MsearchTemplate.php b/src/OpenSearch/Endpoints/MsearchTemplate.php index 247882f7..8a730b49 100644 --- a/src/OpenSearch/Endpoints/MsearchTemplate.php +++ b/src/OpenSearch/Endpoints/MsearchTemplate.php @@ -66,23 +66,25 @@ public function getMethod(): string return isset($this->body) ? 'POST' : 'GET'; } - public function setBody($body): static + public function setBody(string|iterable|null $body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } - if (is_array($body) === true || $body instanceof Traversable) { - foreach ($body as $item) { - $this->body .= $this->serializer->serialize($item) . "\n"; + + if (is_string($body)) { + if (!str_ends_with($body, "\n")) { + $body .= "\n"; } - } elseif (is_string($body)) { $this->body = $body; - if (substr($body, -1) != "\n") { - $this->body .= "\n"; - } - } else { - throw new InvalidArgumentException("Body must be an array, traversable object or string"); + return $this; } + + // Must be an iterable. + foreach ($body as $item) { + $this->body .= $this->serializer->serialize($item) . "\n"; + } + return $this; } diff --git a/src/OpenSearch/Endpoints/Nodes/Info.php b/src/OpenSearch/Endpoints/Nodes/Info.php index da403a7c..03208412 100644 --- a/src/OpenSearch/Endpoints/Nodes/Info.php +++ b/src/OpenSearch/Endpoints/Nodes/Info.php @@ -72,7 +72,7 @@ public function getMethod(): string public function setNodeIdOrMetric($node_id_or_metric): static { - if (isset($node_id_or_metric) !== true) { + if (is_null($node_id_or_metric)) { return $this; } $this->node_id_or_metric = $node_id_or_metric; diff --git a/src/OpenSearch/Endpoints/Nodes/ReloadSecureSettings.php b/src/OpenSearch/Endpoints/Nodes/ReloadSecureSettings.php index 6b3a6a14..1f74c3fb 100644 --- a/src/OpenSearch/Endpoints/Nodes/ReloadSecureSettings.php +++ b/src/OpenSearch/Endpoints/Nodes/ReloadSecureSettings.php @@ -58,7 +58,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Notifications/CreateConfig.php b/src/OpenSearch/Endpoints/Notifications/CreateConfig.php index a21b3c4c..d1a8797c 100644 --- a/src/OpenSearch/Endpoints/Notifications/CreateConfig.php +++ b/src/OpenSearch/Endpoints/Notifications/CreateConfig.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Notifications/DeleteConfig.php b/src/OpenSearch/Endpoints/Notifications/DeleteConfig.php index 6bab9ea4..d4bf129e 100644 --- a/src/OpenSearch/Endpoints/Notifications/DeleteConfig.php +++ b/src/OpenSearch/Endpoints/Notifications/DeleteConfig.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setConfigId($config_id): static { - if (isset($config_id) !== true) { + if (is_null($config_id)) { return $this; } $this->config_id = $config_id; diff --git a/src/OpenSearch/Endpoints/Notifications/GetConfig.php b/src/OpenSearch/Endpoints/Notifications/GetConfig.php index 444dfb10..7e67117f 100644 --- a/src/OpenSearch/Endpoints/Notifications/GetConfig.php +++ b/src/OpenSearch/Endpoints/Notifications/GetConfig.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setConfigId($config_id): static { - if (isset($config_id) !== true) { + if (is_null($config_id)) { return $this; } $this->config_id = $config_id; diff --git a/src/OpenSearch/Endpoints/Notifications/GetConfigs.php b/src/OpenSearch/Endpoints/Notifications/GetConfigs.php index 22d250e1..5c02105f 100644 --- a/src/OpenSearch/Endpoints/Notifications/GetConfigs.php +++ b/src/OpenSearch/Endpoints/Notifications/GetConfigs.php @@ -85,7 +85,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Notifications/SendTest.php b/src/OpenSearch/Endpoints/Notifications/SendTest.php index 2ff69181..c9f237b1 100644 --- a/src/OpenSearch/Endpoints/Notifications/SendTest.php +++ b/src/OpenSearch/Endpoints/Notifications/SendTest.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setConfigId($config_id): static { - if (isset($config_id) !== true) { + if (is_null($config_id)) { return $this; } $this->config_id = $config_id; diff --git a/src/OpenSearch/Endpoints/Notifications/UpdateConfig.php b/src/OpenSearch/Endpoints/Notifications/UpdateConfig.php index 55fa5575..e8b551d7 100644 --- a/src/OpenSearch/Endpoints/Notifications/UpdateConfig.php +++ b/src/OpenSearch/Endpoints/Notifications/UpdateConfig.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -62,7 +62,7 @@ public function setBody($body): static public function setConfigId($config_id): static { - if (isset($config_id) !== true) { + if (is_null($config_id)) { return $this; } $this->config_id = $config_id; diff --git a/src/OpenSearch/Endpoints/Observability/CreateObject.php b/src/OpenSearch/Endpoints/Observability/CreateObject.php index a88377e5..7002addc 100644 --- a/src/OpenSearch/Endpoints/Observability/CreateObject.php +++ b/src/OpenSearch/Endpoints/Observability/CreateObject.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Observability/DeleteObject.php b/src/OpenSearch/Endpoints/Observability/DeleteObject.php index 308d4da4..bbc38c27 100644 --- a/src/OpenSearch/Endpoints/Observability/DeleteObject.php +++ b/src/OpenSearch/Endpoints/Observability/DeleteObject.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setObjectId($object_id): static { - if (isset($object_id) !== true) { + if (is_null($object_id)) { return $this; } $this->object_id = $object_id; diff --git a/src/OpenSearch/Endpoints/Observability/GetObject.php b/src/OpenSearch/Endpoints/Observability/GetObject.php index ed967f9b..94c65fd8 100644 --- a/src/OpenSearch/Endpoints/Observability/GetObject.php +++ b/src/OpenSearch/Endpoints/Observability/GetObject.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setObjectId($object_id): static { - if (isset($object_id) !== true) { + if (is_null($object_id)) { return $this; } $this->object_id = $object_id; diff --git a/src/OpenSearch/Endpoints/Observability/UpdateObject.php b/src/OpenSearch/Endpoints/Observability/UpdateObject.php index 69d44e46..a4567f21 100644 --- a/src/OpenSearch/Endpoints/Observability/UpdateObject.php +++ b/src/OpenSearch/Endpoints/Observability/UpdateObject.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -62,7 +62,7 @@ public function setBody($body): static public function setObjectId($object_id): static { - if (isset($object_id) !== true) { + if (is_null($object_id)) { return $this; } $this->object_id = $object_id; diff --git a/src/OpenSearch/Endpoints/Ppl/Explain.php b/src/OpenSearch/Endpoints/Ppl/Explain.php index 4e1c0468..b49f52e1 100644 --- a/src/OpenSearch/Endpoints/Ppl/Explain.php +++ b/src/OpenSearch/Endpoints/Ppl/Explain.php @@ -47,7 +47,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ppl/PostStats.php b/src/OpenSearch/Endpoints/Ppl/PostStats.php index e7763bdc..0178628d 100644 --- a/src/OpenSearch/Endpoints/Ppl/PostStats.php +++ b/src/OpenSearch/Endpoints/Ppl/PostStats.php @@ -47,7 +47,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Ppl/Query.php b/src/OpenSearch/Endpoints/Ppl/Query.php index 47c31e35..f67cd566 100644 --- a/src/OpenSearch/Endpoints/Ppl/Query.php +++ b/src/OpenSearch/Endpoints/Ppl/Query.php @@ -47,7 +47,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/PutScript.php b/src/OpenSearch/Endpoints/PutScript.php index 43323828..25e4fab3 100644 --- a/src/OpenSearch/Endpoints/PutScript.php +++ b/src/OpenSearch/Endpoints/PutScript.php @@ -33,10 +33,8 @@ class PutScript extends AbstractEndpoint public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for put_script' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for put_script'); } $id = $this->id; $context = $this->context ?? null; @@ -68,7 +66,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -78,7 +76,7 @@ public function setBody($body): static public function setContext($context): static { - if (isset($context) !== true) { + if (is_null($context)) { return $this; } $this->context = $context; diff --git a/src/OpenSearch/Endpoints/Query/DatasourceDelete.php b/src/OpenSearch/Endpoints/Query/DatasourceDelete.php index 717019ba..ccb0b156 100644 --- a/src/OpenSearch/Endpoints/Query/DatasourceDelete.php +++ b/src/OpenSearch/Endpoints/Query/DatasourceDelete.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setDatasourceName($datasource_name): static { - if (isset($datasource_name) !== true) { + if (is_null($datasource_name)) { return $this; } $this->datasource_name = $datasource_name; diff --git a/src/OpenSearch/Endpoints/Query/DatasourceRetrieve.php b/src/OpenSearch/Endpoints/Query/DatasourceRetrieve.php index e0472558..f7f54fb0 100644 --- a/src/OpenSearch/Endpoints/Query/DatasourceRetrieve.php +++ b/src/OpenSearch/Endpoints/Query/DatasourceRetrieve.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setDatasourceName($datasource_name): static { - if (isset($datasource_name) !== true) { + if (is_null($datasource_name)) { return $this; } $this->datasource_name = $datasource_name; diff --git a/src/OpenSearch/Endpoints/Query/DatasourcesCreate.php b/src/OpenSearch/Endpoints/Query/DatasourcesCreate.php index 9f1c2d4e..ba2d457a 100644 --- a/src/OpenSearch/Endpoints/Query/DatasourcesCreate.php +++ b/src/OpenSearch/Endpoints/Query/DatasourcesCreate.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Query/DatasourcesUpdate.php b/src/OpenSearch/Endpoints/Query/DatasourcesUpdate.php index 6836d726..92905dab 100644 --- a/src/OpenSearch/Endpoints/Query/DatasourcesUpdate.php +++ b/src/OpenSearch/Endpoints/Query/DatasourcesUpdate.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/RankEval.php b/src/OpenSearch/Endpoints/RankEval.php index 4b1b23de..cb794bc6 100644 --- a/src/OpenSearch/Endpoints/RankEval.php +++ b/src/OpenSearch/Endpoints/RankEval.php @@ -59,7 +59,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Reindex.php b/src/OpenSearch/Endpoints/Reindex.php index 85b19007..c65560a6 100644 --- a/src/OpenSearch/Endpoints/Reindex.php +++ b/src/OpenSearch/Endpoints/Reindex.php @@ -59,7 +59,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/ReindexRethrottle.php b/src/OpenSearch/Endpoints/ReindexRethrottle.php index fbbdb529..254c969e 100644 --- a/src/OpenSearch/Endpoints/ReindexRethrottle.php +++ b/src/OpenSearch/Endpoints/ReindexRethrottle.php @@ -33,12 +33,11 @@ class ReindexRethrottle extends AbstractEndpoint public function getURI(): string { - if (isset($this->task_id) !== true) { - throw new RuntimeException( - 'task_id is required for reindex_rethrottle' - ); + if (!isset($this->task_id) || $this->task_id === '') { + throw new RuntimeException('task_id is required for reindex_rethrottle'); } $task_id = $this->task_id; + return "/_reindex/$task_id/_rethrottle"; } @@ -61,7 +60,7 @@ public function getMethod(): string public function setTaskId($task_id): static { - if (isset($task_id) !== true) { + if (is_null($task_id)) { return $this; } $this->task_id = $task_id; diff --git a/src/OpenSearch/Endpoints/RemoteStore/Restore.php b/src/OpenSearch/Endpoints/RemoteStore/Restore.php index fb4c6c41..36c240ce 100644 --- a/src/OpenSearch/Endpoints/RemoteStore/Restore.php +++ b/src/OpenSearch/Endpoints/RemoteStore/Restore.php @@ -47,7 +47,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/RenderSearchTemplate.php b/src/OpenSearch/Endpoints/RenderSearchTemplate.php index 48e32042..8a7a83ab 100644 --- a/src/OpenSearch/Endpoints/RenderSearchTemplate.php +++ b/src/OpenSearch/Endpoints/RenderSearchTemplate.php @@ -55,7 +55,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Replication/CreateReplicationRule.php b/src/OpenSearch/Endpoints/Replication/CreateReplicationRule.php index 01c2c100..5048dce0 100644 --- a/src/OpenSearch/Endpoints/Replication/CreateReplicationRule.php +++ b/src/OpenSearch/Endpoints/Replication/CreateReplicationRule.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Replication/DeleteReplicationRule.php b/src/OpenSearch/Endpoints/Replication/DeleteReplicationRule.php index 5a0715af..29f25078 100644 --- a/src/OpenSearch/Endpoints/Replication/DeleteReplicationRule.php +++ b/src/OpenSearch/Endpoints/Replication/DeleteReplicationRule.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Replication/Pause.php b/src/OpenSearch/Endpoints/Replication/Pause.php index b31b960d..eb3cc8ad 100644 --- a/src/OpenSearch/Endpoints/Replication/Pause.php +++ b/src/OpenSearch/Endpoints/Replication/Pause.php @@ -50,7 +50,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Replication/Resume.php b/src/OpenSearch/Endpoints/Replication/Resume.php index b8642f56..b3a724c3 100644 --- a/src/OpenSearch/Endpoints/Replication/Resume.php +++ b/src/OpenSearch/Endpoints/Replication/Resume.php @@ -50,7 +50,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Replication/Start.php b/src/OpenSearch/Endpoints/Replication/Start.php index d82c9294..1a08c701 100644 --- a/src/OpenSearch/Endpoints/Replication/Start.php +++ b/src/OpenSearch/Endpoints/Replication/Start.php @@ -50,7 +50,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Replication/Stop.php b/src/OpenSearch/Endpoints/Replication/Stop.php index 5e61624b..6a2790ca 100644 --- a/src/OpenSearch/Endpoints/Replication/Stop.php +++ b/src/OpenSearch/Endpoints/Replication/Stop.php @@ -50,7 +50,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Replication/UpdateSettings.php b/src/OpenSearch/Endpoints/Replication/UpdateSettings.php index 202e80d6..19fea21c 100644 --- a/src/OpenSearch/Endpoints/Replication/UpdateSettings.php +++ b/src/OpenSearch/Endpoints/Replication/UpdateSettings.php @@ -50,7 +50,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Rollups/Delete.php b/src/OpenSearch/Endpoints/Rollups/Delete.php index 1e439bd6..71a7376d 100644 --- a/src/OpenSearch/Endpoints/Rollups/Delete.php +++ b/src/OpenSearch/Endpoints/Rollups/Delete.php @@ -25,12 +25,11 @@ class Delete extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for delete' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for delete'); } $id = $this->id; + return "/_plugins/_rollup/jobs/$id"; } diff --git a/src/OpenSearch/Endpoints/Rollups/Explain.php b/src/OpenSearch/Endpoints/Rollups/Explain.php index f3b4e567..f2fd2645 100644 --- a/src/OpenSearch/Endpoints/Rollups/Explain.php +++ b/src/OpenSearch/Endpoints/Rollups/Explain.php @@ -25,12 +25,11 @@ class Explain extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for explain' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for explain'); } $id = $this->id; + return "/_plugins/_rollup/jobs/$id/_explain"; } diff --git a/src/OpenSearch/Endpoints/Rollups/Get.php b/src/OpenSearch/Endpoints/Rollups/Get.php index ecdf22b5..ef59af63 100644 --- a/src/OpenSearch/Endpoints/Rollups/Get.php +++ b/src/OpenSearch/Endpoints/Rollups/Get.php @@ -25,12 +25,11 @@ class Get extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for get' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for get'); } $id = $this->id; + return "/_plugins/_rollup/jobs/$id"; } diff --git a/src/OpenSearch/Endpoints/Rollups/Put.php b/src/OpenSearch/Endpoints/Rollups/Put.php index dc8ec845..66f55544 100644 --- a/src/OpenSearch/Endpoints/Rollups/Put.php +++ b/src/OpenSearch/Endpoints/Rollups/Put.php @@ -25,12 +25,11 @@ class Put extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for put' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for put'); } $id = $this->id; + return "/_plugins/_rollup/jobs/$id"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Rollups/Start.php b/src/OpenSearch/Endpoints/Rollups/Start.php index cd10a70c..5ab74504 100644 --- a/src/OpenSearch/Endpoints/Rollups/Start.php +++ b/src/OpenSearch/Endpoints/Rollups/Start.php @@ -25,12 +25,11 @@ class Start extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for start' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for start'); } $id = $this->id; + return "/_plugins/_rollup/jobs/$id/_start"; } diff --git a/src/OpenSearch/Endpoints/Rollups/Stop.php b/src/OpenSearch/Endpoints/Rollups/Stop.php index cce54a0c..898a2613 100644 --- a/src/OpenSearch/Endpoints/Rollups/Stop.php +++ b/src/OpenSearch/Endpoints/Rollups/Stop.php @@ -25,12 +25,11 @@ class Stop extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for stop' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for stop'); } $id = $this->id; + return "/_plugins/_rollup/jobs/$id/_stop"; } diff --git a/src/OpenSearch/Endpoints/ScriptsPainlessExecute.php b/src/OpenSearch/Endpoints/ScriptsPainlessExecute.php index 1e3ecef2..d7b27ec8 100644 --- a/src/OpenSearch/Endpoints/ScriptsPainlessExecute.php +++ b/src/OpenSearch/Endpoints/ScriptsPainlessExecute.php @@ -51,7 +51,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Scroll.php b/src/OpenSearch/Endpoints/Scroll.php index f4042d83..b2c9ea7b 100644 --- a/src/OpenSearch/Endpoints/Scroll.php +++ b/src/OpenSearch/Endpoints/Scroll.php @@ -64,7 +64,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -74,7 +74,7 @@ public function setBody($body): static public function setScrollId($scroll_id): static { - if (isset($scroll_id) !== true) { + if (is_null($scroll_id)) { return $this; } $this->scroll_id = $scroll_id; diff --git a/src/OpenSearch/Endpoints/Search.php b/src/OpenSearch/Endpoints/Search.php index 8380e3f5..8e0e2ba1 100644 --- a/src/OpenSearch/Endpoints/Search.php +++ b/src/OpenSearch/Endpoints/Search.php @@ -101,7 +101,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/SearchPipeline/Put.php b/src/OpenSearch/Endpoints/SearchPipeline/Put.php index dc0332a5..c73b3b95 100644 --- a/src/OpenSearch/Endpoints/SearchPipeline/Put.php +++ b/src/OpenSearch/Endpoints/SearchPipeline/Put.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/SearchShards.php b/src/OpenSearch/Endpoints/SearchShards.php index 86fecc60..f777c44c 100644 --- a/src/OpenSearch/Endpoints/SearchShards.php +++ b/src/OpenSearch/Endpoints/SearchShards.php @@ -61,7 +61,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/SearchTemplate.php b/src/OpenSearch/Endpoints/SearchTemplate.php index e5236916..d23b0a55 100644 --- a/src/OpenSearch/Endpoints/SearchTemplate.php +++ b/src/OpenSearch/Endpoints/SearchTemplate.php @@ -68,7 +68,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/ChangePassword.php b/src/OpenSearch/Endpoints/Security/ChangePassword.php index 494921f5..562a1754 100644 --- a/src/OpenSearch/Endpoints/Security/ChangePassword.php +++ b/src/OpenSearch/Endpoints/Security/ChangePassword.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/ConfigUpgradePerform.php b/src/OpenSearch/Endpoints/Security/ConfigUpgradePerform.php index cc68e11f..d7e1b53a 100644 --- a/src/OpenSearch/Endpoints/Security/ConfigUpgradePerform.php +++ b/src/OpenSearch/Endpoints/Security/ConfigUpgradePerform.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/CreateActionGroup.php b/src/OpenSearch/Endpoints/Security/CreateActionGroup.php index dfb844c0..7d37ef76 100644 --- a/src/OpenSearch/Endpoints/Security/CreateActionGroup.php +++ b/src/OpenSearch/Endpoints/Security/CreateActionGroup.php @@ -27,12 +27,11 @@ class CreateActionGroup extends AbstractEndpoint public function getURI(): string { - if (isset($this->action_group) !== true) { - throw new RuntimeException( - 'action_group is required for create_action_group' - ); + if (!isset($this->action_group) || $this->action_group === '') { + throw new RuntimeException('action_group is required for create_action_group'); } $action_group = $this->action_group; + return "/_plugins/_security/api/actiongroups/$action_group"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -64,7 +63,7 @@ public function setBody($body): static public function setActionGroup($action_group): static { - if (isset($action_group) !== true) { + if (is_null($action_group)) { return $this; } $this->action_group = $action_group; diff --git a/src/OpenSearch/Endpoints/Security/CreateAllowlist.php b/src/OpenSearch/Endpoints/Security/CreateAllowlist.php index 1cccd618..c938f126 100644 --- a/src/OpenSearch/Endpoints/Security/CreateAllowlist.php +++ b/src/OpenSearch/Endpoints/Security/CreateAllowlist.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/CreateRole.php b/src/OpenSearch/Endpoints/Security/CreateRole.php index 5bf8a7b5..0887b6c5 100644 --- a/src/OpenSearch/Endpoints/Security/CreateRole.php +++ b/src/OpenSearch/Endpoints/Security/CreateRole.php @@ -27,12 +27,11 @@ class CreateRole extends AbstractEndpoint public function getURI(): string { - if (isset($this->role) !== true) { - throw new RuntimeException( - 'role is required for create_role' - ); + if (!isset($this->role) || $this->role === '') { + throw new RuntimeException('role is required for create_role'); } $role = $this->role; + return "/_plugins/_security/api/roles/$role"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -64,7 +63,7 @@ public function setBody($body): static public function setRole($role): static { - if (isset($role) !== true) { + if (is_null($role)) { return $this; } $this->role = $role; diff --git a/src/OpenSearch/Endpoints/Security/CreateRoleMapping.php b/src/OpenSearch/Endpoints/Security/CreateRoleMapping.php index 7acbb792..7977caad 100644 --- a/src/OpenSearch/Endpoints/Security/CreateRoleMapping.php +++ b/src/OpenSearch/Endpoints/Security/CreateRoleMapping.php @@ -27,12 +27,11 @@ class CreateRoleMapping extends AbstractEndpoint public function getURI(): string { - if (isset($this->role) !== true) { - throw new RuntimeException( - 'role is required for create_role_mapping' - ); + if (!isset($this->role) || $this->role === '') { + throw new RuntimeException('role is required for create_role_mapping'); } $role = $this->role; + return "/_plugins/_security/api/rolesmapping/$role"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -64,7 +63,7 @@ public function setBody($body): static public function setRole($role): static { - if (isset($role) !== true) { + if (is_null($role)) { return $this; } $this->role = $role; diff --git a/src/OpenSearch/Endpoints/Security/CreateTenant.php b/src/OpenSearch/Endpoints/Security/CreateTenant.php index 5463d44d..a0a4db10 100644 --- a/src/OpenSearch/Endpoints/Security/CreateTenant.php +++ b/src/OpenSearch/Endpoints/Security/CreateTenant.php @@ -27,12 +27,11 @@ class CreateTenant extends AbstractEndpoint public function getURI(): string { - if (isset($this->tenant) !== true) { - throw new RuntimeException( - 'tenant is required for create_tenant' - ); + if (!isset($this->tenant) || $this->tenant === '') { + throw new RuntimeException('tenant is required for create_tenant'); } $tenant = $this->tenant; + return "/_plugins/_security/api/tenants/$tenant"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -64,7 +63,7 @@ public function setBody($body): static public function setTenant($tenant): static { - if (isset($tenant) !== true) { + if (is_null($tenant)) { return $this; } $this->tenant = $tenant; diff --git a/src/OpenSearch/Endpoints/Security/CreateUpdateTenancyConfig.php b/src/OpenSearch/Endpoints/Security/CreateUpdateTenancyConfig.php index 15574d10..7989d2b0 100644 --- a/src/OpenSearch/Endpoints/Security/CreateUpdateTenancyConfig.php +++ b/src/OpenSearch/Endpoints/Security/CreateUpdateTenancyConfig.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/CreateUser.php b/src/OpenSearch/Endpoints/Security/CreateUser.php index a4367738..0dff995e 100644 --- a/src/OpenSearch/Endpoints/Security/CreateUser.php +++ b/src/OpenSearch/Endpoints/Security/CreateUser.php @@ -27,12 +27,11 @@ class CreateUser extends AbstractEndpoint public function getURI(): string { - if (isset($this->username) !== true) { - throw new RuntimeException( - 'username is required for create_user' - ); + if (!isset($this->username) || $this->username === '') { + throw new RuntimeException('username is required for create_user'); } $username = $this->username; + return "/_plugins/_security/api/internalusers/$username"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -64,7 +63,7 @@ public function setBody($body): static public function setUsername($username): static { - if (isset($username) !== true) { + if (is_null($username)) { return $this; } $this->username = $username; diff --git a/src/OpenSearch/Endpoints/Security/CreateUserLegacy.php b/src/OpenSearch/Endpoints/Security/CreateUserLegacy.php index 4e2bd51f..a675e8bf 100644 --- a/src/OpenSearch/Endpoints/Security/CreateUserLegacy.php +++ b/src/OpenSearch/Endpoints/Security/CreateUserLegacy.php @@ -27,12 +27,11 @@ class CreateUserLegacy extends AbstractEndpoint public function getURI(): string { - if (isset($this->username) !== true) { - throw new RuntimeException( - 'username is required for create_user_legacy' - ); + if (!isset($this->username) || $this->username === '') { + throw new RuntimeException('username is required for create_user_legacy'); } $username = $this->username; + return "/_plugins/_security/api/user/$username"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -64,7 +63,7 @@ public function setBody($body): static public function setUsername($username): static { - if (isset($username) !== true) { + if (is_null($username)) { return $this; } $this->username = $username; diff --git a/src/OpenSearch/Endpoints/Security/DeleteActionGroup.php b/src/OpenSearch/Endpoints/Security/DeleteActionGroup.php index 9645e761..1e70edaa 100644 --- a/src/OpenSearch/Endpoints/Security/DeleteActionGroup.php +++ b/src/OpenSearch/Endpoints/Security/DeleteActionGroup.php @@ -27,12 +27,11 @@ class DeleteActionGroup extends AbstractEndpoint public function getURI(): string { - if (isset($this->action_group) !== true) { - throw new RuntimeException( - 'action_group is required for delete_action_group' - ); + if (!isset($this->action_group) || $this->action_group === '') { + throw new RuntimeException('action_group is required for delete_action_group'); } $action_group = $this->action_group; + return "/_plugins/_security/api/actiongroups/$action_group"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setActionGroup($action_group): static { - if (isset($action_group) !== true) { + if (is_null($action_group)) { return $this; } $this->action_group = $action_group; diff --git a/src/OpenSearch/Endpoints/Security/DeleteDistinguishedName.php b/src/OpenSearch/Endpoints/Security/DeleteDistinguishedName.php index f80c7e9c..430c2424 100644 --- a/src/OpenSearch/Endpoints/Security/DeleteDistinguishedName.php +++ b/src/OpenSearch/Endpoints/Security/DeleteDistinguishedName.php @@ -27,12 +27,11 @@ class DeleteDistinguishedName extends AbstractEndpoint public function getURI(): string { - if (isset($this->cluster_name) !== true) { - throw new RuntimeException( - 'cluster_name is required for delete_distinguished_name' - ); + if (!isset($this->cluster_name) || $this->cluster_name === '') { + throw new RuntimeException('cluster_name is required for delete_distinguished_name'); } $cluster_name = $this->cluster_name; + return "/_plugins/_security/api/nodesdn/$cluster_name"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setClusterName($cluster_name): static { - if (isset($cluster_name) !== true) { + if (is_null($cluster_name)) { return $this; } $this->cluster_name = $cluster_name; diff --git a/src/OpenSearch/Endpoints/Security/DeleteRole.php b/src/OpenSearch/Endpoints/Security/DeleteRole.php index aa906d66..86c97893 100644 --- a/src/OpenSearch/Endpoints/Security/DeleteRole.php +++ b/src/OpenSearch/Endpoints/Security/DeleteRole.php @@ -27,12 +27,11 @@ class DeleteRole extends AbstractEndpoint public function getURI(): string { - if (isset($this->role) !== true) { - throw new RuntimeException( - 'role is required for delete_role' - ); + if (!isset($this->role) || $this->role === '') { + throw new RuntimeException('role is required for delete_role'); } $role = $this->role; + return "/_plugins/_security/api/roles/$role"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setRole($role): static { - if (isset($role) !== true) { + if (is_null($role)) { return $this; } $this->role = $role; diff --git a/src/OpenSearch/Endpoints/Security/DeleteRoleMapping.php b/src/OpenSearch/Endpoints/Security/DeleteRoleMapping.php index 67b6d54a..724c1eca 100644 --- a/src/OpenSearch/Endpoints/Security/DeleteRoleMapping.php +++ b/src/OpenSearch/Endpoints/Security/DeleteRoleMapping.php @@ -27,12 +27,11 @@ class DeleteRoleMapping extends AbstractEndpoint public function getURI(): string { - if (isset($this->role) !== true) { - throw new RuntimeException( - 'role is required for delete_role_mapping' - ); + if (!isset($this->role) || $this->role === '') { + throw new RuntimeException('role is required for delete_role_mapping'); } $role = $this->role; + return "/_plugins/_security/api/rolesmapping/$role"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setRole($role): static { - if (isset($role) !== true) { + if (is_null($role)) { return $this; } $this->role = $role; diff --git a/src/OpenSearch/Endpoints/Security/DeleteTenant.php b/src/OpenSearch/Endpoints/Security/DeleteTenant.php index d2e4d89e..ae1d5e80 100644 --- a/src/OpenSearch/Endpoints/Security/DeleteTenant.php +++ b/src/OpenSearch/Endpoints/Security/DeleteTenant.php @@ -27,12 +27,11 @@ class DeleteTenant extends AbstractEndpoint public function getURI(): string { - if (isset($this->tenant) !== true) { - throw new RuntimeException( - 'tenant is required for delete_tenant' - ); + if (!isset($this->tenant) || $this->tenant === '') { + throw new RuntimeException('tenant is required for delete_tenant'); } $tenant = $this->tenant; + return "/_plugins/_security/api/tenants/$tenant"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setTenant($tenant): static { - if (isset($tenant) !== true) { + if (is_null($tenant)) { return $this; } $this->tenant = $tenant; diff --git a/src/OpenSearch/Endpoints/Security/DeleteUser.php b/src/OpenSearch/Endpoints/Security/DeleteUser.php index 10c3b593..9fb9c60f 100644 --- a/src/OpenSearch/Endpoints/Security/DeleteUser.php +++ b/src/OpenSearch/Endpoints/Security/DeleteUser.php @@ -27,12 +27,11 @@ class DeleteUser extends AbstractEndpoint public function getURI(): string { - if (isset($this->username) !== true) { - throw new RuntimeException( - 'username is required for delete_user' - ); + if (!isset($this->username) || $this->username === '') { + throw new RuntimeException('username is required for delete_user'); } $username = $this->username; + return "/_plugins/_security/api/internalusers/$username"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setUsername($username): static { - if (isset($username) !== true) { + if (is_null($username)) { return $this; } $this->username = $username; diff --git a/src/OpenSearch/Endpoints/Security/DeleteUserLegacy.php b/src/OpenSearch/Endpoints/Security/DeleteUserLegacy.php index cdaf7315..acb0efb5 100644 --- a/src/OpenSearch/Endpoints/Security/DeleteUserLegacy.php +++ b/src/OpenSearch/Endpoints/Security/DeleteUserLegacy.php @@ -27,12 +27,11 @@ class DeleteUserLegacy extends AbstractEndpoint public function getURI(): string { - if (isset($this->username) !== true) { - throw new RuntimeException( - 'username is required for delete_user_legacy' - ); + if (!isset($this->username) || $this->username === '') { + throw new RuntimeException('username is required for delete_user_legacy'); } $username = $this->username; + return "/_plugins/_security/api/user/$username"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setUsername($username): static { - if (isset($username) !== true) { + if (is_null($username)) { return $this; } $this->username = $username; diff --git a/src/OpenSearch/Endpoints/Security/GenerateOboToken.php b/src/OpenSearch/Endpoints/Security/GenerateOboToken.php index 503d3021..187ca285 100644 --- a/src/OpenSearch/Endpoints/Security/GenerateOboToken.php +++ b/src/OpenSearch/Endpoints/Security/GenerateOboToken.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/GenerateUserToken.php b/src/OpenSearch/Endpoints/Security/GenerateUserToken.php index 16d21456..34d83ecd 100644 --- a/src/OpenSearch/Endpoints/Security/GenerateUserToken.php +++ b/src/OpenSearch/Endpoints/Security/GenerateUserToken.php @@ -27,12 +27,11 @@ class GenerateUserToken extends AbstractEndpoint public function getURI(): string { - if (isset($this->username) !== true) { - throw new RuntimeException( - 'username is required for generate_user_token' - ); + if (!isset($this->username) || $this->username === '') { + throw new RuntimeException('username is required for generate_user_token'); } $username = $this->username; + return "/_plugins/_security/api/internalusers/$username/authtoken"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setUsername($username): static { - if (isset($username) !== true) { + if (is_null($username)) { return $this; } $this->username = $username; diff --git a/src/OpenSearch/Endpoints/Security/GenerateUserTokenLegacy.php b/src/OpenSearch/Endpoints/Security/GenerateUserTokenLegacy.php index 4ebdfecd..3bae4f2e 100644 --- a/src/OpenSearch/Endpoints/Security/GenerateUserTokenLegacy.php +++ b/src/OpenSearch/Endpoints/Security/GenerateUserTokenLegacy.php @@ -27,12 +27,11 @@ class GenerateUserTokenLegacy extends AbstractEndpoint public function getURI(): string { - if (isset($this->username) !== true) { - throw new RuntimeException( - 'username is required for generate_user_token_legacy' - ); + if (!isset($this->username) || $this->username === '') { + throw new RuntimeException('username is required for generate_user_token_legacy'); } $username = $this->username; + return "/_plugins/_security/api/user/$username/authtoken"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setUsername($username): static { - if (isset($username) !== true) { + if (is_null($username)) { return $this; } $this->username = $username; diff --git a/src/OpenSearch/Endpoints/Security/GetActionGroup.php b/src/OpenSearch/Endpoints/Security/GetActionGroup.php index c0c51c54..985f5fcd 100644 --- a/src/OpenSearch/Endpoints/Security/GetActionGroup.php +++ b/src/OpenSearch/Endpoints/Security/GetActionGroup.php @@ -27,12 +27,11 @@ class GetActionGroup extends AbstractEndpoint public function getURI(): string { - if (isset($this->action_group) !== true) { - throw new RuntimeException( - 'action_group is required for get_action_group' - ); + if (!isset($this->action_group) || $this->action_group === '') { + throw new RuntimeException('action_group is required for get_action_group'); } $action_group = $this->action_group; + return "/_plugins/_security/api/actiongroups/$action_group"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setActionGroup($action_group): static { - if (isset($action_group) !== true) { + if (is_null($action_group)) { return $this; } $this->action_group = $action_group; diff --git a/src/OpenSearch/Endpoints/Security/GetDistinguishedName.php b/src/OpenSearch/Endpoints/Security/GetDistinguishedName.php index e7dd3ee0..0aa1fffe 100644 --- a/src/OpenSearch/Endpoints/Security/GetDistinguishedName.php +++ b/src/OpenSearch/Endpoints/Security/GetDistinguishedName.php @@ -27,12 +27,11 @@ class GetDistinguishedName extends AbstractEndpoint public function getURI(): string { - if (isset($this->cluster_name) !== true) { - throw new RuntimeException( - 'cluster_name is required for get_distinguished_name' - ); + if (!isset($this->cluster_name) || $this->cluster_name === '') { + throw new RuntimeException('cluster_name is required for get_distinguished_name'); } $cluster_name = $this->cluster_name; + return "/_plugins/_security/api/nodesdn/$cluster_name"; } @@ -55,7 +54,7 @@ public function getMethod(): string public function setClusterName($cluster_name): static { - if (isset($cluster_name) !== true) { + if (is_null($cluster_name)) { return $this; } $this->cluster_name = $cluster_name; diff --git a/src/OpenSearch/Endpoints/Security/GetNodeCertificates.php b/src/OpenSearch/Endpoints/Security/GetNodeCertificates.php index a0013349..2a22e2f8 100644 --- a/src/OpenSearch/Endpoints/Security/GetNodeCertificates.php +++ b/src/OpenSearch/Endpoints/Security/GetNodeCertificates.php @@ -54,7 +54,7 @@ public function getMethod(): string public function setNodeId($node_id): static { - if (isset($node_id) !== true) { + if (is_null($node_id)) { return $this; } $this->node_id = $node_id; diff --git a/src/OpenSearch/Endpoints/Security/GetRole.php b/src/OpenSearch/Endpoints/Security/GetRole.php index de9dfc71..ecb6f2f1 100644 --- a/src/OpenSearch/Endpoints/Security/GetRole.php +++ b/src/OpenSearch/Endpoints/Security/GetRole.php @@ -27,12 +27,11 @@ class GetRole extends AbstractEndpoint public function getURI(): string { - if (isset($this->role) !== true) { - throw new RuntimeException( - 'role is required for get_role' - ); + if (!isset($this->role) || $this->role === '') { + throw new RuntimeException('role is required for get_role'); } $role = $this->role; + return "/_plugins/_security/api/roles/$role"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setRole($role): static { - if (isset($role) !== true) { + if (is_null($role)) { return $this; } $this->role = $role; diff --git a/src/OpenSearch/Endpoints/Security/GetRoleMapping.php b/src/OpenSearch/Endpoints/Security/GetRoleMapping.php index b58d74ec..b460510a 100644 --- a/src/OpenSearch/Endpoints/Security/GetRoleMapping.php +++ b/src/OpenSearch/Endpoints/Security/GetRoleMapping.php @@ -27,12 +27,11 @@ class GetRoleMapping extends AbstractEndpoint public function getURI(): string { - if (isset($this->role) !== true) { - throw new RuntimeException( - 'role is required for get_role_mapping' - ); + if (!isset($this->role) || $this->role === '') { + throw new RuntimeException('role is required for get_role_mapping'); } $role = $this->role; + return "/_plugins/_security/api/rolesmapping/$role"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setRole($role): static { - if (isset($role) !== true) { + if (is_null($role)) { return $this; } $this->role = $role; diff --git a/src/OpenSearch/Endpoints/Security/GetTenant.php b/src/OpenSearch/Endpoints/Security/GetTenant.php index dcfd3c00..abe420a0 100644 --- a/src/OpenSearch/Endpoints/Security/GetTenant.php +++ b/src/OpenSearch/Endpoints/Security/GetTenant.php @@ -27,12 +27,11 @@ class GetTenant extends AbstractEndpoint public function getURI(): string { - if (isset($this->tenant) !== true) { - throw new RuntimeException( - 'tenant is required for get_tenant' - ); + if (!isset($this->tenant) || $this->tenant === '') { + throw new RuntimeException('tenant is required for get_tenant'); } $tenant = $this->tenant; + return "/_plugins/_security/api/tenants/$tenant"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setTenant($tenant): static { - if (isset($tenant) !== true) { + if (is_null($tenant)) { return $this; } $this->tenant = $tenant; diff --git a/src/OpenSearch/Endpoints/Security/GetUser.php b/src/OpenSearch/Endpoints/Security/GetUser.php index ec67393a..ac5d13cf 100644 --- a/src/OpenSearch/Endpoints/Security/GetUser.php +++ b/src/OpenSearch/Endpoints/Security/GetUser.php @@ -27,12 +27,11 @@ class GetUser extends AbstractEndpoint public function getURI(): string { - if (isset($this->username) !== true) { - throw new RuntimeException( - 'username is required for get_user' - ); + if (!isset($this->username) || $this->username === '') { + throw new RuntimeException('username is required for get_user'); } $username = $this->username; + return "/_plugins/_security/api/internalusers/$username"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setUsername($username): static { - if (isset($username) !== true) { + if (is_null($username)) { return $this; } $this->username = $username; diff --git a/src/OpenSearch/Endpoints/Security/GetUserLegacy.php b/src/OpenSearch/Endpoints/Security/GetUserLegacy.php index f58bdf4d..0db4e6be 100644 --- a/src/OpenSearch/Endpoints/Security/GetUserLegacy.php +++ b/src/OpenSearch/Endpoints/Security/GetUserLegacy.php @@ -27,12 +27,11 @@ class GetUserLegacy extends AbstractEndpoint public function getURI(): string { - if (isset($this->username) !== true) { - throw new RuntimeException( - 'username is required for get_user_legacy' - ); + if (!isset($this->username) || $this->username === '') { + throw new RuntimeException('username is required for get_user_legacy'); } $username = $this->username; + return "/_plugins/_security/api/user/$username"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setUsername($username): static { - if (isset($username) !== true) { + if (is_null($username)) { return $this; } $this->username = $username; diff --git a/src/OpenSearch/Endpoints/Security/PatchActionGroup.php b/src/OpenSearch/Endpoints/Security/PatchActionGroup.php index 35e737aa..36474939 100644 --- a/src/OpenSearch/Endpoints/Security/PatchActionGroup.php +++ b/src/OpenSearch/Endpoints/Security/PatchActionGroup.php @@ -27,12 +27,11 @@ class PatchActionGroup extends AbstractEndpoint public function getURI(): string { - if (isset($this->action_group) !== true) { - throw new RuntimeException( - 'action_group is required for patch_action_group' - ); + if (!isset($this->action_group) || $this->action_group === '') { + throw new RuntimeException('action_group is required for patch_action_group'); } $action_group = $this->action_group; + return "/_plugins/_security/api/actiongroups/$action_group"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -64,7 +63,7 @@ public function setBody($body): static public function setActionGroup($action_group): static { - if (isset($action_group) !== true) { + if (is_null($action_group)) { return $this; } $this->action_group = $action_group; diff --git a/src/OpenSearch/Endpoints/Security/PatchActionGroups.php b/src/OpenSearch/Endpoints/Security/PatchActionGroups.php index 53e84258..6bdd042e 100644 --- a/src/OpenSearch/Endpoints/Security/PatchActionGroups.php +++ b/src/OpenSearch/Endpoints/Security/PatchActionGroups.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/PatchAllowlist.php b/src/OpenSearch/Endpoints/Security/PatchAllowlist.php index bbd76c6f..0499abac 100644 --- a/src/OpenSearch/Endpoints/Security/PatchAllowlist.php +++ b/src/OpenSearch/Endpoints/Security/PatchAllowlist.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/PatchAuditConfiguration.php b/src/OpenSearch/Endpoints/Security/PatchAuditConfiguration.php index 3bcd2b91..804ca281 100644 --- a/src/OpenSearch/Endpoints/Security/PatchAuditConfiguration.php +++ b/src/OpenSearch/Endpoints/Security/PatchAuditConfiguration.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/PatchConfiguration.php b/src/OpenSearch/Endpoints/Security/PatchConfiguration.php index 7fb935e2..48c38cc5 100644 --- a/src/OpenSearch/Endpoints/Security/PatchConfiguration.php +++ b/src/OpenSearch/Endpoints/Security/PatchConfiguration.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/PatchDistinguishedName.php b/src/OpenSearch/Endpoints/Security/PatchDistinguishedName.php index 419d22cb..062f174d 100644 --- a/src/OpenSearch/Endpoints/Security/PatchDistinguishedName.php +++ b/src/OpenSearch/Endpoints/Security/PatchDistinguishedName.php @@ -27,12 +27,11 @@ class PatchDistinguishedName extends AbstractEndpoint public function getURI(): string { - if (isset($this->cluster_name) !== true) { - throw new RuntimeException( - 'cluster_name is required for patch_distinguished_name' - ); + if (!isset($this->cluster_name) || $this->cluster_name === '') { + throw new RuntimeException('cluster_name is required for patch_distinguished_name'); } $cluster_name = $this->cluster_name; + return "/_plugins/_security/api/nodesdn/$cluster_name"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -64,7 +63,7 @@ public function setBody($body): static public function setClusterName($cluster_name): static { - if (isset($cluster_name) !== true) { + if (is_null($cluster_name)) { return $this; } $this->cluster_name = $cluster_name; diff --git a/src/OpenSearch/Endpoints/Security/PatchDistinguishedNames.php b/src/OpenSearch/Endpoints/Security/PatchDistinguishedNames.php index 280dd322..3f4de031 100644 --- a/src/OpenSearch/Endpoints/Security/PatchDistinguishedNames.php +++ b/src/OpenSearch/Endpoints/Security/PatchDistinguishedNames.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/PatchRole.php b/src/OpenSearch/Endpoints/Security/PatchRole.php index 432817e7..ceda2f2a 100644 --- a/src/OpenSearch/Endpoints/Security/PatchRole.php +++ b/src/OpenSearch/Endpoints/Security/PatchRole.php @@ -27,12 +27,11 @@ class PatchRole extends AbstractEndpoint public function getURI(): string { - if (isset($this->role) !== true) { - throw new RuntimeException( - 'role is required for patch_role' - ); + if (!isset($this->role) || $this->role === '') { + throw new RuntimeException('role is required for patch_role'); } $role = $this->role; + return "/_plugins/_security/api/roles/$role"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -64,7 +63,7 @@ public function setBody($body): static public function setRole($role): static { - if (isset($role) !== true) { + if (is_null($role)) { return $this; } $this->role = $role; diff --git a/src/OpenSearch/Endpoints/Security/PatchRoleMapping.php b/src/OpenSearch/Endpoints/Security/PatchRoleMapping.php index b593f2bc..e5727b30 100644 --- a/src/OpenSearch/Endpoints/Security/PatchRoleMapping.php +++ b/src/OpenSearch/Endpoints/Security/PatchRoleMapping.php @@ -27,12 +27,11 @@ class PatchRoleMapping extends AbstractEndpoint public function getURI(): string { - if (isset($this->role) !== true) { - throw new RuntimeException( - 'role is required for patch_role_mapping' - ); + if (!isset($this->role) || $this->role === '') { + throw new RuntimeException('role is required for patch_role_mapping'); } $role = $this->role; + return "/_plugins/_security/api/rolesmapping/$role"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -64,7 +63,7 @@ public function setBody($body): static public function setRole($role): static { - if (isset($role) !== true) { + if (is_null($role)) { return $this; } $this->role = $role; diff --git a/src/OpenSearch/Endpoints/Security/PatchRoleMappings.php b/src/OpenSearch/Endpoints/Security/PatchRoleMappings.php index 29ef48b5..33efe6c7 100644 --- a/src/OpenSearch/Endpoints/Security/PatchRoleMappings.php +++ b/src/OpenSearch/Endpoints/Security/PatchRoleMappings.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/PatchRoles.php b/src/OpenSearch/Endpoints/Security/PatchRoles.php index cb1bb3b4..faedd90d 100644 --- a/src/OpenSearch/Endpoints/Security/PatchRoles.php +++ b/src/OpenSearch/Endpoints/Security/PatchRoles.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/PatchTenant.php b/src/OpenSearch/Endpoints/Security/PatchTenant.php index a3902d56..974e8b6d 100644 --- a/src/OpenSearch/Endpoints/Security/PatchTenant.php +++ b/src/OpenSearch/Endpoints/Security/PatchTenant.php @@ -27,12 +27,11 @@ class PatchTenant extends AbstractEndpoint public function getURI(): string { - if (isset($this->tenant) !== true) { - throw new RuntimeException( - 'tenant is required for patch_tenant' - ); + if (!isset($this->tenant) || $this->tenant === '') { + throw new RuntimeException('tenant is required for patch_tenant'); } $tenant = $this->tenant; + return "/_plugins/_security/api/tenants/$tenant"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -64,7 +63,7 @@ public function setBody($body): static public function setTenant($tenant): static { - if (isset($tenant) !== true) { + if (is_null($tenant)) { return $this; } $this->tenant = $tenant; diff --git a/src/OpenSearch/Endpoints/Security/PatchTenants.php b/src/OpenSearch/Endpoints/Security/PatchTenants.php index 1f6b71a8..05e931a5 100644 --- a/src/OpenSearch/Endpoints/Security/PatchTenants.php +++ b/src/OpenSearch/Endpoints/Security/PatchTenants.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/PatchUser.php b/src/OpenSearch/Endpoints/Security/PatchUser.php index b15e8471..4da62f44 100644 --- a/src/OpenSearch/Endpoints/Security/PatchUser.php +++ b/src/OpenSearch/Endpoints/Security/PatchUser.php @@ -27,12 +27,11 @@ class PatchUser extends AbstractEndpoint public function getURI(): string { - if (isset($this->username) !== true) { - throw new RuntimeException( - 'username is required for patch_user' - ); + if (!isset($this->username) || $this->username === '') { + throw new RuntimeException('username is required for patch_user'); } $username = $this->username; + return "/_plugins/_security/api/internalusers/$username"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -64,7 +63,7 @@ public function setBody($body): static public function setUsername($username): static { - if (isset($username) !== true) { + if (is_null($username)) { return $this; } $this->username = $username; diff --git a/src/OpenSearch/Endpoints/Security/PatchUsers.php b/src/OpenSearch/Endpoints/Security/PatchUsers.php index 8b61f658..6a5ba80f 100644 --- a/src/OpenSearch/Endpoints/Security/PatchUsers.php +++ b/src/OpenSearch/Endpoints/Security/PatchUsers.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/UpdateAuditConfiguration.php b/src/OpenSearch/Endpoints/Security/UpdateAuditConfiguration.php index c5e6824a..c75d1c4e 100644 --- a/src/OpenSearch/Endpoints/Security/UpdateAuditConfiguration.php +++ b/src/OpenSearch/Endpoints/Security/UpdateAuditConfiguration.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/UpdateConfiguration.php b/src/OpenSearch/Endpoints/Security/UpdateConfiguration.php index b0862fd1..9b5192d9 100644 --- a/src/OpenSearch/Endpoints/Security/UpdateConfiguration.php +++ b/src/OpenSearch/Endpoints/Security/UpdateConfiguration.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Security/UpdateDistinguishedName.php b/src/OpenSearch/Endpoints/Security/UpdateDistinguishedName.php index 25d8f138..7b56d2f8 100644 --- a/src/OpenSearch/Endpoints/Security/UpdateDistinguishedName.php +++ b/src/OpenSearch/Endpoints/Security/UpdateDistinguishedName.php @@ -27,12 +27,11 @@ class UpdateDistinguishedName extends AbstractEndpoint public function getURI(): string { - if (isset($this->cluster_name) !== true) { - throw new RuntimeException( - 'cluster_name is required for update_distinguished_name' - ); + if (!isset($this->cluster_name) || $this->cluster_name === '') { + throw new RuntimeException('cluster_name is required for update_distinguished_name'); } $cluster_name = $this->cluster_name; + return "/_plugins/_security/api/nodesdn/$cluster_name"; } @@ -54,7 +53,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -64,7 +63,7 @@ public function setBody($body): static public function setClusterName($cluster_name): static { - if (isset($cluster_name) !== true) { + if (is_null($cluster_name)) { return $this; } $this->cluster_name = $cluster_name; diff --git a/src/OpenSearch/Endpoints/Sm/CreatePolicy.php b/src/OpenSearch/Endpoints/Sm/CreatePolicy.php index 9d069d83..47125342 100644 --- a/src/OpenSearch/Endpoints/Sm/CreatePolicy.php +++ b/src/OpenSearch/Endpoints/Sm/CreatePolicy.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -62,7 +62,7 @@ public function setBody($body): static public function setPolicyName($policy_name): static { - if (isset($policy_name) !== true) { + if (is_null($policy_name)) { return $this; } $this->policy_name = $policy_name; diff --git a/src/OpenSearch/Endpoints/Sm/DeletePolicy.php b/src/OpenSearch/Endpoints/Sm/DeletePolicy.php index b342d8e3..83d3a338 100644 --- a/src/OpenSearch/Endpoints/Sm/DeletePolicy.php +++ b/src/OpenSearch/Endpoints/Sm/DeletePolicy.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setPolicyName($policy_name): static { - if (isset($policy_name) !== true) { + if (is_null($policy_name)) { return $this; } $this->policy_name = $policy_name; diff --git a/src/OpenSearch/Endpoints/Sm/ExplainPolicy.php b/src/OpenSearch/Endpoints/Sm/ExplainPolicy.php index 2396b3a7..d48b223b 100644 --- a/src/OpenSearch/Endpoints/Sm/ExplainPolicy.php +++ b/src/OpenSearch/Endpoints/Sm/ExplainPolicy.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setPolicyName($policy_name): static { - if (isset($policy_name) !== true) { + if (is_null($policy_name)) { return $this; } $this->policy_name = $policy_name; diff --git a/src/OpenSearch/Endpoints/Sm/GetPolicy.php b/src/OpenSearch/Endpoints/Sm/GetPolicy.php index dc59eeaf..9ed27349 100644 --- a/src/OpenSearch/Endpoints/Sm/GetPolicy.php +++ b/src/OpenSearch/Endpoints/Sm/GetPolicy.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setPolicyName($policy_name): static { - if (isset($policy_name) !== true) { + if (is_null($policy_name)) { return $this; } $this->policy_name = $policy_name; diff --git a/src/OpenSearch/Endpoints/Sm/StartPolicy.php b/src/OpenSearch/Endpoints/Sm/StartPolicy.php index ece11dad..10252995 100644 --- a/src/OpenSearch/Endpoints/Sm/StartPolicy.php +++ b/src/OpenSearch/Endpoints/Sm/StartPolicy.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setPolicyName($policy_name): static { - if (isset($policy_name) !== true) { + if (is_null($policy_name)) { return $this; } $this->policy_name = $policy_name; diff --git a/src/OpenSearch/Endpoints/Sm/StopPolicy.php b/src/OpenSearch/Endpoints/Sm/StopPolicy.php index 35e82af6..f8bdd18a 100644 --- a/src/OpenSearch/Endpoints/Sm/StopPolicy.php +++ b/src/OpenSearch/Endpoints/Sm/StopPolicy.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setPolicyName($policy_name): static { - if (isset($policy_name) !== true) { + if (is_null($policy_name)) { return $this; } $this->policy_name = $policy_name; diff --git a/src/OpenSearch/Endpoints/Sm/UpdatePolicy.php b/src/OpenSearch/Endpoints/Sm/UpdatePolicy.php index dc0950b6..ad0d39fd 100644 --- a/src/OpenSearch/Endpoints/Sm/UpdatePolicy.php +++ b/src/OpenSearch/Endpoints/Sm/UpdatePolicy.php @@ -54,7 +54,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -64,7 +64,7 @@ public function setBody($body): static public function setPolicyName($policy_name): static { - if (isset($policy_name) !== true) { + if (is_null($policy_name)) { return $this; } $this->policy_name = $policy_name; diff --git a/src/OpenSearch/Endpoints/Snapshot/CleanupRepository.php b/src/OpenSearch/Endpoints/Snapshot/CleanupRepository.php index 33800a06..94c9bfea 100644 --- a/src/OpenSearch/Endpoints/Snapshot/CleanupRepository.php +++ b/src/OpenSearch/Endpoints/Snapshot/CleanupRepository.php @@ -61,7 +61,7 @@ public function getMethod(): string public function setRepository($repository): static { - if (isset($repository) !== true) { + if (is_null($repository)) { return $this; } $this->repository = $repository; diff --git a/src/OpenSearch/Endpoints/Snapshot/CloneSnapshot.php b/src/OpenSearch/Endpoints/Snapshot/CloneSnapshot.php index 2d452330..e9b0997c 100644 --- a/src/OpenSearch/Endpoints/Snapshot/CloneSnapshot.php +++ b/src/OpenSearch/Endpoints/Snapshot/CloneSnapshot.php @@ -64,7 +64,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -74,7 +74,7 @@ public function setBody($body): static public function setRepository($repository): static { - if (isset($repository) !== true) { + if (is_null($repository)) { return $this; } $this->repository = $repository; @@ -84,7 +84,7 @@ public function setRepository($repository): static public function setSnapshot($snapshot): static { - if (isset($snapshot) !== true) { + if (is_null($snapshot)) { return $this; } $this->snapshot = $snapshot; @@ -94,7 +94,7 @@ public function setSnapshot($snapshot): static public function setTargetSnapshot($target_snapshot): static { - if (isset($target_snapshot) !== true) { + if (is_null($target_snapshot)) { return $this; } $this->target_snapshot = $target_snapshot; diff --git a/src/OpenSearch/Endpoints/Snapshot/Create.php b/src/OpenSearch/Endpoints/Snapshot/Create.php index 63c5ea70..f296b2ac 100644 --- a/src/OpenSearch/Endpoints/Snapshot/Create.php +++ b/src/OpenSearch/Endpoints/Snapshot/Create.php @@ -63,7 +63,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -73,7 +73,7 @@ public function setBody($body): static public function setRepository($repository): static { - if (isset($repository) !== true) { + if (is_null($repository)) { return $this; } $this->repository = $repository; @@ -83,7 +83,7 @@ public function setRepository($repository): static public function setSnapshot($snapshot): static { - if (isset($snapshot) !== true) { + if (is_null($snapshot)) { return $this; } $this->snapshot = $snapshot; diff --git a/src/OpenSearch/Endpoints/Snapshot/CreateRepository.php b/src/OpenSearch/Endpoints/Snapshot/CreateRepository.php index 5d5f7ef6..c1974fa4 100644 --- a/src/OpenSearch/Endpoints/Snapshot/CreateRepository.php +++ b/src/OpenSearch/Endpoints/Snapshot/CreateRepository.php @@ -62,7 +62,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -72,7 +72,7 @@ public function setBody($body): static public function setRepository($repository): static { - if (isset($repository) !== true) { + if (is_null($repository)) { return $this; } $this->repository = $repository; diff --git a/src/OpenSearch/Endpoints/Snapshot/Delete.php b/src/OpenSearch/Endpoints/Snapshot/Delete.php index 9dd2492a..876490e1 100644 --- a/src/OpenSearch/Endpoints/Snapshot/Delete.php +++ b/src/OpenSearch/Endpoints/Snapshot/Delete.php @@ -62,7 +62,7 @@ public function getMethod(): string public function setRepository($repository): static { - if (isset($repository) !== true) { + if (is_null($repository)) { return $this; } $this->repository = $repository; @@ -72,7 +72,7 @@ public function setRepository($repository): static public function setSnapshot($snapshot): static { - if (isset($snapshot) !== true) { + if (is_null($snapshot)) { return $this; } $this->snapshot = $snapshot; diff --git a/src/OpenSearch/Endpoints/Snapshot/Get.php b/src/OpenSearch/Endpoints/Snapshot/Get.php index 6951e15f..51fc607b 100644 --- a/src/OpenSearch/Endpoints/Snapshot/Get.php +++ b/src/OpenSearch/Endpoints/Snapshot/Get.php @@ -64,7 +64,7 @@ public function getMethod(): string public function setRepository($repository): static { - if (isset($repository) !== true) { + if (is_null($repository)) { return $this; } $this->repository = $repository; diff --git a/src/OpenSearch/Endpoints/Snapshot/Restore.php b/src/OpenSearch/Endpoints/Snapshot/Restore.php index 9c30e67a..ca6d614e 100644 --- a/src/OpenSearch/Endpoints/Snapshot/Restore.php +++ b/src/OpenSearch/Endpoints/Snapshot/Restore.php @@ -63,7 +63,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -73,7 +73,7 @@ public function setBody($body): static public function setRepository($repository): static { - if (isset($repository) !== true) { + if (is_null($repository)) { return $this; } $this->repository = $repository; @@ -83,7 +83,7 @@ public function setRepository($repository): static public function setSnapshot($snapshot): static { - if (isset($snapshot) !== true) { + if (is_null($snapshot)) { return $this; } $this->snapshot = $snapshot; diff --git a/src/OpenSearch/Endpoints/Snapshot/Status.php b/src/OpenSearch/Endpoints/Snapshot/Status.php index d894ce8c..b73cb8e0 100644 --- a/src/OpenSearch/Endpoints/Snapshot/Status.php +++ b/src/OpenSearch/Endpoints/Snapshot/Status.php @@ -65,7 +65,7 @@ public function getMethod(): string public function setRepository($repository): static { - if (isset($repository) !== true) { + if (is_null($repository)) { return $this; } $this->repository = $repository; diff --git a/src/OpenSearch/Endpoints/Snapshot/VerifyRepository.php b/src/OpenSearch/Endpoints/Snapshot/VerifyRepository.php index 4c8b0f87..e3d765ed 100644 --- a/src/OpenSearch/Endpoints/Snapshot/VerifyRepository.php +++ b/src/OpenSearch/Endpoints/Snapshot/VerifyRepository.php @@ -61,7 +61,7 @@ public function getMethod(): string public function setRepository($repository): static { - if (isset($repository) !== true) { + if (is_null($repository)) { return $this; } $this->repository = $repository; diff --git a/src/OpenSearch/Endpoints/Sql/Close.php b/src/OpenSearch/Endpoints/Sql/Close.php index dd9f8d32..7bf12b55 100644 --- a/src/OpenSearch/Endpoints/Sql/Close.php +++ b/src/OpenSearch/Endpoints/Sql/Close.php @@ -47,7 +47,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Sql/Explain.php b/src/OpenSearch/Endpoints/Sql/Explain.php index c7380165..82ddc4c7 100644 --- a/src/OpenSearch/Endpoints/Sql/Explain.php +++ b/src/OpenSearch/Endpoints/Sql/Explain.php @@ -47,7 +47,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Sql/PostStats.php b/src/OpenSearch/Endpoints/Sql/PostStats.php index 4e1073dd..cf3b297e 100644 --- a/src/OpenSearch/Endpoints/Sql/PostStats.php +++ b/src/OpenSearch/Endpoints/Sql/PostStats.php @@ -47,7 +47,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Sql/Query.php b/src/OpenSearch/Endpoints/Sql/Query.php index 47d3699e..e4a362c1 100644 --- a/src/OpenSearch/Endpoints/Sql/Query.php +++ b/src/OpenSearch/Endpoints/Sql/Query.php @@ -47,7 +47,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Sql/Settings.php b/src/OpenSearch/Endpoints/Sql/Settings.php index 5872d364..78fc51f5 100644 --- a/src/OpenSearch/Endpoints/Sql/Settings.php +++ b/src/OpenSearch/Endpoints/Sql/Settings.php @@ -46,7 +46,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Tasks/Cancel.php b/src/OpenSearch/Endpoints/Tasks/Cancel.php index 2d578c53..f5b6f6f1 100644 --- a/src/OpenSearch/Endpoints/Tasks/Cancel.php +++ b/src/OpenSearch/Endpoints/Tasks/Cancel.php @@ -61,7 +61,7 @@ public function getMethod(): string public function setTaskId($task_id): static { - if (isset($task_id) !== true) { + if (is_null($task_id)) { return $this; } $this->task_id = $task_id; diff --git a/src/OpenSearch/Endpoints/Tasks/Get.php b/src/OpenSearch/Endpoints/Tasks/Get.php index 198941ab..e6166abf 100644 --- a/src/OpenSearch/Endpoints/Tasks/Get.php +++ b/src/OpenSearch/Endpoints/Tasks/Get.php @@ -60,7 +60,7 @@ public function getMethod(): string public function setTaskId($task_id): static { - if (isset($task_id) !== true) { + if (is_null($task_id)) { return $this; } $this->task_id = $task_id; diff --git a/src/OpenSearch/Endpoints/TermVectors.php b/src/OpenSearch/Endpoints/TermVectors.php index 7a35caf1..f044f3ad 100644 --- a/src/OpenSearch/Endpoints/TermVectors.php +++ b/src/OpenSearch/Endpoints/TermVectors.php @@ -31,10 +31,8 @@ class TermVectors extends AbstractEndpoint { public function getURI(): string { - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for termvectors' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for termvectors'); } $index = $this->index; $id = $this->id ?? null; @@ -73,7 +71,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Transforms/Preview.php b/src/OpenSearch/Endpoints/Transforms/Preview.php index 167422e5..fe27bf90 100644 --- a/src/OpenSearch/Endpoints/Transforms/Preview.php +++ b/src/OpenSearch/Endpoints/Transforms/Preview.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Transforms/Put.php b/src/OpenSearch/Endpoints/Transforms/Put.php index 5230fc88..b5fc4e1e 100644 --- a/src/OpenSearch/Endpoints/Transforms/Put.php +++ b/src/OpenSearch/Endpoints/Transforms/Put.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Update.php b/src/OpenSearch/Endpoints/Update.php index a45d4ee2..5b39b54f 100644 --- a/src/OpenSearch/Endpoints/Update.php +++ b/src/OpenSearch/Endpoints/Update.php @@ -31,18 +31,15 @@ class Update extends AbstractEndpoint { public function getURI(): string { - if (isset($this->id) !== true) { - throw new RuntimeException( - 'id is required for update' - ); + if (!isset($this->id) || $this->id === '') { + throw new RuntimeException('id is required for update'); } $id = $this->id; - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for update' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for update'); } $index = $this->index; + return "/$index/_update/$id"; } @@ -76,7 +73,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/UpdateByQuery.php b/src/OpenSearch/Endpoints/UpdateByQuery.php index 627176dd..45623475 100644 --- a/src/OpenSearch/Endpoints/UpdateByQuery.php +++ b/src/OpenSearch/Endpoints/UpdateByQuery.php @@ -31,12 +31,11 @@ class UpdateByQuery extends AbstractEndpoint { public function getURI(): string { - if (isset($this->index) !== true) { - throw new RuntimeException( - 'index is required for update_by_query' - ); + if (!isset($this->index) || $this->index === '') { + throw new RuntimeException('index is required for update_by_query'); } $index = $this->index; + return "/$index/_update_by_query"; } @@ -92,7 +91,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/UpdateByQueryRethrottle.php b/src/OpenSearch/Endpoints/UpdateByQueryRethrottle.php index 1281a1ab..72b268ca 100644 --- a/src/OpenSearch/Endpoints/UpdateByQueryRethrottle.php +++ b/src/OpenSearch/Endpoints/UpdateByQueryRethrottle.php @@ -33,12 +33,11 @@ class UpdateByQueryRethrottle extends AbstractEndpoint public function getURI(): string { - if (isset($this->task_id) !== true) { - throw new RuntimeException( - 'task_id is required for update_by_query_rethrottle' - ); + if (!isset($this->task_id) || $this->task_id === '') { + throw new RuntimeException('task_id is required for update_by_query_rethrottle'); } $task_id = $this->task_id; + return "/_update_by_query/$task_id/_rethrottle"; } @@ -61,7 +60,7 @@ public function getMethod(): string public function setTaskId($task_id): static { - if (isset($task_id) !== true) { + if (is_null($task_id)) { return $this; } $this->task_id = $task_id; diff --git a/src/OpenSearch/Endpoints/Wlm/CreateQueryGroup.php b/src/OpenSearch/Endpoints/Wlm/CreateQueryGroup.php index 299d9825..bb902b60 100644 --- a/src/OpenSearch/Endpoints/Wlm/CreateQueryGroup.php +++ b/src/OpenSearch/Endpoints/Wlm/CreateQueryGroup.php @@ -45,7 +45,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; diff --git a/src/OpenSearch/Endpoints/Wlm/DeleteQueryGroup.php b/src/OpenSearch/Endpoints/Wlm/DeleteQueryGroup.php index 8a7cda79..8b63c953 100644 --- a/src/OpenSearch/Endpoints/Wlm/DeleteQueryGroup.php +++ b/src/OpenSearch/Endpoints/Wlm/DeleteQueryGroup.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/Wlm/GetQueryGroup.php b/src/OpenSearch/Endpoints/Wlm/GetQueryGroup.php index 5db7e031..1c6b7e9c 100644 --- a/src/OpenSearch/Endpoints/Wlm/GetQueryGroup.php +++ b/src/OpenSearch/Endpoints/Wlm/GetQueryGroup.php @@ -51,7 +51,7 @@ public function getMethod(): string public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Endpoints/Wlm/UpdateQueryGroup.php b/src/OpenSearch/Endpoints/Wlm/UpdateQueryGroup.php index 2c437c42..49e32ba8 100644 --- a/src/OpenSearch/Endpoints/Wlm/UpdateQueryGroup.php +++ b/src/OpenSearch/Endpoints/Wlm/UpdateQueryGroup.php @@ -52,7 +52,7 @@ public function getMethod(): string public function setBody($body): static { - if (isset($body) !== true) { + if (is_null($body)) { return $this; } $this->body = $body; @@ -62,7 +62,7 @@ public function setBody($body): static public function setName($name): static { - if (isset($name) !== true) { + if (is_null($name)) { return $this; } $this->name = $name; diff --git a/src/OpenSearch/Namespaces/AsynchronousSearchNamespace.php b/src/OpenSearch/Namespaces/AsynchronousSearchNamespace.php index 2fc49119..9922a808 100644 --- a/src/OpenSearch/Namespaces/AsynchronousSearchNamespace.php +++ b/src/OpenSearch/Namespaces/AsynchronousSearchNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class AsynchronousSearchNamespace * diff --git a/src/OpenSearch/Namespaces/BooleanRequestWrapper.php b/src/OpenSearch/Namespaces/BooleanRequestWrapper.php index 1e6f55b5..adf387a7 100644 --- a/src/OpenSearch/Namespaces/BooleanRequestWrapper.php +++ b/src/OpenSearch/Namespaces/BooleanRequestWrapper.php @@ -21,13 +21,12 @@ namespace OpenSearch\Namespaces; +use GuzzleHttp\Ring\Future\FutureArrayInterface; use OpenSearch\Common\Exceptions\Missing404Exception; use OpenSearch\Common\Exceptions\RoutingMissingException; use OpenSearch\Endpoints\AbstractEndpoint; use OpenSearch\Transport; -use GuzzleHttp\Ring\Future\FutureArrayInterface; use OpenSearch\TransportInterface; -use Psr\Http\Client\ClientExceptionInterface; abstract class BooleanRequestWrapper { @@ -42,20 +41,22 @@ abstract class BooleanRequestWrapper public static function sendRequest(AbstractEndpoint $endpoint, TransportInterface $transport): bool { try { - $transport->sendRequest( + $response = $transport->sendRequest( $endpoint->getMethod(), $endpoint->getURI(), $endpoint->getParams(), $endpoint->getBody(), $endpoint->getOptions() ); - } catch (ClientExceptionInterface $e) { - if ($e->getCode() === 404) { - return false; - } - throw $e; + + return match ($response['status_code'] ?? null) { + 404 => false, + default => true, + }; + } catch (Missing404Exception|RoutingMissingException $e) { + // Handle legacy exceptions. + return false; } - return true; } /** diff --git a/src/OpenSearch/Namespaces/CatNamespace.php b/src/OpenSearch/Namespaces/CatNamespace.php index 1911ce8d..f1503a8f 100644 --- a/src/OpenSearch/Namespaces/CatNamespace.php +++ b/src/OpenSearch/Namespaces/CatNamespace.php @@ -21,8 +21,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class CatNamespace * @@ -31,7 +29,7 @@ class CatNamespace extends AbstractNamespace { /** - * Shows information about currently configured aliases to indexes including filter and routing info. + * Shows information about aliases currently configured to indexes, including filter and routing information. * * $params['name'] = (array) A comma-separated list of aliases to retrieve. Supports wildcards (`*`). To retrieve all aliases, omit this parameter or use `*` or `_all`. * $params['expand_wildcards'] = (any) Expands wildcard expressions to concrete indexes. Combine multiple values with commas. Supported values are `all`, `open`, `closed`, `hidden`, and `none`. @@ -62,14 +60,14 @@ public function aliases(array $params = []) } /** - * Lists all active point-in-time segments. + * Lists all active CAT point-in-time segments. * - * $params['bytes'] = (enum) The unit in which to display byte values. (Options = b,g,gb,k,kb,m,mb,p,pb,t,tb) - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['bytes'] = (any) The units used to display byte values. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -91,7 +89,7 @@ public function allPitSegments(array $params = []) * Provides a snapshot of how many shards are allocated to each data node and how much disk space they are using. * * $params['node_id'] = (array) A comma-separated list of node IDs or names used to limit the returned information. - * $params['bytes'] = (enum) The units used to display byte values. (Options = b,g,gb,k,kb,m,mb,p,pb,t,tb) + * $params['bytes'] = (any) The units used to display byte values. * $params['cluster_manager_timeout'] = (string) A timeout for connection to the cluster manager node. * $params['format'] = (string) A short version of the HTTP `Accept` header, such as `json` or `yaml`. * $params['h'] = (array) A comma-separated list of column names to display. @@ -127,7 +125,7 @@ public function allocation(array $params = []) * $params['format'] = (string) A short version of the HTTP `Accept` header, such as `json` or `yaml`. * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['local'] = (boolean) Return local information, do not retrieve the state from cluster-manager node. (Default = false) + * $params['local'] = (boolean) Returns local information but does not retrieve the state from the cluster manager node. (Default = false) * $params['master_timeout'] = (string) A timeout for connection to the cluster manager node. * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) @@ -149,14 +147,14 @@ public function clusterManager(array $params = []) } /** - * Provides quick access to the document count of the entire cluster, or individual indexes. + * Provides quick access to the document count of the entire cluster or of an individual index. * * $params['index'] = (array) Comma-separated list of data streams, indexes, and aliases used to limit the request. Supports wildcards (`*`). To target all data streams and indexes, omit this parameter or use `*` or `_all`. - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -180,13 +178,13 @@ public function count(array $params = []) /** * Shows how much heap memory is currently being used by field data on every data node in the cluster. * - * $params['fields'] = (array) Comma-separated list of fields used to limit returned information. To retrieve all fields, omit this parameter. - * $params['bytes'] = (enum) The unit used to display byte values. (Options = b,g,gb,k,kb,m,mb,p,pb,t,tb) - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['fields'] = (array) A comma-separated list of fields used to limit the amount of returned information. To retrieve all fields, omit this parameter. + * $params['bytes'] = (any) The units used to display byte values. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -210,13 +208,13 @@ public function fielddata(array $params = []) /** * Returns a concise representation of the cluster health. * - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['time'] = (enum) The unit used to display time values. (Options = d,h,m,micros,ms,nanos,s) - * $params['ts'] = (boolean) If `true`, returns `HH:MM:SS` and Unix epoch timestamps. (Default = true) - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['time'] = (any) The unit used to display time values. + * $params['ts'] = (boolean) When `true`, returns `HH:MM:SS` and Unix epoch timestamps. (Default = true) + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -255,23 +253,23 @@ public function help(array $params = []) } /** - * Returns information about indexes: number of primaries and replicas, document counts, disk size, ... + * Lists information related to indexes, that is, how much disk space they are using, how many shards they have, their health status, and so on. * - * $params['index'] = (array) Comma-separated list of data streams, indexes, and aliases used to limit the request. Supports wildcards (`*`). To target all data streams and indexes, omit this parameter or use `*` or `_all`. - * $params['bytes'] = (enum) The unit used to display byte values. (Options = b,g,gb,k,kb,m,mb,p,pb,t,tb) - * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. + * $params['index'] = (array) A comma-separated list of data streams, indexes, and aliases used to limit the request. Supports wildcards (`*`). To target all data streams and indexes, omit this parameter or use `*` or `_all`. + * $params['bytes'] = (any) The units used to display byte values. + * $params['cluster_manager_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. * $params['expand_wildcards'] = (any) The type of index that wildcard patterns can match. - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. - * $params['health'] = (any) The health status used to limit returned indexes. By default, the response includes indexes of any health status. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. + * $params['health'] = (any) Limits indexes based on their health status. Supported values are `green`, `yellow`, and `red`. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['include_unloaded_segments'] = (boolean) If `true`, the response includes information from segments that are not loaded into memory. (Default = false) - * $params['local'] = (boolean) Return local information, do not retrieve the state from cluster-manager node. (Default = false) - * $params['master_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['pri'] = (boolean) If `true`, the response only includes information from primary shards. (Default = false) - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['time'] = (enum) The unit used to display time values. (Options = d,h,m,micros,ms,nanos,s) - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['include_unloaded_segments'] = (boolean) Whether to include information from segments not loaded into memory. (Default = false) + * $params['local'] = (boolean) Returns local information but does not retrieve the state from the cluster manager node. (Default = false) + * $params['master_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['pri'] = (boolean) When `true`, returns information only from the primary shards. (Default = false) + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['time'] = (any) Specifies the time units. + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -295,14 +293,14 @@ public function indices(array $params = []) /** * Returns information about the cluster-manager node. * - * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['cluster_manager_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['local'] = (boolean) Return local information, do not retrieve the state from cluster-manager node. (Default = false) - * $params['master_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['local'] = (boolean) Returns local information but does not retrieve the state from the cluster manager node. (Default = false) + * $params['master_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -323,14 +321,14 @@ public function master(array $params = []) /** * Returns information about custom node attributes. * - * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['cluster_manager_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['local'] = (boolean) Return local information, do not retrieve the state from cluster-manager node. (Default = false) - * $params['master_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['local'] = (boolean) Returns local information but does not retrieve the state from the cluster manager node. (Default = false) + * $params['master_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -349,19 +347,19 @@ public function nodeattrs(array $params = []) } /** - * Returns basic statistics about performance of cluster nodes. + * Returns basic statistics about the performance of cluster nodes. * - * $params['bytes'] = (enum) The unit used to display byte values. (Options = b,g,gb,k,kb,m,mb,p,pb,t,tb) - * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['full_id'] = (any) If `true`, return the full node ID. If `false`, return the shortened node ID. (Default = ) - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['bytes'] = (any) The units used to display byte values. + * $params['cluster_manager_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['full_id'] = (any) When `true`, returns the full node ID. When `false`, returns the shortened node ID. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['local'] = (boolean) Return local information, do not retrieve the state from cluster-manager node. (Default = false) - * $params['master_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['time'] = (enum) The unit in which to display time values. (Options = d,h,m,micros,ms,nanos,s) - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['local'] = (boolean) Returns local information but does not retrieve the state from the cluster manager node. (Default = false) + * $params['master_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['time'] = (any) Specifies the time units, for example, `5d` or `7h`. For more information, see [Supported units](https://opensearch.org/docs/latest/api-reference/units/). + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -380,17 +378,17 @@ public function nodes(array $params = []) } /** - * Returns a concise representation of the cluster pending tasks. + * Returns a concise representation of the cluster's pending tasks. * - * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['cluster_manager_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['local'] = (boolean) Return local information, do not retrieve the state from cluster-manager node. (Default = false) - * $params['master_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['time'] = (enum) The unit in which to display time values. (Options = d,h,m,micros,ms,nanos,s) - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['local'] = (boolean) Returns local information but does not retrieve the state from the cluster manager node. (Default = false) + * $params['master_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['time'] = (any) Specifies the time units, for example, `5d` or `7h`. For more information, see [Supported units](https://opensearch.org/docs/latest/api-reference/units/). + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -409,14 +407,14 @@ public function pendingTasks(array $params = []) } /** - * List segments for one or several PITs. + * Lists one or several CAT point-in-time segments. * - * $params['bytes'] = (enum) The unit in which to display byte values. (Options = b,g,gb,k,kb,m,mb,p,pb,t,tb) - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['bytes'] = (any) The units used to display byte values. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -438,16 +436,16 @@ public function pitSegments(array $params = []) } /** - * Returns information about installed plugins across nodes node. + * Returns information about the names, components, and versions of the installed plugins. * - * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['cluster_manager_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['local'] = (boolean) Return local information, do not retrieve the state from cluster-manager node. (Default = false) - * $params['master_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['local'] = (boolean) Returns local information but does not retrieve the state from the cluster manager node. (Default = false) + * $params['master_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -466,18 +464,18 @@ public function plugins(array $params = []) } /** - * Returns information about index shard recoveries, both on-going completed. + * Returns all completed and ongoing index and shard recoveries. * * $params['index'] = (array) A comma-separated list of data streams, indexes, and aliases used to limit the request. Supports wildcards (`*`). To target all data streams and indexes, omit this parameter or use `*` or `_all`. * $params['active_only'] = (boolean) If `true`, the response only includes ongoing shard recoveries. (Default = false) - * $params['bytes'] = (enum) The unit used to display byte values. (Options = b,g,gb,k,kb,m,mb,p,pb,t,tb) - * $params['detailed'] = (boolean) If `true`, the response includes detailed information about shard recoveries. (Default = false) - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['bytes'] = (any) The units used to display byte values. + * $params['detailed'] = (boolean) When `true`, includes detailed information about shard recoveries. (Default = false) + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['time'] = (enum) The unit in which to display time values. (Options = d,h,m,micros,ms,nanos,s) - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['time'] = (any) Specifies the time units, for example, `5d` or `7h`. For more information, see [Supported units](https://opensearch.org/docs/latest/api-reference/units/). + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -499,16 +497,16 @@ public function recovery(array $params = []) } /** - * Returns information about snapshot repositories registered in the cluster. + * Returns information about all snapshot repositories for a cluster. * - * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['cluster_manager_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['local'] = (boolean) Return local information, do not retrieve the state from cluster-manager node. (Default = false) - * $params['master_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['local'] = (boolean) Returns local information but does not retrieve the state from the cluster manager node. (Default = false) + * $params['master_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -527,25 +525,25 @@ public function repositories(array $params = []) } /** - * Returns information about both on-going and latest completed Segment Replication events. - * - * $params['index'] = (array) Comma-separated list or wildcard expression of index names to limit the returned information. - * $params['active_only'] = (boolean) If `true`, the response only includes ongoing segment replication events. (Default = false) - * $params['allow_no_indices'] = (boolean) Whether to ignore if a wildcard indexes expression resolves into no concrete indexes. (This includes `_all` string or when no indexes have been specified). - * $params['bytes'] = (enum) The unit in which to display byte values. (Options = b,g,gb,k,kb,m,mb,p,pb,t,tb) - * $params['completed_only'] = (boolean) If `true`, the response only includes latest completed segment replication events. (Default = false) - * $params['detailed'] = (boolean) If `true`, the response includes detailed information about segment replications. (Default = false) - * $params['expand_wildcards'] = (any) Whether to expand wildcard expression to concrete indexes that are open, closed or both. - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * Returns information about active and last-completed segment replication events on each replica shard, including related shard-level metrics. These metrics provide information about how far behind the primary shard the replicas are lagging. + * + * $params['index'] = (array) A comma-separated list of data streams, indexes, and aliases used to limit the request. Supports wildcards (`*`). To target all data streams and indexes, omit this parameter or use `*` or `_all`. + * $params['active_only'] = (boolean) When `true`, the response only includes ongoing segment replication events. (Default = false) + * $params['allow_no_indices'] = (boolean) Whether to ignore the index if a wildcard index expression resolves to no concrete indexes. This includes the `_all` string or when no indexes have been specified. + * $params['bytes'] = (any) The units used to display byte values. + * $params['completed_only'] = (boolean) When `true`, the response only includes the last-completed segment replication events. (Default = false) + * $params['detailed'] = (boolean) When `true`, the response includes additional metrics for each stage of a segment replication event. (Default = false) + * $params['expand_wildcards'] = (any) Whether to expand the wildcard expression to include concrete indexes that are open, closed, or both. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['ignore_throttled'] = (boolean) Whether specified concrete, expanded or aliased indexes should be ignored when throttled. - * $params['ignore_unavailable'] = (boolean) Whether specified concrete indexes should be ignored when unavailable (missing or closed). - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['shards'] = (array) Comma-separated list of shards to display. - * $params['time'] = (enum) The unit in which to display time values. (Options = d,h,m,micros,ms,nanos,s) - * $params['timeout'] = (string) Operation timeout. - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['ignore_throttled'] = (boolean) Whether specified concrete, expanded, or aliased indexes should be ignored when throttled. + * $params['ignore_unavailable'] = (boolean) Whether the specified concrete indexes should be ignored when missing or closed. + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['shards'] = (array) A comma-separated list of shards to display. + * $params['time'] = (any) Specifies the time units, for example, `5d` or `7h`. For more information, see [Supported units](https://opensearch.org/docs/latest/api-reference/units/). + * $params['timeout'] = (string) The operation timeout. + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -570,14 +568,14 @@ public function segmentReplication(array $params = []) * Provides low-level information about the segments in the shards of an index. * * $params['index'] = (array) A comma-separated list of data streams, indexes, and aliases used to limit the request. Supports wildcards (`*`). To target all data streams and indexes, omit this parameter or use `*` or `_all`. - * $params['bytes'] = (enum) The unit used to display byte values. (Options = b,g,gb,k,kb,m,mb,p,pb,t,tb) - * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. - * $params['help'] = (boolean) Return help information. (Default = false) - * $params['master_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['bytes'] = (any) The units used to display byte values. + * $params['cluster_manager_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. + * $params['help'] = (boolean) Returns help information. (Default = false) + * $params['master_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -599,19 +597,19 @@ public function segments(array $params = []) } /** - * Provides a detailed view of shard allocation on nodes. + * Lists the states of all primary and replica shards and how they are distributed. * * $params['index'] = (array) A comma-separated list of data streams, indexes, and aliases used to limit the request. Supports wildcards (`*`). To target all data streams and indexes, omit this parameter or use `*` or `_all`. - * $params['bytes'] = (enum) The unit used to display byte values. (Options = b,g,gb,k,kb,m,mb,p,pb,t,tb) - * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['bytes'] = (any) The units used to display byte values. + * $params['cluster_manager_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['local'] = (boolean) Return local information, do not retrieve the state from cluster-manager node. (Default = false) - * $params['master_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['time'] = (enum) The unit in which to display time values. (Options = d,h,m,micros,ms,nanos,s) - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['local'] = (boolean) Returns local information but does not retrieve the state from the cluster manager node. (Default = false) + * $params['master_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['time'] = (any) Specifies the time units, for example, `5d` or `7h`. For more information, see [Supported units](https://opensearch.org/docs/latest/api-reference/units/). + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -633,18 +631,18 @@ public function shards(array $params = []) } /** - * Returns all snapshots in a specific repository. + * Lists all of the snapshots stored in a specific repository. * * $params['repository'] = (array) A comma-separated list of snapshot repositories used to limit the request. Accepts wildcard expressions. `_all` returns all repositories. If any repository fails during the request, OpenSearch returns an error. - * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['cluster_manager_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['ignore_unavailable'] = (boolean) If `true`, the response does not include information from unavailable snapshots. (Default = false) - * $params['master_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['time'] = (enum) The unit in which to display time values. (Options = d,h,m,micros,ms,nanos,s) - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['ignore_unavailable'] = (boolean) When `true`, the response does not include information from unavailable snapshots. (Default = false) + * $params['master_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['time'] = (any) Specifies the time units, for example, `5d` or `7h`. For more information, see [Supported units](https://opensearch.org/docs/latest/api-reference/units/). + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -666,22 +664,22 @@ public function snapshots(array $params = []) } /** - * Returns information about the tasks currently executing on one or more nodes in the cluster. + * Lists the progress of all tasks currently running on the cluster. * - * $params['actions'] = (array) The task action names, which are used to limit the response. + * $params['actions'] = (array) The task action names used to limit the response. * $params['detailed'] = (boolean) If `true`, the response includes detailed information about shard recoveries. (Default = false) - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['time'] = (enum) The unit in which to display time values. (Options = d,h,m,micros,ms,nanos,s) - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['time'] = (any) Specifies the time units, for example, `5d` or `7h`. For more information, see [Supported units](https://opensearch.org/docs/latest/api-reference/units/). + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) * $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 "-". - * $params['node_id'] = (array) Comma-separated list of node IDs or names to limit the returned information; use `_local` to return information from the node you're connecting to, leave empty to get information from all nodes. + * $params['node_id'] = (array) A comma-separated list of node IDs or names used to limit the returned information. Use `_local` to return information from the node to which you're connecting, specify a specific node from which to get information, or keep the parameter empty to get information from all nodes. * $params['parent_task'] = (string) The parent task identifier, which is used to limit the response. * * @param array $params Associative array of parameters @@ -696,17 +694,17 @@ public function tasks(array $params = []) } /** - * Returns information about existing templates. + * Lists the names, patterns, order numbers, and version numbers of index templates. * * $params['name'] = (string) The name of the template to return. Accepts wildcard expressions. If omitted, all templates are returned. - * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['cluster_manager_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['local'] = (boolean) Return local information, do not retrieve the state from cluster-manager node. (Default = false) - * $params['master_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['local'] = (boolean) Returns local information but does not retrieve the state from the cluster manager node. (Default = false) + * $params['master_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) @@ -728,18 +726,18 @@ public function templates(array $params = []) } /** - * Returns cluster-wide thread pool statistics per node.By default the active, queue and rejected statistics are returned for all thread pools. + * Returns cluster-wide thread pool statistics per node.By default the active, queued, and rejected statistics are returned for all thread pools. * * $params['thread_pool_patterns'] = (array) A comma-separated list of thread pool names used to limit the request. Accepts wildcard expressions. - * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['format'] = (string) A short version of the Accept header (for example, `json`, `yaml`). - * $params['h'] = (array) Comma-separated list of column names to display. + * $params['cluster_manager_timeout'] = (string) A timeout for connection to the cluster manager node. + * $params['format'] = (string) A short version of the `Accept` header, such as `json` or `yaml`. + * $params['h'] = (array) A comma-separated list of column names to display. * $params['help'] = (boolean) Return help information. (Default = false) - * $params['local'] = (boolean) Return local information, do not retrieve the state from cluster-manager node. (Default = false) - * $params['master_timeout'] = (string) Operation timeout for connection to cluster-manager node. - * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. + * $params['local'] = (boolean) Returns local information but does not retrieve the state from the cluster manager node. (Default = false) + * $params['master_timeout'] = (string) The amount of time allowed to establish a connection to the cluster manager node. + * $params['s'] = (array) A comma-separated list of column names or column aliases to sort by. * $params['size'] = (integer) The multiplier in which to display values. - * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) + * $params['v'] = (boolean) Enables verbose mode, which displays column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) diff --git a/src/OpenSearch/Namespaces/ClusterNamespace.php b/src/OpenSearch/Namespaces/ClusterNamespace.php index 3ebcd0f8..dd9b5135 100644 --- a/src/OpenSearch/Namespaces/ClusterNamespace.php +++ b/src/OpenSearch/Namespaces/ClusterNamespace.php @@ -21,8 +21,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class ClusterNamespace * @@ -182,6 +180,7 @@ public function existsComponentTemplate(array $params = []): bool * * $params['name'] = (array) Name of the component template to retrieve. Wildcard (`*`) expressions are supported. * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. + * $params['flat_settings'] = (boolean) If `true`, returns settings in flat format. (Default = false) * $params['local'] = (boolean) If `true`, the request retrieves information from the local node only.If `false`, information is retrieved from the cluster-manager node. (Default = false) * $params['master_timeout'] = (string) Period to wait for a connection to the cluster-manager node.If no response is received before the timeout expires, the request fails and returns an error. * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) diff --git a/src/OpenSearch/Namespaces/DanglingIndicesNamespace.php b/src/OpenSearch/Namespaces/DanglingIndicesNamespace.php index 14fd9acc..fcc9c0f6 100644 --- a/src/OpenSearch/Namespaces/DanglingIndicesNamespace.php +++ b/src/OpenSearch/Namespaces/DanglingIndicesNamespace.php @@ -21,8 +21,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class DanglingIndicesNamespace * diff --git a/src/OpenSearch/Namespaces/FlowFrameworkNamespace.php b/src/OpenSearch/Namespaces/FlowFrameworkNamespace.php index d758ad9e..1a926267 100644 --- a/src/OpenSearch/Namespaces/FlowFrameworkNamespace.php +++ b/src/OpenSearch/Namespaces/FlowFrameworkNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class FlowFrameworkNamespace * diff --git a/src/OpenSearch/Namespaces/IndicesNamespace.php b/src/OpenSearch/Namespaces/IndicesNamespace.php index cd7b64b0..ffa64981 100644 --- a/src/OpenSearch/Namespaces/IndicesNamespace.php +++ b/src/OpenSearch/Namespaces/IndicesNamespace.php @@ -21,8 +21,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class IndicesNamespace * @@ -440,7 +438,7 @@ public function exists(array $params = []): bool $endpoint->setParams($params); $endpoint->setIndex($index); - return BooleanRequestWrapper::performRequest($endpoint, $this->transport); + return BooleanRequestWrapper::sendRequest($endpoint, $this->httpTransport); } /** @@ -474,7 +472,7 @@ public function existsAlias(array $params = []): bool $endpoint->setName($name); $endpoint->setIndex($index); - return BooleanRequestWrapper::performRequest($endpoint, $this->transport); + return BooleanRequestWrapper::sendRequest($endpoint, $this->httpTransport); } /** @@ -505,7 +503,7 @@ public function existsIndexTemplate(array $params = []): bool $endpoint->setParams($params); $endpoint->setName($name); - return BooleanRequestWrapper::performRequest($endpoint, $this->transport); + return BooleanRequestWrapper::sendRequest($endpoint, $this->httpTransport); } /** @@ -536,7 +534,7 @@ public function existsTemplate(array $params = []): bool $endpoint->setParams($params); $endpoint->setName($name); - return BooleanRequestWrapper::performRequest($endpoint, $this->transport); + return BooleanRequestWrapper::sendRequest($endpoint, $this->httpTransport); } /** @@ -576,7 +574,7 @@ public function flush(array $params = []) * $params['expand_wildcards'] = (any) Whether to expand wildcard expression to concrete indexes that are open, closed or both. * $params['flush'] = (boolean) Specify whether the index should be flushed after performing the operation. (Default = true) * $params['ignore_unavailable'] = (boolean) Whether specified concrete indexes should be ignored when unavailable (missing or closed) - * $params['max_num_segments'] = (number) The number of larger segments into which smaller segments are merged.Set this parameter to 1 to merge all segments into one segment.The default behavior is to perform the merge as necessary. + * $params['max_num_segments'] = (integer) The number of larger segments into which smaller segments are merged.Set this parameter to 1 to merge all segments into one segment.The default behavior is to perform the merge as necessary. * $params['only_expunge_deletes'] = (boolean) Specify whether the operation should only expunge deleted documents * $params['primary_only'] = (boolean) Specify whether the operation should only perform on primary shards. Defaults to false. (Default = false) * $params['wait_for_completion'] = (boolean) Should the request wait until the force merge is completed. (Default = true) @@ -1449,12 +1447,10 @@ public function updateAliases(array $params = []) public function upgrade(array $params = []) { $index = $this->extractArgument($params, 'index'); - $body = $this->extractArgument($params, 'body'); $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Indices\Upgrade::class); $endpoint->setParams($params); $endpoint->setIndex($index); - $endpoint->setBody($body); return $this->performRequest($endpoint); } diff --git a/src/OpenSearch/Namespaces/IngestNamespace.php b/src/OpenSearch/Namespaces/IngestNamespace.php index b0ef3723..23e18482 100644 --- a/src/OpenSearch/Namespaces/IngestNamespace.php +++ b/src/OpenSearch/Namespaces/IngestNamespace.php @@ -21,8 +21,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class IngestNamespace * diff --git a/src/OpenSearch/Namespaces/InsightsNamespace.php b/src/OpenSearch/Namespaces/InsightsNamespace.php index 8017024f..7edb4fdc 100644 --- a/src/OpenSearch/Namespaces/InsightsNamespace.php +++ b/src/OpenSearch/Namespaces/InsightsNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class InsightsNamespace * diff --git a/src/OpenSearch/Namespaces/IsmNamespace.php b/src/OpenSearch/Namespaces/IsmNamespace.php index bebc3911..9aca519f 100644 --- a/src/OpenSearch/Namespaces/IsmNamespace.php +++ b/src/OpenSearch/Namespaces/IsmNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class IsmNamespace * @@ -124,7 +122,7 @@ public function existsPolicy(array $params = []): bool $endpoint->setParams($params); $endpoint->setPolicyId($policy_id); - return BooleanRequestWrapper::performRequest($endpoint, $this->transport); + return BooleanRequestWrapper::sendRequest($endpoint, $this->httpTransport); } /** diff --git a/src/OpenSearch/Namespaces/KnnNamespace.php b/src/OpenSearch/Namespaces/KnnNamespace.php index 0fb72f78..d33805db 100644 --- a/src/OpenSearch/Namespaces/KnnNamespace.php +++ b/src/OpenSearch/Namespaces/KnnNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class KnnNamespace * diff --git a/src/OpenSearch/Namespaces/ListNamespace.php b/src/OpenSearch/Namespaces/ListNamespace.php index f6e97043..de0aac1f 100644 --- a/src/OpenSearch/Namespaces/ListNamespace.php +++ b/src/OpenSearch/Namespaces/ListNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class ListNamespace * @@ -48,7 +46,7 @@ public function help(array $params = []) * Returns paginated information about indexes including number of primaries and replicas, document counts, disk size. * * $params['index'] = (array) Comma-separated list of data streams, indexes, and aliases used to limit the request. Supports wildcards (`*`). To target all data streams and indexes, omit this parameter or use `*` or `_all`. - * $params['bytes'] = (enum) The unit used to display byte values. (Options = b,g,gb,k,kb,m,mb,p,pb,t,tb) + * $params['bytes'] = (any) The unit used to display byte values. * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. * $params['expand_wildcards'] = (any) The type of index that wildcard patterns can match. * $params['format'] = (string) A short version of the Accept header, such as `JSON`, `YAML`. @@ -63,7 +61,7 @@ public function help(array $params = []) * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. * $params['size'] = (integer) Maximum number of indexes to be displayed in a page. * $params['sort'] = (enum) Defines order in which indexes will be displayed. Accepted values are `asc` and `desc`. If `desc`, most recently created indexes would be displayed first. (Options = asc,desc) - * $params['time'] = (enum) The unit used to display time values. (Options = d,h,m,micros,ms,nanos,s) + * $params['time'] = (any) The unit used to display time values. * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) @@ -89,7 +87,7 @@ public function indices(array $params = []) * Returns paginated details of shard allocation on nodes. * * $params['index'] = (array) A comma-separated list of data streams, indexes, and aliases used to limit the request. Supports wildcards (`*`). To target all data streams and indexes, omit this parameter or use `*` or `_all`. - * $params['bytes'] = (enum) The unit used to display byte values. (Options = b,g,gb,k,kb,m,mb,p,pb,t,tb) + * $params['bytes'] = (any) The unit used to display byte values. * $params['cluster_manager_timeout'] = (string) Operation timeout for connection to cluster-manager node. * $params['format'] = (string) A short version of the Accept header, such as `JSON`, `YAML`. * $params['h'] = (array) Comma-separated list of column names to display. @@ -100,7 +98,7 @@ public function indices(array $params = []) * $params['s'] = (array) Comma-separated list of column names or column aliases to sort by. * $params['size'] = (integer) Maximum number of shards to be displayed in a page. * $params['sort'] = (enum) Defines order in which shards will be displayed. Accepted values are `asc` and `desc`. If `desc`, most recently created shards would be displayed first. (Options = asc,desc) - * $params['time'] = (enum) The unit in which to display time values. (Options = d,h,m,micros,ms,nanos,s) + * $params['time'] = (any) The unit in which to display time values. * $params['v'] = (boolean) Verbose mode. Display column headers. (Default = false) * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) diff --git a/src/OpenSearch/Namespaces/MlNamespace.php b/src/OpenSearch/Namespaces/MlNamespace.php index 473a754f..52f28446 100644 --- a/src/OpenSearch/Namespaces/MlNamespace.php +++ b/src/OpenSearch/Namespaces/MlNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class MlNamespace * @@ -24,6 +22,55 @@ */ class MlNamespace extends AbstractNamespace { + /** + * Create a memory. + * + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 createMemory(array $params = []) + { + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\CreateMemory::class); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + + /** + * Create a message. + * + * $params['memory_id'] = (string) + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 createMessage(array $params = []) + { + $memory_id = $this->extractArgument($params, 'memory_id'); + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\CreateMessage::class); + $endpoint->setParams($params); + $endpoint->setMemoryId($memory_id); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + /** * Delete an agent. * @@ -48,6 +95,30 @@ public function deleteAgent(array $params = []) return $this->performRequest($endpoint); } + /** + * Delete a memory. + * + * $params['memory_id'] = (string) + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 deleteMemory(array $params = []) + { + $memory_id = $this->extractArgument($params, 'memory_id'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\DeleteMemory::class); + $endpoint->setParams($params); + $endpoint->setMemoryId($memory_id); + + return $this->performRequest($endpoint); + } + /** * Deletes a model. * @@ -120,6 +191,83 @@ public function deleteTask(array $params = []) return $this->performRequest($endpoint); } + /** + * Get a memory. + * + * $params['memory_id'] = (string) + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 getMemory(array $params = []) + { + $memory_id = $this->extractArgument($params, 'memory_id'); + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\GetMemory::class); + $endpoint->setParams($params); + $endpoint->setMemoryId($memory_id); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + + /** + * Get a message. + * + * $params['memory_id'] = (string) + * $params['message_id'] = (string) + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 getMessage(array $params = []) + { + $memory_id = $this->extractArgument($params, 'memory_id'); + $message_id = $this->extractArgument($params, 'message_id'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\GetMessage::class); + $endpoint->setParams($params); + $endpoint->setMemoryId($memory_id); + $endpoint->setMessageId($message_id); + + return $this->performRequest($endpoint); + } + + /** + * Get a message traces. + * + * $params['message_id'] = (string) + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 getMessageTraces(array $params = []) + { + $message_id = $this->extractArgument($params, 'message_id'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\GetMessageTraces::class); + $endpoint->setParams($params); + $endpoint->setMessageId($message_id); + + return $this->performRequest($endpoint); + } + /** * Retrieves a model group. * @@ -237,6 +385,101 @@ public function registerModelGroup(array $params = []) return $this->performRequest($endpoint); } + /** + * Searches for standalone connectors. + * + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 searchConnectors(array $params = []) + { + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\SearchConnectors::class); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + + /** + * Search memory. + * + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 searchMemory(array $params = []) + { + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\SearchMemory::class); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + + /** + * Search messages. + * + * $params['memory_id'] = (string) + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 searchMessage(array $params = []) + { + $memory_id = $this->extractArgument($params, 'memory_id'); + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\SearchMessage::class); + $endpoint->setParams($params); + $endpoint->setMemoryId($memory_id); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + + /** + * Searches for model groups. + * + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 searchModelGroup(array $params = []) + { + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\SearchModelGroup::class); + $endpoint->setParams($params); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + /** * Searches for models. * @@ -260,6 +503,136 @@ public function searchModels(array $params = []) return $this->performRequest($endpoint); } + /** + * Trains a model synchronously. + * + * $params['algorithm_name'] = (string) + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 train(array $params = []) + { + $algorithm_name = $this->extractArgument($params, 'algorithm_name'); + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\Train::class); + $endpoint->setParams($params); + $endpoint->setAlgorithmName($algorithm_name); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + + /** + * Trains a model and predicts against the same training dataset. + * + * $params['algorithm_name'] = (string) + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 trainPredict(array $params = []) + { + $algorithm_name = $this->extractArgument($params, 'algorithm_name'); + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\TrainPredict::class); + $endpoint->setParams($params); + $endpoint->setAlgorithmName($algorithm_name); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + + /** + * Updates a standalone connector. + * + * $params['connector_id'] = (string) + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 updateConnector(array $params = []) + { + $connector_id = $this->extractArgument($params, 'connector_id'); + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\UpdateConnector::class); + $endpoint->setParams($params); + $endpoint->setConnectorId($connector_id); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + + /** + * Update a memory. + * + * $params['memory_id'] = (string) + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 updateMemory(array $params = []) + { + $memory_id = $this->extractArgument($params, 'memory_id'); + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\UpdateMemory::class); + $endpoint->setParams($params); + $endpoint->setMemoryId($memory_id); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + + /** + * Update a message. + * + * $params['message_id'] = (string) + * $params['pretty'] = (boolean) Whether to pretty format the returned JSON response. (Default = false) + * $params['human'] = (boolean) Whether to return human readable values for statistics. (Default = true) + * $params['error_trace'] = (boolean) Whether to include the stack trace of returned errors. (Default = false) + * $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 updateMessage(array $params = []) + { + $message_id = $this->extractArgument($params, 'message_id'); + $body = $this->extractArgument($params, 'body'); + + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\UpdateMessage::class); + $endpoint->setParams($params); + $endpoint->setMessageId($message_id); + $endpoint->setBody($body); + + return $this->performRequest($endpoint); + } + /** * $params['body'] = (string) The body of the request (Required) * @@ -327,9 +700,11 @@ public function deployModel(array $params = []): array public function getConnector(array $params = []): array { $id = $this->extractArgument($params, 'id'); + $connector_id = $this->extractArgument($params, 'connector_id'); $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\GetConnector::class); $endpoint->setParams($params); $endpoint->setId($id); + $endpoint->setConnectorId($connector_id); return $this->performRequest($endpoint); } @@ -428,10 +803,15 @@ public function predict(array $params = []): array { $id = $this->extractArgument($params, 'id'); $body = $this->extractArgument($params, 'body'); + $algorithm_name = $this->extractArgument($params, 'algorithm_name'); + $model_id = $this->extractArgument($params, 'model_id'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\Predict::class); - $endpoint->setParams($params); - $endpoint->setId($id); - $endpoint->setBody($body); + $endpoint->setParams($params) + ->setId($id) + ->setBody($body) + ->setAlgorithmName($algorithm_name) + ->setModelId($model_id); return $this->performRequest($endpoint); } @@ -469,11 +849,13 @@ public function undeployModel(array $params = []): array public function updateModelGroup(array $params = []): array { $id = $this->extractArgument($params, 'id'); + $model_group_id = $this->extractArgument($params, 'model_group_id'); $body = $this->extractArgument($params, 'body'); $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\UpdateModelGroup::class); $endpoint->setParams($params); $endpoint->setBody($body); $endpoint->setId($id); + $endpoint->setModelGroupId($model_group_id); return $this->performRequest($endpoint); } diff --git a/src/OpenSearch/Namespaces/NodesNamespace.php b/src/OpenSearch/Namespaces/NodesNamespace.php index d5029067..32dfc08e 100644 --- a/src/OpenSearch/Namespaces/NodesNamespace.php +++ b/src/OpenSearch/Namespaces/NodesNamespace.php @@ -21,8 +21,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class NodesNamespace * diff --git a/src/OpenSearch/Namespaces/NotificationsNamespace.php b/src/OpenSearch/Namespaces/NotificationsNamespace.php index cf4df692..997e5bac 100644 --- a/src/OpenSearch/Namespaces/NotificationsNamespace.php +++ b/src/OpenSearch/Namespaces/NotificationsNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class NotificationsNamespace * diff --git a/src/OpenSearch/Namespaces/ObservabilityNamespace.php b/src/OpenSearch/Namespaces/ObservabilityNamespace.php index 167efc0a..3bc1486e 100644 --- a/src/OpenSearch/Namespaces/ObservabilityNamespace.php +++ b/src/OpenSearch/Namespaces/ObservabilityNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class ObservabilityNamespace * diff --git a/src/OpenSearch/Namespaces/PplNamespace.php b/src/OpenSearch/Namespaces/PplNamespace.php index aa08509a..fa2149c1 100644 --- a/src/OpenSearch/Namespaces/PplNamespace.php +++ b/src/OpenSearch/Namespaces/PplNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class PplNamespace * diff --git a/src/OpenSearch/Namespaces/QueryNamespace.php b/src/OpenSearch/Namespaces/QueryNamespace.php index 15ebf3f2..a9f3893e 100644 --- a/src/OpenSearch/Namespaces/QueryNamespace.php +++ b/src/OpenSearch/Namespaces/QueryNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class QueryNamespace * diff --git a/src/OpenSearch/Namespaces/RemoteStoreNamespace.php b/src/OpenSearch/Namespaces/RemoteStoreNamespace.php index a910f508..1884900d 100644 --- a/src/OpenSearch/Namespaces/RemoteStoreNamespace.php +++ b/src/OpenSearch/Namespaces/RemoteStoreNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class RemoteStoreNamespace * diff --git a/src/OpenSearch/Namespaces/ReplicationNamespace.php b/src/OpenSearch/Namespaces/ReplicationNamespace.php index e90c397d..bc9f709a 100644 --- a/src/OpenSearch/Namespaces/ReplicationNamespace.php +++ b/src/OpenSearch/Namespaces/ReplicationNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class ReplicationNamespace * diff --git a/src/OpenSearch/Namespaces/RollupsNamespace.php b/src/OpenSearch/Namespaces/RollupsNamespace.php index 4a5a00d2..57adaea2 100644 --- a/src/OpenSearch/Namespaces/RollupsNamespace.php +++ b/src/OpenSearch/Namespaces/RollupsNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class RollupsNamespace * diff --git a/src/OpenSearch/Namespaces/SearchPipelineNamespace.php b/src/OpenSearch/Namespaces/SearchPipelineNamespace.php index c9f294db..fea10cfb 100644 --- a/src/OpenSearch/Namespaces/SearchPipelineNamespace.php +++ b/src/OpenSearch/Namespaces/SearchPipelineNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class SearchPipelineNamespace * diff --git a/src/OpenSearch/Namespaces/SecurityNamespace.php b/src/OpenSearch/Namespaces/SecurityNamespace.php index 7930ef90..17dd7fef 100644 --- a/src/OpenSearch/Namespaces/SecurityNamespace.php +++ b/src/OpenSearch/Namespaces/SecurityNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class SecurityNamespace * diff --git a/src/OpenSearch/Namespaces/SmNamespace.php b/src/OpenSearch/Namespaces/SmNamespace.php index 950420a0..3837edbe 100644 --- a/src/OpenSearch/Namespaces/SmNamespace.php +++ b/src/OpenSearch/Namespaces/SmNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class SmNamespace * diff --git a/src/OpenSearch/Namespaces/SnapshotNamespace.php b/src/OpenSearch/Namespaces/SnapshotNamespace.php index b93cb40d..8f00b42c 100644 --- a/src/OpenSearch/Namespaces/SnapshotNamespace.php +++ b/src/OpenSearch/Namespaces/SnapshotNamespace.php @@ -21,8 +21,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class SnapshotNamespace * diff --git a/src/OpenSearch/Namespaces/SqlNamespace.php b/src/OpenSearch/Namespaces/SqlNamespace.php index 783668c2..5a9fe9cf 100644 --- a/src/OpenSearch/Namespaces/SqlNamespace.php +++ b/src/OpenSearch/Namespaces/SqlNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class SqlNamespace * diff --git a/src/OpenSearch/Namespaces/TasksNamespace.php b/src/OpenSearch/Namespaces/TasksNamespace.php index 9c46d111..99fdf537 100644 --- a/src/OpenSearch/Namespaces/TasksNamespace.php +++ b/src/OpenSearch/Namespaces/TasksNamespace.php @@ -21,8 +21,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class TasksNamespace * diff --git a/src/OpenSearch/Namespaces/TransformsNamespace.php b/src/OpenSearch/Namespaces/TransformsNamespace.php index e4599d22..794c48f3 100644 --- a/src/OpenSearch/Namespaces/TransformsNamespace.php +++ b/src/OpenSearch/Namespaces/TransformsNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class TransformsNamespace * diff --git a/src/OpenSearch/Namespaces/WlmNamespace.php b/src/OpenSearch/Namespaces/WlmNamespace.php index 53670a61..c520e8ea 100644 --- a/src/OpenSearch/Namespaces/WlmNamespace.php +++ b/src/OpenSearch/Namespaces/WlmNamespace.php @@ -15,8 +15,6 @@ namespace OpenSearch\Namespaces; -use OpenSearch\Namespaces\AbstractNamespace; - /** * Class WlmNamespace * diff --git a/tests/ClientBuilderTest.php b/tests/ClientBuilderTest.php index 751e3895..88991271 100644 --- a/tests/ClientBuilderTest.php +++ b/tests/ClientBuilderTest.php @@ -27,6 +27,9 @@ use OpenSearch\Common\Exceptions\RuntimeException; use PHPUnit\Framework\TestCase; +/** + * @group legacy + */ class ClientBuilderTest extends TestCase { /** diff --git a/tests/ClientIntegrationTest.php b/tests/ClientIntegrationTest.php index 2fd5c391..d6b807a8 100644 --- a/tests/ClientIntegrationTest.php +++ b/tests/ClientIntegrationTest.php @@ -21,12 +21,15 @@ namespace OpenSearch\Tests; +use GuzzleHttp\Client as GuzzleClient; +use GuzzleHttp\Psr7\HttpFactory; use OpenSearch\Client; -use OpenSearch\ClientBuilder; -use OpenSearch\Common\Exceptions\BadRequest400Exception; -use OpenSearch\Common\Exceptions\Missing404Exception; -use OpenSearch\Tests\ClientBuilder\ArrayLogger; -use Psr\Log\LogLevel; +use OpenSearch\Common\Exceptions\RuntimeException; +use OpenSearch\EndpointFactory; +use OpenSearch\RequestFactory; +use OpenSearch\Serializers\SmartSerializer; +use OpenSearch\TransportFactory; +use PHPUnit\Framework\TestCase; /** * Class ClientTest @@ -35,73 +38,46 @@ * @group Integration * @group Integration-Min */ -class ClientIntegrationTest extends \PHPUnit\Framework\TestCase +class ClientIntegrationTest extends TestCase { /** - * @var ArrayLogger + * The client under test. */ - private $logger; + private Client $client; - /** - * @var string - */ - private $host; - - public function setUp(): void + protected function setUp(): void { - $this->host = Utility::getHost(); - $this->logger = new ArrayLogger(); + parent::setUp(); + $this->client = $this->getClient(); } - private function getClient(): Client + public function testInfoNotEmpty() { - $client = ClientBuilder::create() - ->setHosts([$this->host]) - ->setLogger($this->logger) - ->setSSLVerification(false); + $result = $this->client->info(); - return $client->build(); + $this->assertArrayHasKey('name', $result); + $this->assertArrayHasKey('cluster_name', $result); + $this->assertArrayHasKey('cluster_uuid', $result); + $this->assertArrayHasKey('version', $result); } - public function testLogRequestSuccessHasInfoNotEmpty() + public function testNotFoundError() { - $client = $this->getClient(); - - $result = $client->info(); - - $this->assertNotEmpty($this->getLevelOutput(LogLevel::INFO, $this->logger->output)); - } - - public function testLogRequestSuccessHasPortInInfo() - { - $client = $this->getClient(); - - $result = $client->info(); - - $this->assertStringContainsString('"port"', $this->getLevelOutput(LogLevel::INFO, $this->logger->output)); - } - - public function testLogRequestFailHasWarning() - { - $client = $this->getClient(); - - try { - $result = $client->get([ - 'index' => 'foo', - 'id' => 'bar', - ]); - } catch (Missing404Exception $e) { - $this->assertNotEmpty($this->getLevelOutput(LogLevel::WARNING, $this->logger->output)); - } + $result = $this->client->get([ + 'index' => 'foo', + 'id' => 'bar', + ]); + $this->assertEquals(404, $result['status']); + $error = $result['error']; + $this->assertEquals('index_not_found_exception', $error['type']); + $this->assertEquals('no such index [foo]', $error['reason']); + $this->assertEquals('foo', $error['index']); } public function testIndexCannotBeEmptyStringForDelete() { - $client = $this->getClient(); - - $this->expectException(Missing404Exception::class); - - $client->delete( + $this->expectException(RuntimeException::class); + $this->client->delete( [ 'index' => '', 'id' => 'test', @@ -111,11 +87,10 @@ public function testIndexCannotBeEmptyStringForDelete() public function testIdCannotBeEmptyStringForDelete() { - $client = $this->getClient(); + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('id is required for delete'); - $this->expectException(BadRequest400Exception::class); - - $client->delete( + $this->client->delete( [ 'index' => 'test', 'id' => '', @@ -125,11 +100,10 @@ public function testIdCannotBeEmptyStringForDelete() public function testIndexCannotBeArrayOfEmptyStringsForDelete() { - $client = $this->getClient(); - - $this->expectException(Missing404Exception::class); + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('index is required for delete'); - $client->delete( + $this->client->delete( [ 'index' => ['', '', ''], 'id' => 'test', @@ -139,11 +113,10 @@ public function testIndexCannotBeArrayOfEmptyStringsForDelete() public function testIndexCannotBeArrayOfNullsForDelete() { - $client = $this->getClient(); + $this->expectException(RuntimeException::class); + $this->expectExceptionMessage('index is required for delete'); - $this->expectException(Missing404Exception::class); - - $client->delete( + $this->client->delete( [ 'index' => [null, null, null], 'id' => 'test', @@ -154,9 +127,7 @@ public function testIndexCannotBeArrayOfNullsForDelete() /** @test */ public function sendRawRequest(): void { - $client = $this->getClient(); - - $response = $client->request('GET', '/'); + $response = $this->client->request('GET', '/'); $this->assertIsArray($response); $expectedKeys = ['name', 'cluster_name', 'cluster_uuid', 'version', 'tagline']; @@ -168,10 +139,9 @@ public function sendRawRequest(): void /** @test */ public function insertDocumentUsingRawRequest(): void { - $client = $this->getClient(); - $randomIndex = 'test_index_' .time(); + $randomIndex = 'test_index_' . time(); - $response = $client->request('POST', "/$randomIndex/_doc", ['body' => ['field' => 'value']]); + $response = $this->client->request('POST', "/$randomIndex/_doc", ['body' => ['field' => 'value']]); $this->assertIsArray($response); $this->assertArrayHasKey('_index', $response); @@ -181,14 +151,42 @@ public function insertDocumentUsingRawRequest(): void $this->assertSame('created', $response['result']); } - private function getLevelOutput(string $level, array $output): string + private function getClient(): Client { - foreach ($output as $out) { - if (false !== strpos($out, $level)) { - return $out; - } - } + $guzzleClient = new GuzzleClient([ + 'base_uri' => Utility::getHost(), + 'auth' => ['admin', getenv('OPENSEARCH_INITIAL_ADMIN_PASSWORD')], + 'verify' => false, + 'retries' => 2, + 'headers' => [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + 'User-Agent' => sprintf( + 'opensearch-php/%s (%s; PHP %s)', + Client::VERSION, + PHP_OS, + PHP_VERSION + ), + ] + ]); - return ''; + $guzzleHttpFactory = new HttpFactory(); + $serializer = new SmartSerializer(); + + $requestFactory = new RequestFactory( + $guzzleHttpFactory, + $guzzleHttpFactory, + $guzzleHttpFactory, + $serializer, + ); + + $transport = (new TransportFactory()) + ->setHttpClient($guzzleClient) + ->setRequestFactory($requestFactory) + ->create(); + + $endpointFactory = new EndpointFactory(); + return new Client($transport, $endpointFactory, []); } + } diff --git a/tests/ClientTest.php b/tests/ClientTest.php index ce5a2bc7..9696828f 100644 --- a/tests/ClientTest.php +++ b/tests/ClientTest.php @@ -25,12 +25,9 @@ use OpenSearch\Common\Exceptions\RuntimeException; use OpenSearch\EndpointFactoryInterface; use OpenSearch\Endpoints\Delete; -use OpenSearch\Transport; use OpenSearch\TransportInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -use Psr\Http\Message\RequestInterface; -use Psr\Http\Message\ResponseInterface; /** * Class ClientTest diff --git a/tests/LegacyClientIntegrationTest.php b/tests/LegacyClientIntegrationTest.php new file mode 100644 index 00000000..81e92430 --- /dev/null +++ b/tests/LegacyClientIntegrationTest.php @@ -0,0 +1,195 @@ +host = Utility::getHost(); + $this->logger = new ArrayLogger(); + } + + private function getClient(): Client + { + $client = ClientBuilder::create() + ->setHosts([$this->host]) + ->setLogger($this->logger) + ->setSSLVerification(false); + + return $client->build(); + } + + public function testLogRequestSuccessHasInfoNotEmpty() + { + $client = $this->getClient(); + + $result = $client->info(); + + $this->assertNotEmpty($this->getLevelOutput(LogLevel::INFO, $this->logger->output)); + } + + public function testLogRequestSuccessHasPortInInfo() + { + $client = $this->getClient(); + + $result = $client->info(); + + $this->assertStringContainsString('"port"', $this->getLevelOutput(LogLevel::INFO, $this->logger->output)); + } + + public function testLogRequestFailHasWarning() + { + $this->expectException(Missing404Exception::class); + $this->expectExceptionMessage('no such index [foo]'); + + $client = $this->getClient(); + $client->get([ + 'index' => 'foo', + 'id' => 'bar', + ]); + + } + + public function testIndexCannotBeEmptyStringForDelete() + { + $client = $this->getClient(); + + $this->expectException(RuntimeException::class); + + $client->delete( + [ + 'index' => '', + 'id' => 'test', + ] + ); + } + + public function testIdCannotBeEmptyStringForDelete() + { + $client = $this->getClient(); + + $this->expectException(RuntimeException::class); + + $client->delete( + [ + 'index' => 'test', + 'id' => '', + ] + ); + } + + public function testIndexCannotBeArrayOfEmptyStringsForDelete() + { + $client = $this->getClient(); + + $this->expectException(RuntimeException::class); + + $client->delete( + [ + 'index' => ['', '', ''], + 'id' => 'test', + ] + ); + } + + public function testIndexCannotBeArrayOfNullsForDelete() + { + $client = $this->getClient(); + + $this->expectException(RuntimeException::class); + + $client->delete( + [ + 'index' => [null, null, null], + 'id' => 'test', + ] + ); + } + + /** @test */ + public function sendRawRequest(): void + { + $client = $this->getClient(); + + $response = $client->request('GET', '/'); + + $this->assertIsArray($response); + $expectedKeys = ['name', 'cluster_name', 'cluster_uuid', 'version', 'tagline']; + foreach ($expectedKeys as $key) { + $this->assertArrayHasKey($key, $response); + } + } + + /** @test */ + public function insertDocumentUsingRawRequest(): void + { + $client = $this->getClient(); + $randomIndex = 'test_index_' .time(); + + $response = $client->request('POST', "/$randomIndex/_doc", ['body' => ['field' => 'value']]); + + $this->assertIsArray($response); + $this->assertArrayHasKey('_index', $response); + $this->assertSame($randomIndex, $response['_index']); + $this->assertArrayHasKey('_id', $response); + $this->assertArrayHasKey('result', $response); + $this->assertSame('created', $response['result']); + } + + private function getLevelOutput(string $level, array $output): string + { + foreach ($output as $out) { + if (false !== strpos($out, $level)) { + return $out; + } + } + + return ''; + } +} diff --git a/tests/Namespaces/MachineLearningNamespaceTest.php b/tests/Namespaces/MlNamespaceTest.php similarity index 63% rename from tests/Namespaces/MachineLearningNamespaceTest.php rename to tests/Namespaces/MlNamespaceTest.php index 9001bfe9..85cfbeba 100644 --- a/tests/Namespaces/MachineLearningNamespaceTest.php +++ b/tests/Namespaces/MlNamespaceTest.php @@ -1,29 +1,28 @@ method('getEndpoint') ->willReturn(new CreateConnector()); - $transport = $this->createMock(Transport::class); - - $transport->method('performRequest') - ->with('POST', '/_plugins/_ml/connectors/_create', [], [ - 'foo' => 'bar', - ]); + $transport = $this->createMock(TransportInterface::class); - $transport->method('resultOrFuture') - ->willReturn([]); + $transport->method('sendRequest') + ->with('POST', '/_plugins/_ml/connectors/_create', [], [ + 'foo' => 'bar', + ]) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->createConnector([ 'body' => [ @@ -67,16 +64,15 @@ public function testGetConnector(): void $endpointFactory->method('getEndpoint') ->willReturn(new GetConnector()); - $transport = $this->createMock(Transport::class); + $transport = $this->createMock(TransportInterface::class); - $transport->method('performRequest') - ->with('GET', '/_plugins/_ml/connectors/foobar', [], null); - - $transport->method('resultOrFuture') - ->willReturn([]); + $transport->method('sendRequest') + ->with('GET', '/_plugins/_ml/connectors/foobar', [], null) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->getConnector([ - 'id' => 'foobar' + 'id' => 'foobar', + 'connector_id' => 'foobar' ]); } @@ -87,18 +83,16 @@ public function testGetConnectors(): void $endpointFactory->method('getEndpoint') ->willReturn(new GetConnectors()); - $transport = $this->createMock(Transport::class); + $transport = $this->createMock(TransportInterface::class); - $transport->method('performRequest') + $transport->method('sendRequest') ->with('POST', '/_plugins/_ml/connectors/_search', [], [ 'query' => [ 'match_all' => new \StdClass(), ], 'size' => 1000, - ]); - - $transport->method('resultOrFuture') - ->willReturn([]); + ]) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->getConnectors([ 'body' => [ @@ -117,13 +111,11 @@ public function testDeleteConnector(): void $endpointFactory->method('getEndpoint') ->willReturn(new DeleteConnector()); - $transport = $this->createMock(Transport::class); + $transport = $this->createMock(TransportInterface::class); - $transport->method('performRequest') - ->with('DELETE', '/_plugins/_ml/connectors/foobar', [], null); - - $transport->method('resultOrFuture') - ->willReturn([]); + $transport->method('sendRequest') + ->with('DELETE', '/_plugins/_ml/connectors/foobar', [], null) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->deleteConnector([ 'connector_id' => 'foobar' @@ -137,15 +129,13 @@ public function testRegisterModelGroup(): void $endpointFactory->method('getEndpoint') ->willReturn(new RegisterModelGroup()); - $transport = $this->createMock(Transport::class); - - $transport->method('performRequest') - ->with('POST', '/_plugins/_ml/model_groups/_register', [], [ - 'foo' => 'bar', - ]); + $transport = $this->createMock(TransportInterface::class); - $transport->method('resultOrFuture') - ->willReturn([]); + $transport->method('sendRequest') + ->with('POST', '/_plugins/_ml/model_groups/_register', [], [ + 'foo' => 'bar', + ]) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->registerModelGroup([ 'body' => [ @@ -161,18 +151,16 @@ public function testGetModelGroups(): void $endpointFactory->method('getEndpoint') ->willReturn(new GetModelGroups()); - $transport = $this->createMock(Transport::class); + $transport = $this->createMock(TransportInterface::class); - $transport->method('performRequest') - ->with('POST', '/_plugins/_ml/model_groups/_search', [], [ - 'query' => [ - 'match_all' => new \StdClass(), - ], - 'size' => 1000, - ]); - - $transport->method('resultOrFuture') - ->willReturn([]); + $transport->method('sendRequest') + ->with('POST', '/_plugins/_ml/model_groups/_search', [], [ + 'query' => [ + 'match_all' => new \StdClass(), + ], + 'size' => 1000, + ]) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->getModelGroups([ 'body' => [ @@ -191,21 +179,20 @@ public function testUpdateModelGroup(): void $endpointFactory->method('getEndpoint') ->willReturn(new UpdateModelGroup()); - $transport = $this->createMock(Transport::class); + $transport = $this->createMock(TransportInterface::class); - $transport->method('performRequest') - ->with('PUT', '/_plugins/_ml/model_groups/foobar', [], [ - 'query' => [ - 'match_all' => new \StdClass(), - ], - 'size' => 1000, - ]); - - $transport->method('resultOrFuture') - ->willReturn([]); + $transport->method('sendRequest') + ->with('PUT', '/_plugins/_ml/model_groups/foobar', [], [ + 'query' => [ + 'match_all' => new \StdClass(), + ], + 'size' => 1000, + ]) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->updateModelGroup([ 'id' => 'foobar', + 'model_group_id' => 'foobar', 'body' => [ 'query' => [ 'match_all' => new \StdClass(), @@ -222,13 +209,11 @@ public function testDeleteModelGroup(): void $endpointFactory->method('getEndpoint') ->willReturn(new DeleteModelGroup()); - $transport = $this->createMock(Transport::class); + $transport = $this->createMock(TransportInterface::class); - $transport->method('performRequest') - ->with('DELETE', '/_plugins/_ml/model_groups/foobar', [], null); - - $transport->method('resultOrFuture') - ->willReturn([]); + $transport->method('sendRequest') + ->with('DELETE', '/_plugins/_ml/model_groups/foobar', [], null) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->deleteModelGroup([ 'id' => 'foobar' @@ -242,15 +227,13 @@ public function testRegisterModel(): void $endpointFactory->method('getEndpoint') ->willReturn(new RegisterModel()); - $transport = $this->createMock(Transport::class); - - $transport->method('performRequest') - ->with('POST', '/_plugins/_ml/models/_register', [], [ - 'foo' => 'bar', - ]); + $transport = $this->createMock(TransportInterface::class); - $transport->method('resultOrFuture') - ->willReturn([]); + $transport->method('sendRequest') + ->with('POST', '/_plugins/_ml/models/_register', [], [ + 'foo' => 'bar', + ]) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->registerModel([ 'body' => [ @@ -265,13 +248,11 @@ public function testGetModel(): void $endpointFactory->method('getEndpoint') ->willReturn(new GetModel()); - $transport = $this->createMock(Transport::class); + $transport = $this->createMock(TransportInterface::class); - $transport->method('performRequest') - ->with('GET', '/_plugins/_ml/models/foobar', [], null); - - $transport->method('resultOrFuture') - ->willReturn([]); + $transport->method('sendRequest') + ->with('GET', '/_plugins/_ml/models/foobar', [], null) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->getModel([ 'id' => 'foobar', @@ -284,18 +265,16 @@ public function testSearchModels(): void $endpointFactory->method('getEndpoint') ->willReturn(new SearchModels()); - $transport = $this->createMock(Transport::class); + $transport = $this->createMock(TransportInterface::class); - $transport->method('performRequest') + $transport->method('sendRequest') ->with('GET', '/_plugins/_ml/models/_search', [], [ 'query' => [ 'match_all' => new \StdClass(), ], 'size' => 1000, - ]); - - $transport->method('resultOrFuture') - ->willReturn([]); + ]) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->searchModels([ 'body' => [ @@ -313,13 +292,11 @@ public function testDeployModel(): void $endpointFactory->method('getEndpoint') ->willReturn(new DeployModel()); - $transport = $this->createMock(Transport::class); - - $transport->method('performRequest') - ->with('POST', '/_plugins/_ml/models/foobar/_deploy', [], null); + $transport = $this->createMock(TransportInterface::class); - $transport->method('resultOrFuture') - ->willReturn([]); + $transport->method('sendRequest') + ->with('POST', '/_plugins/_ml/models/foobar/_deploy', [], null) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->deployModel([ 'model_id' => 'foobar', @@ -332,13 +309,11 @@ public function testUnDeployModel(): void $endpointFactory->method('getEndpoint') ->willReturn(new UndeployModel()); - $transport = $this->createMock(Transport::class); + $transport = $this->createMock(TransportInterface::class); - $transport->method('performRequest') - ->with('POST', '/_plugins/_ml/models/foobar/_undeploy', [], null); - - $transport->method('resultOrFuture') - ->willReturn([]); + $transport->method('sendRequest') + ->with('POST', '/_plugins/_ml/models/foobar/_undeploy', [], null) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->undeployModel([ 'model_id' => 'foobar', @@ -351,13 +326,11 @@ public function testDeleteModel(): void $endpointFactory->method('getEndpoint') ->willReturn(new DeleteModel()); - $transport = $this->createMock(Transport::class); - - $transport->method('performRequest') - ->with('DELETE', '/_plugins/_ml/models/foobar', [], null); + $transport = $this->createMock(TransportInterface::class); - $transport->method('resultOrFuture') - ->willReturn([]); + $transport->method('sendRequest') + ->with('DELETE', '/_plugins/_ml/models/foobar', [], null) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->deleteModel([ 'id' => 'foobar', @@ -370,21 +343,21 @@ public function testPredict(): void $endpointFactory->method('getEndpoint') ->willReturn(new Predict()); - $transport = $this->createMock(Transport::class); - - $transport->method('performRequest') - ->with('POST', '/_plugins/_ml/models/foobar/_predict', [], [ - 'foo' => 'bar', - ]); + $transport = $this->createMock(TransportInterface::class); - $transport->method('resultOrFuture') - ->willReturn([]); + $transport->method('sendRequest') + ->with('POST', '/_plugins/_ml/_predict/algo/model', [], [ + 'foo' => 'bar', + ]) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->predict([ - 'id' => 'foobar', - 'body' => [ - 'foo' => 'bar', - ] + 'id' => 'foobar', + 'body' => [ + 'foo' => 'bar', + ], + 'algorithm_name' => 'algo', + 'model_id' => 'model', ]); } @@ -394,13 +367,11 @@ public function testGetTask(): void $endpointFactory->method('getEndpoint') ->willReturn(new GetTask()); - $transport = $this->createMock(Transport::class); - - $transport->method('performRequest') - ->with('GET', '/_plugins/_ml/tasks/foobar', [], null); + $transport = $this->createMock(TransportInterface::class); - $transport->method('resultOrFuture') - ->willReturn([]); + $transport->method('sendRequest') + ->with('GET', '/_plugins/_ml/tasks/foobar', [], null) + ->willReturn([]); (new MlNamespace($transport, $endpointFactory))->getTask([ 'id' => 'foobar', diff --git a/tests/Namespaces/SecurityNamespaceTest.php b/tests/Namespaces/SecurityNamespaceTest.php index 9c4a6e2e..55c69bca 100644 --- a/tests/Namespaces/SecurityNamespaceTest.php +++ b/tests/Namespaces/SecurityNamespaceTest.php @@ -15,11 +15,10 @@ namespace OpenSearch\Tests\Namespaces; -use OpenSearch\Client; -use OpenSearch\ClientBuilder; use OpenSearch\Common\Exceptions\RuntimeException; +use OpenSearch\EndpointFactory; use OpenSearch\Namespaces\SecurityNamespace; -use OpenSearch\Transport; +use OpenSearch\TransportInterface; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use ReflectionClass; @@ -28,22 +27,15 @@ class SecurityNamespaceTest extends TestCase { - /** - * @var Client - */ - private $client; - /** - * @var Transport|MockObject - */ - private $transport; + private SecurityNamespace $securityNamespace; + + private TransportInterface&MockObject $transport; protected function setUp(): void { - $this->transport = $this->createMock(Transport::class); - $this->client = ClientBuilder::create() - ->setTransport($this->transport) - ->setSSLVerification(false) - ->build(); + parent::setUp(); + $this->transport = $this->createMock(TransportInterface::class); + $this->securityNamespace = new SecurityNamespace($this->transport, new EndpointFactory()); } /** @@ -51,14 +43,17 @@ protected function setUp(): void */ public function methodProvider(): array { - return array_map(function (ReflectionMethod $method) { - return [$method->name]; - }, array_filter( - (new ReflectionClass(SecurityNamespace::class))->getMethods(), + return array_map( function (ReflectionMethod $method) { - return $method->class === SecurityNamespace::class; - } - )); + return [$method->name]; + }, + array_filter( + (new ReflectionClass(SecurityNamespace::class))->getMethods(), + function (ReflectionMethod $method) { + return $method->class === SecurityNamespace::class; + } + ) + ); } /** @@ -69,25 +64,24 @@ public function testWithInvalidParams(string $methodName): void $this->expectException(UnexpectedValueException::class); $this->expectExceptionMessage('"invalid" is not a valid parameter.'); - $this->client->security()->$methodName([ + $this->securityNamespace->$methodName([ 'invalid' => 'abc', ]); } public function testChangePassword(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PUT', '/_plugins/_security/api/account', [], [ 'password' => 'abc', 'current_password' => 'abc', - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $result = $this->client->security()->changePassword([ + $result = $this->securityNamespace->changePassword([ 'password' => 'abc', 'current_password' => 'abc' ]); @@ -100,17 +94,16 @@ public function testChangePassword(): void public function testCreateActionGroup(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PUT', '/_plugins/_security/api/actiongroups/my_test_action_group', [], [ 'allowed_actions' => ['indices:data/read*'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $result = $this->client->security()->createActionGroup([ + $result = $this->securityNamespace->createActionGroup([ 'action_group' => 'my_test_action_group', 'allowed_actions' => ['indices:data/read*'] ]); @@ -126,14 +119,14 @@ public function testCreateActionGroupThrowsWithoutActionGroup(): void $this->expectException(RuntimeException::class); $this->expectExceptionMessage('action_group is required for create_action_group'); - $this->client->security()->createActionGroup([ + $this->securityNamespace->createActionGroup([ 'allowed_actions' => ['indices:data/read*'] ]); } public function testCreateRole(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PUT', '/_plugins/_security/api/roles/my_test_role', [], [ 'cluster_permissions' => [ 'cluster_composite_ops', @@ -162,14 +155,13 @@ public function testCreateRole(): void ] ] ] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $result = $this->client->security()->createRole([ + $result = $this->securityNamespace->createRole([ 'role' => 'my_test_role', 'cluster_permissions' => [ 'cluster_composite_ops', @@ -211,7 +203,7 @@ public function testCreateRoleThrowsWithoutRole(): void $this->expectException(RuntimeException::class); $this->expectExceptionMessage('role is required for create_role'); - $this->client->security()->createRole([ + $this->securityNamespace->createRole([ 'cluster_permissions' => [], 'index_permissions' => [ [ @@ -226,19 +218,18 @@ public function testCreateRoleThrowsWithoutRole(): void public function testCreateRoleMapping(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PUT', '/_plugins/_security/api/rolesmapping/my_test_role_mapping', [], [ 'backend_roles' => ['starfleet', 'captains', 'defectors', 'cn=ldaprole,ou=groups,dc=example,dc=com'], 'hosts' => ['*.starfleetintranet.com'], 'users' => ['worf'], - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $result = $this->client->security()->createRoleMapping([ + $result = $this->securityNamespace->createRoleMapping([ 'role' => 'my_test_role_mapping', 'backend_roles' => ['starfleet', 'captains', 'defectors', 'cn=ldaprole,ou=groups,dc=example,dc=com'], 'hosts' => ['*.starfleetintranet.com'], @@ -256,7 +247,7 @@ public function testCreateRoleMappingThrowsWithoutRole(): void $this->expectException(RuntimeException::class); $this->expectExceptionMessage('role is required for create_role_mapping'); - $this->client->security()->createRoleMapping([ + $this->securityNamespace->createRoleMapping([ 'backend_roles' => ['starfleet', 'captains', 'defectors', 'cn=ldaprole,ou=groups,dc=example,dc=com'], 'hosts' => ['*.starfleetintranet.com'], 'users' => ['worf'], @@ -265,17 +256,16 @@ public function testCreateRoleMappingThrowsWithoutRole(): void public function testCreateTenant(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PUT', '/_plugins/_security/api/tenants/my_test_tenant', [], [ 'description' => 'My test tenant' - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $result = $this->client->security()->createTenant([ + $result = $this->securityNamespace->createTenant([ 'tenant' => 'my_test_tenant', 'description' => 'My test tenant' ]); @@ -291,14 +281,14 @@ public function testCreateTenantThrowsWithoutRole(): void $this->expectException(RuntimeException::class); $this->expectExceptionMessage('tenant is required for create_tenant'); - $this->client->security()->createTenant([ + $this->securityNamespace->createTenant([ 'description' => 'My test tenant' ]); } public function testCreateUser(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PUT', '/_plugins/_security/api/internalusers/my_test_username', [], [ 'password' => 'kirkpass', 'opendistro_security_roles' => ['maintenance_staff', 'weapons'], @@ -307,14 +297,13 @@ public function testCreateUser(): void 'attribute1' => 'value1', 'attribute2' => 'value2' ] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $result = $this->client->security()->createUser([ + $result = $this->securityNamespace->createUser([ 'username' => 'my_test_username', 'password' => 'kirkpass', 'opendistro_security_roles' => ['maintenance_staff', 'weapons'], @@ -336,7 +325,7 @@ public function testCreateUserThrowsWithoutUsername(): void $this->expectException(RuntimeException::class); $this->expectExceptionMessage('username is required for create_user'); - $this->client->security()->createUser([ + $this->securityNamespace->createUser([ 'password' => 'kirkpass', 'opendistro_security_roles' => ['maintenance_staff', 'weapons'], 'backend_roles' => ['captains', 'starfleet'], @@ -349,15 +338,14 @@ public function testCreateUserThrowsWithoutUsername(): void public function testDeleteActionGroup(): void { - $this->transport->method('performRequest') - ->with('DELETE', '/_plugins/_security/api/actiongroups/my_test_action_group', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('DELETE', '/_plugins/_security/api/actiongroups/my_test_action_group', [], null) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $result = $this->client->security()->deleteActionGroup([ + $result = $this->securityNamespace->deleteActionGroup([ 'action_group' => 'my_test_action_group', ]); @@ -372,20 +360,19 @@ public function testDeleteActionGroupThrowsWithoutActionGroupName(): void $this->expectException(RuntimeException::class); $this->expectExceptionMessage('action_group is required for delete_action_group'); - $this->client->security()->deleteActionGroup(); + $this->securityNamespace->deleteActionGroup(); } public function testDeleteDistinguishedNames(): void { - $this->transport->method('performRequest') - ->with('DELETE', '/_plugins/_security/api/nodesdn/my_test_cluster', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('DELETE', '/_plugins/_security/api/nodesdn/my_test_cluster', [], null) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $result = $this->client->security()->deleteDistinguishedNames([ + $result = $this->securityNamespace->deleteDistinguishedNames([ 'cluster_name' => 'my_test_cluster', ]); @@ -397,15 +384,14 @@ public function testDeleteDistinguishedNames(): void public function testDeleteDistinguishedName(): void { - $this->transport->method('performRequest') - ->with('DELETE', '/_plugins/_security/api/nodesdn/my_test_cluster', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('DELETE', '/_plugins/_security/api/nodesdn/my_test_cluster', [], null) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $result = $this->client->security()->deleteDistinguishedName([ + $result = $this->securityNamespace->deleteDistinguishedName([ 'cluster_name' => 'my_test_cluster', ]); @@ -420,20 +406,19 @@ public function testDeleteDistinguishedNamesThrowsWithoutRoleName(): void $this->expectException(RuntimeException::class); $this->expectExceptionMessage('cluster_name is required for delete_distinguished_name'); - $this->client->security()->deleteDistinguishedNames(); + $this->securityNamespace->deleteDistinguishedNames(); } public function testDeleteRole(): void { - $this->transport->method('performRequest') - ->with('DELETE', '/_plugins/_security/api/roles/my_test_role', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('DELETE', '/_plugins/_security/api/roles/my_test_role', [], null) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $result = $this->client->security()->deleteRole([ + $result = $this->securityNamespace->deleteRole([ 'role' => 'my_test_role', ]); @@ -448,20 +433,19 @@ public function testDeleteRoleThrowsWithoutRole(): void $this->expectException(RuntimeException::class); $this->expectExceptionMessage('role is required for delete_role'); - $this->client->security()->deleteRole(); + $this->securityNamespace->deleteRole(); } public function testDeleteRoleMapping(): void { - $this->transport->method('performRequest') - ->with('DELETE', '/_plugins/_security/api/rolesmapping/my_test_role_mapping', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('DELETE', '/_plugins/_security/api/rolesmapping/my_test_role_mapping', [], null) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $result = $this->client->security()->deleteRoleMapping([ + $result = $this->securityNamespace->deleteRoleMapping([ 'role' => 'my_test_role_mapping', ]); @@ -476,20 +460,19 @@ public function testDeleteRoleMappingThrowsWithoutRoleMappingName(): void $this->expectException(RuntimeException::class); $this->expectExceptionMessage('role is required for delete_role_mapping'); - $this->client->security()->deleteRoleMapping(); + $this->securityNamespace->deleteRoleMapping(); } public function testDeleteTenant(): void { - $this->transport->method('performRequest') - ->with('DELETE', '/_plugins/_security/api/tenants/my_test_tenant', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('DELETE', '/_plugins/_security/api/tenants/my_test_tenant', [], null) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $result = $this->client->security()->deleteTenant([ + $result = $this->securityNamespace->deleteTenant([ 'tenant' => 'my_test_tenant', ]); @@ -504,20 +487,19 @@ public function testDeleteTenantThrowsWithoutTenantName(): void $this->expectException(RuntimeException::class); $this->expectExceptionMessage('tenant is required for delete_tenant'); - $this->client->security()->deleteTenant(); + $this->securityNamespace->deleteTenant(); } public function testDeleteUser(): void { - $this->transport->method('performRequest') - ->with('DELETE', '/_plugins/_security/api/internalusers/my_test_user', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('DELETE', '/_plugins/_security/api/internalusers/my_test_user', [], null) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $result = $this->client->security()->deleteUser([ + $result = $this->securityNamespace->deleteUser([ 'username' => 'my_test_user', ]); @@ -532,27 +514,26 @@ public function testDeleteUserThrowsWithoutUsername(): void $this->expectException(RuntimeException::class); $this->expectExceptionMessage('username is required for delete_user'); - $this->client->security()->deleteUser(); + $this->securityNamespace->deleteUser(); } public function testFlushCache(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('DELETE', '/_plugins/_security/api/cache', [], null); - $this->client->security()->flushCache(); + $this->securityNamespace->flushCache(); } public function testGetAccount(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/account', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/account', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getAccount(); + $response = $this->securityNamespace->getAccount(); static::assertSame([ 'resource' => ['test_resource'] @@ -561,14 +542,13 @@ public function testGetAccount(): void public function testGetAccountDetails(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/account', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/account', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getAccountDetails(); + $response = $this->securityNamespace->getAccountDetails(); static::assertSame([ 'resource' => ['test_resource'] @@ -577,14 +557,13 @@ public function testGetAccountDetails(): void public function testGetActionGroups(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/actiongroups/my_test_action_group', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/actiongroups/my_test_action_group', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getActionGroups([ + $response = $this->securityNamespace->getActionGroups([ 'action_group' => 'my_test_action_group', ]); @@ -595,14 +574,13 @@ public function testGetActionGroups(): void public function testGetActionGroupsWithoutActionGroupName(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/actiongroups', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/actiongroups', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getActionGroups(); + $response = $this->securityNamespace->getActionGroups(); static::assertSame([ 'resource' => ['test_resource'] @@ -611,14 +589,13 @@ public function testGetActionGroupsWithoutActionGroupName(): void public function testGetActionGroup(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/actiongroups/my_test_action_group', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/actiongroups/my_test_action_group', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getActionGroup([ + $response = $this->securityNamespace->getActionGroup([ 'action_group' => 'my_test_action_group', ]); @@ -629,14 +606,13 @@ public function testGetActionGroup(): void public function testGetCertificates(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/ssl/certs', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/ssl/certs', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getCertificates(); + $response = $this->securityNamespace->getCertificates(); static::assertSame([ 'resource' => ['test_resource'], @@ -645,14 +621,13 @@ public function testGetCertificates(): void public function testGetConfig(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/securityconfig', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/securityconfig', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getConfig(); + $response = $this->securityNamespace->getConfig(); static::assertSame([ 'resource' => ['test_resource'], @@ -661,14 +636,13 @@ public function testGetConfig(): void public function testGetConfiguration(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/securityconfig', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/securityconfig', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getConfiguration(); + $response = $this->securityNamespace->getConfiguration(); static::assertSame([ 'resource' => ['test_resource'], @@ -677,14 +651,13 @@ public function testGetConfiguration(): void public function testGetDistinguishedNames(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/nodesdn/my_test_cluster', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/nodesdn/my_test_cluster', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getDistinguishedNames([ + $response = $this->securityNamespace->getDistinguishedNames([ 'cluster_name' => 'my_test_cluster', ]); @@ -695,14 +668,13 @@ public function testGetDistinguishedNames(): void public function testGetDistinguishedNamesWithoutClusterName(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/nodesdn', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/nodesdn', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getDistinguishedNames(); + $response = $this->securityNamespace->getDistinguishedNames(); static::assertSame([ 'resource' => ['test_resource'] @@ -711,14 +683,13 @@ public function testGetDistinguishedNamesWithoutClusterName(): void public function testGetDistinguishedName(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/nodesdn/my_test_cluster', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/nodesdn/my_test_cluster', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getDistinguishedName([ + $response = $this->securityNamespace->getDistinguishedName([ 'cluster_name' => 'my_test_cluster', ]); @@ -729,14 +700,13 @@ public function testGetDistinguishedName(): void public function testGetRoleMappings(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/rolesmapping/my_test_role', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/rolesmapping/my_test_role', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getRoleMappings([ + $response = $this->securityNamespace->getRoleMappings([ 'role' => 'my_test_role', ]); @@ -747,14 +717,13 @@ public function testGetRoleMappings(): void public function testGetRoleMappingsWithoutRoleName(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/rolesmapping', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/rolesmapping', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getRoleMappings(); + $response = $this->securityNamespace->getRoleMappings(); static::assertSame([ 'resource' => ['test_resource'] @@ -763,14 +732,13 @@ public function testGetRoleMappingsWithoutRoleName(): void public function testGetRoleMapping(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/rolesmapping/my_test_role', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/rolesmapping/my_test_role', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getRoleMapping([ + $response = $this->securityNamespace->getRoleMapping([ 'role' => 'my_test_role', ]); @@ -781,14 +749,13 @@ public function testGetRoleMapping(): void public function testGetRoles(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/roles/my_test_role', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/roles/my_test_role', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getRoles([ + $response = $this->securityNamespace->getRoles([ 'role' => 'my_test_role', ]); @@ -799,14 +766,13 @@ public function testGetRoles(): void public function testGetRolesWithoutActionGroupName(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/roles', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/roles', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getRoles(); + $response = $this->securityNamespace->getRoles(); static::assertSame([ 'resource' => ['test_resource'] @@ -815,14 +781,13 @@ public function testGetRolesWithoutActionGroupName(): void public function testGetRole(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/roles/my_test_role', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/roles/my_test_role', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getRole([ + $response = $this->securityNamespace->getRole([ 'role' => 'my_test_role', ]); @@ -833,14 +798,13 @@ public function testGetRole(): void public function testGetTenants(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/tenants/my_test_tenant', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/tenants/my_test_tenant', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getTenants([ + $response = $this->securityNamespace->getTenants([ 'tenant' => 'my_test_tenant', ]); @@ -851,14 +815,13 @@ public function testGetTenants(): void public function testGetTenantsWithoutTenantName(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/tenants', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/tenants', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getTenants(); + $response = $this->securityNamespace->getTenants(); static::assertSame([ 'resource' => ['test_resource'] @@ -867,14 +830,13 @@ public function testGetTenantsWithoutTenantName(): void public function testGetTenant(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/tenants/my_test_tenant', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/tenants/my_test_tenant', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getTenant([ + $response = $this->securityNamespace->getTenant([ 'tenant' => 'my_test_tenant', ]); @@ -885,14 +847,13 @@ public function testGetTenant(): void public function testGetUsers(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/internalusers/my_test_user', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/internalusers/my_test_user', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getUsers([ + $response = $this->securityNamespace->getUsers([ 'username' => 'my_test_user', ]); @@ -903,14 +864,13 @@ public function testGetUsers(): void public function testGetUsersWithoutUsername(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/internalusers', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/internalusers', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getUsers(); + $response = $this->securityNamespace->getUsers(); static::assertSame([ 'resource' => ['test_resource'] @@ -919,14 +879,13 @@ public function testGetUsersWithoutUsername(): void public function testGetUser(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/api/internalusers/my_test_user', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/api/internalusers/my_test_user', [], null) ->willReturn([ 'resource' => ['test_resource'], ]); - $response = $this->client->security()->getUser([ + $response = $this->securityNamespace->getUser([ 'username' => 'my_test_user', ]); @@ -937,15 +896,14 @@ public function testGetUser(): void public function testHealth(): void { - $this->transport->method('performRequest') - ->with('GET', '/_plugins/_security/health', [], null); - $this->transport->method('resultOrFuture') + $this->transport->method('sendRequest') + ->with('GET', '/_plugins/_security/health', [], null) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->health(); + $response = $this->securityNamespace->health(); static::assertSame([ 'status' => 'OK', @@ -955,17 +913,16 @@ public function testHealth(): void public function testPatchActionGroups(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/actiongroups/my_test_action_group', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchActionGroups([ + $response = $this->securityNamespace->patchActionGroups([ 'action_group' => 'my_test_action_group', 'ops' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] @@ -980,17 +937,16 @@ public function testPatchActionGroups(): void public function testPatchActionGroupsWithoutActionGroupName(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/actiongroups', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchActionGroups([ + $response = $this->securityNamespace->patchActionGroups([ 'ops' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] ] @@ -1004,17 +960,16 @@ public function testPatchActionGroupsWithoutActionGroupName(): void public function testPatchActionGroup(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/actiongroups/my_test_action_group', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchActionGroup([ + $response = $this->securityNamespace->patchActionGroup([ 'action_group' => 'my_test_action_group', 'body' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] @@ -1029,17 +984,16 @@ public function testPatchActionGroup(): void public function testPatchConfig(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/securityconfig', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchConfig([ + $response = $this->securityNamespace->patchConfig([ 'ops' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] ] @@ -1053,17 +1007,16 @@ public function testPatchConfig(): void public function testPatchConfiguration(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/securityconfig', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchConfiguration([ + $response = $this->securityNamespace->patchConfiguration([ 'body' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] ] @@ -1077,17 +1030,16 @@ public function testPatchConfiguration(): void public function testPatchRoleMappings(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/rolesmapping/my_test_role_mapping', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchRoleMappings([ + $response = $this->securityNamespace->patchRoleMappings([ 'role' => 'my_test_role_mapping', 'ops' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] @@ -1102,17 +1054,16 @@ public function testPatchRoleMappings(): void public function testPatchRoleMappingsWithoutRoleMappingName(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/rolesmapping', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchRoleMappings([ + $response = $this->securityNamespace->patchRoleMappings([ 'ops' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] ] @@ -1126,17 +1077,16 @@ public function testPatchRoleMappingsWithoutRoleMappingName(): void public function testPatchRoleMapping(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/rolesmapping/my_test_role_mapping', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchRoleMapping([ + $response = $this->securityNamespace->patchRoleMapping([ 'role' => 'my_test_role_mapping', 'body' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] @@ -1151,17 +1101,16 @@ public function testPatchRoleMapping(): void public function testPatchRoles(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/roles/my_test_role', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchRoles([ + $response = $this->securityNamespace->patchRoles([ 'role' => 'my_test_role', 'ops' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] @@ -1176,17 +1125,16 @@ public function testPatchRoles(): void public function testPatchRolesWithoutRoleName(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/roles', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchRoles([ + $response = $this->securityNamespace->patchRoles([ 'ops' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] ] @@ -1200,17 +1148,16 @@ public function testPatchRolesWithoutRoleName(): void public function testPatchRole(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/roles/my_test_role', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchRole([ + $response = $this->securityNamespace->patchRole([ 'role' => 'my_test_role', 'body' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] @@ -1225,17 +1172,16 @@ public function testPatchRole(): void public function testPatchTenants(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/tenants/my_test_tenant', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchTenants([ + $response = $this->securityNamespace->patchTenants([ 'tenant' => 'my_test_tenant', 'ops' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] @@ -1250,17 +1196,16 @@ public function testPatchTenants(): void public function testPatchTenantsWithoutRoleName(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/tenants', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchTenants([ + $response = $this->securityNamespace->patchTenants([ 'ops' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] ] @@ -1274,17 +1219,16 @@ public function testPatchTenantsWithoutRoleName(): void public function testPatchTenant(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/tenants/my_test_tenant', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchTenant([ + $response = $this->securityNamespace->patchTenant([ 'tenant' => 'my_test_tenant', 'body' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] @@ -1299,17 +1243,16 @@ public function testPatchTenant(): void public function testPatchUsers(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/internalusers/my_test_user', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchUsers([ + $response = $this->securityNamespace->patchUsers([ 'username' => 'my_test_user', 'ops' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] @@ -1324,17 +1267,16 @@ public function testPatchUsers(): void public function testPatchUsersWithoutUsername(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/internalusers', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchUsers([ + $response = $this->securityNamespace->patchUsers([ 'ops' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] ] @@ -1348,17 +1290,16 @@ public function testPatchUsersWithoutUsername(): void public function testPatchUser(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PATCH', '/_plugins/_security/api/internalusers/my_test_user', [], [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->patchUser([ + $response = $this->securityNamespace->patchUser([ 'username' => 'my_test_user', 'body' => [ ['op' => 'remove', 'path' => '/index_permissions/0/dls'] @@ -1373,19 +1314,18 @@ public function testPatchUser(): void public function testUpdateConfig(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PUT', '/_plugins/_security/api/securityconfig/config', [], [ 'dynamic' => [ 'filtered_alias_mode' => 'warn', ] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->updateConfig([ + $response = $this->securityNamespace->updateConfig([ 'dynamic' => [ 'filtered_alias_mode' => 'warn', ] @@ -1399,19 +1339,18 @@ public function testUpdateConfig(): void public function testUpdateConfiguration(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PUT', '/_plugins/_security/api/securityconfig/config', [], [ 'dynamic' => [ 'filtered_alias_mode' => 'warn', ] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->updateConfiguration([ + $response = $this->securityNamespace->updateConfiguration([ 'body' => [ 'dynamic' => ['filtered_alias_mode' => 'warn',] ] @@ -1425,17 +1364,16 @@ public function testUpdateConfiguration(): void public function testUpdateDistinguishedNames(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PUT', '/_plugins/_security/api/nodesdn/my_test_cluster', [], [ 'nodes_dn' => ['CN=cluster3.example.com'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->updateDistinguishedNames([ + $response = $this->securityNamespace->updateDistinguishedNames([ 'cluster_name' => 'my_test_cluster', 'nodes_dn' => ['CN=cluster3.example.com'] ]); @@ -1448,21 +1386,20 @@ public function testUpdateDistinguishedNames(): void public function testUpdateDistinguishedName(): void { - $this->transport->method('performRequest') + $this->transport->method('sendRequest') ->with('PUT', '/_plugins/_security/api/nodesdn/my_test_cluster', [], [ 'nodes_dn' => ['CN=cluster3.example.com'] - ]); - $this->transport->method('resultOrFuture') + ]) ->willReturn([ 'status' => 'OK', 'message' => 'Stubbed response' ]); - $response = $this->client->security()->updateDistinguishedName([ + $response = $this->securityNamespace->updateDistinguishedName([ 'cluster_name' => 'my_test_cluster', 'body' => [ 'nodes_dn' => ['CN=cluster3.example.com'] - ] + ] ]); static::assertSame([ diff --git a/tests/Namespaces/SqlNamespaceTest.php b/tests/Namespaces/SqlNamespaceTest.php index dae5b5f6..24e51722 100644 --- a/tests/Namespaces/SqlNamespaceTest.php +++ b/tests/Namespaces/SqlNamespaceTest.php @@ -1,5 +1,7 @@ transport = $this->createMock(TransportInterface::class); + $this->sqlNamespace = new SqlNamespace($this->transport, new EndpointFactory()); + } + public function testQuery(): void { - $transport = $this->createMock(Transport::class); - $transport->method('performRequest') + $this->transport->method('sendRequest') ->with('POST', '/_plugins/_sql', [], [ 'query' => 'select * from test', - ]); - - $transport->method('resultOrFuture') - ->willReturn([]); - - $endpointFactory = $this->createMock(EndpointFactoryInterface::class); - $endpointFactory->method('getEndpoint') - ->willReturn(new Query()); + ]) + ->willReturn(['foo' => 'bar']); - (new SqlNamespace($transport, $endpointFactory))->query([ + $result = $this->sqlNamespace->query([ 'query' => 'select * from test', ]); + + $this->assertEquals(['foo' => 'bar'], $result); } public function testExplain(): void { - $transport = $this->createMock(Transport::class); - $transport->method('performRequest') + $this->transport->method('sendRequest') ->with('POST', '/_plugins/_sql/_explain', [], [ 'query' => 'select * from test', - ]); - - $transport->method('resultOrFuture') - ->willReturn([]); + ]) + ->willReturn(['foo' => 'bar']); - $endpointFactory = $this->createMock(EndpointFactoryInterface::class); - $endpointFactory->method('getEndpoint') - ->willReturn(new Explain()); - - (new SqlNamespace($transport, $endpointFactory))->explain([ + $result = $this->sqlNamespace->explain([ 'query' => 'select * from test', ]); + + $this->assertEquals(['foo' => 'bar'], $result); } public function testCloseCursor(): void { - $transport = $this->createMock(Transport::class); - $transport->method('performRequest') + $this->transport->method('sendRequest') ->with('POST', '/_plugins/_sql/close', [], [ 'cursor' => 'fooo', - ]); + ]) + ->willReturn(['foo' => 'bar']); - $transport->method('resultOrFuture') - ->willReturn([]); - - $endpointFactory = $this->createMock(EndpointFactoryInterface::class); - $endpointFactory->method('getEndpoint') - ->willReturn(new CursorClose()); - - (new SqlNamespace($transport, $endpointFactory))->closeCursor([ + $result = $this->sqlNamespace->closeCursor([ 'cursor' => 'fooo', ]); + + $this->assertEquals(['foo' => 'bar'], $result); } } diff --git a/tests/RegisteredNamespaceTest.php b/tests/RegisteredNamespaceTest.php index 117b550f..385955c4 100644 --- a/tests/RegisteredNamespaceTest.php +++ b/tests/RegisteredNamespaceTest.php @@ -53,7 +53,7 @@ public function testNonExistingNamespace() $builder = new FooNamespaceBuilder(); $client = ClientBuilder::create()->registerNamespace($builder)->build(); - $this->expectException(\OpenSearch\Common\Exceptions\BadMethodCallException::class); + $this->expectException(\BadMethodCallException::class); $this->expectExceptionMessage('Namespace [bar] not found'); $client->bar()->fooMethod(); diff --git a/util/EndpointProxies/ml/getConnectorProxy.php b/util/EndpointProxies/ml/getConnectorProxy.php index 739adfc5..a89d3034 100644 --- a/util/EndpointProxies/ml/getConnectorProxy.php +++ b/util/EndpointProxies/ml/getConnectorProxy.php @@ -13,9 +13,11 @@ public function getConnector(array $params = []): array { $id = $this->extractArgument($params, 'id'); + $connector_id = $this->extractArgument($params, 'connector_id'); $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\GetConnector::class); $endpoint->setParams($params); $endpoint->setId($id); + $endpoint->setConnectorId($connector_id); return $this->performRequest($endpoint); } diff --git a/util/EndpointProxies/ml/predictProxy.php b/util/EndpointProxies/ml/predictProxy.php index cc0e8f7d..2fedfe1f 100644 --- a/util/EndpointProxies/ml/predictProxy.php +++ b/util/EndpointProxies/ml/predictProxy.php @@ -15,10 +15,15 @@ public function predict(array $params = []): array { $id = $this->extractArgument($params, 'id'); $body = $this->extractArgument($params, 'body'); + $algorithm_name = $this->extractArgument($params, 'algorithm_name'); + $model_id = $this->extractArgument($params, 'model_id'); + $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\Predict::class); - $endpoint->setParams($params); - $endpoint->setId($id); - $endpoint->setBody($body); + $endpoint->setParams($params) + ->setId($id) + ->setBody($body) + ->setAlgorithmName($algorithm_name) + ->setModelId($model_id); return $this->performRequest($endpoint); } diff --git a/util/EndpointProxies/ml/updateModelGroupProxy.php b/util/EndpointProxies/ml/updateModelGroupProxy.php index aad4c72a..e3eb6577 100644 --- a/util/EndpointProxies/ml/updateModelGroupProxy.php +++ b/util/EndpointProxies/ml/updateModelGroupProxy.php @@ -14,11 +14,13 @@ public function updateModelGroup(array $params = []): array { $id = $this->extractArgument($params, 'id'); + $model_group_id = $this->extractArgument($params, 'model_group_id'); $body = $this->extractArgument($params, 'body'); $endpoint = $this->endpointFactory->getEndpoint(\OpenSearch\Endpoints\Ml\UpdateModelGroup::class); $endpoint->setParams($params); $endpoint->setBody($body); $endpoint->setId($id); + $endpoint->setModelGroupId($model_group_id); return $this->performRequest($endpoint); } diff --git a/util/template/client-class b/util/template/client-class index 53782840..073578a8 100644 --- a/util/template/client-class +++ b/util/template/client-class @@ -21,6 +21,17 @@ declare(strict_types=1); namespace OpenSearch; +use OpenSearch\Common\Exceptions\BadRequest400Exception; +use OpenSearch\Common\Exceptions\Conflict409Exception; +use OpenSearch\Common\Exceptions\Forbidden403Exception; +use OpenSearch\Common\Exceptions\Missing404Exception; +use OpenSearch\Common\Exceptions\NoDocumentsToGetException; +use OpenSearch\Common\Exceptions\NoShardAvailableException; +use OpenSearch\Common\Exceptions\RequestTimeout408Exception; +use OpenSearch\Common\Exceptions\RoutingMissingException; +use OpenSearch\Common\Exceptions\ScriptLangNotSupportedException; +use OpenSearch\Common\Exceptions\ServerErrorResponseException; +use OpenSearch\Common\Exceptions\Unauthorized401Exception; use OpenSearch\Endpoints\AbstractEndpoint; use OpenSearch\Namespaces\BooleanRequestWrapper; use OpenSearch\Namespaces\NamespaceBuilderInterface; @@ -64,16 +75,27 @@ class Client */ protected $registeredNamespaces = []; + /** + * @deprecated in 2.3.2 and will be removed in 3.0.0. + */ + private bool $throwExceptions = false; + :namespace_properties + /** * Client constructor * * @param TransportInterface|Transport $transport * @param callable|EndpointFactoryInterface $endpointFactory * @param NamespaceBuilderInterface[] $registeredNamespaces + * @param bool $throwExceptions */ - public function __construct(TransportInterface|Transport $transport, callable|EndpointFactoryInterface $endpointFactory, array $registeredNamespaces) - { + public function __construct( + TransportInterface|Transport $transport, + callable|EndpointFactoryInterface $endpointFactory, + array $registeredNamespaces, + bool $throwExceptions = false, + ) { if (!$transport instanceof TransportInterface) { @trigger_error('Passing an instance of \OpenSearch\Transport to ' . __METHOD__ . '() is deprecated in 2.3.2 and will be removed in 3.0.0. Pass an instance of \OpenSearch\TransportInterface instead.', E_USER_DEPRECATED); $this->transport = $transport; @@ -93,6 +115,13 @@ class Client } $this->endpoints = $endpoints; $this->endpointFactory = $endpointFactory; + if ($throwExceptions === true) { + @trigger_error( + 'The $throwExceptions parameter is deprecated in 2.4.0 and will be removed in 3.0.0. Check the response \'status_code\' instead', + E_USER_DEPRECATED + ); + $this->throwExceptions = true; + } :new-namespaces $this->registeredNamespaces = $registeredNamespaces; } @@ -143,30 +172,128 @@ class Client * Send a raw request to the cluster. * * @throws \Psr\Http\Client\ClientExceptionInterface + * @throws \OpenSearch\Common\Exceptions\OpenSearchException */ - public function request(string $method, string $uri, array $attributes = []): array|string|null - { + public function request( + string $method, + string $uri, + array $attributes = [] + ): array|string|null { $params = $attributes['params'] ?? []; $body = $attributes['body'] ?? null; $options = $attributes['options'] ?? []; - return $this->httpTransport->sendRequest($method, $uri, $params, $body, $options['headers'] ?? []); + $response = $this->httpTransport->sendRequest($method, $uri, $params, $body, $options['headers'] ?? []); + + // @todo: Remove this in the next major release. + // Throw legacy exceptions. + if ($this->throwExceptions) { + if (isset($response['status']) && $response['status'] >= 400) { + $this->throwLegacyException($response); + } + } + + return $response; } /** * Send a request for an endpoint. * * @throws \Psr\Http\Client\ClientExceptionInterface + * @throws \OpenSearch\Common\Exceptions\OpenSearchException */ private function performRequest(AbstractEndpoint $endpoint): array|string|null { - return $this->httpTransport->sendRequest( + $response = $this->httpTransport->sendRequest( $endpoint->getMethod(), $endpoint->getURI(), $endpoint->getParams(), $endpoint->getBody(), $endpoint->getOptions() ); + + // @todo: Remove this in the next major release. + // Throw legacy exceptions. + if ($this->throwExceptions) { + if (isset($response['status']) && $response['status'] >= 400) { + $this->throwLegacyException($response); + } + } + + return $response; + } + + /** + * Throw legacy exceptions. + * + * @param array $response + * + * @throws \OpenSearch\Common\Exceptions\OpenSearchException + */ + private function throwLegacyException(array $response): void + { + if ($response['status'] >= 400 && $response['status'] < 500) { + $this->throwLegacyClientException($response); + } + if ($response['status'] >= 500) { + $this->throwLegacyServerException($response); + } + } + + /** + * Throw legacy client exceptions based on status code. + * + * @throws \OpenSearch\Common\Exceptions\OpenSearchException + */ + private function throwLegacyClientException($response): void + { + $statusCode = $response['status_code']; + $responseBody = $this->convertBodyToString($response['body'], $statusCode); + throw match ($statusCode) { + 401 => new Unauthorized401Exception($responseBody, $statusCode), + 403 => new Forbidden403Exception($responseBody, $statusCode), + 404 => new Missing404Exception($responseBody, $statusCode), + 409 => new Conflict409Exception($responseBody, $statusCode), + 400 => (str_contains($responseBody, 'script_lang not supported')) + ? new ScriptLangNotSupportedException($responseBody . $statusCode) + : new BadRequest400Exception($responseBody, $statusCode), + 408 => new RequestTimeout408Exception($responseBody, $statusCode), + default => new BadRequest400Exception($responseBody, $statusCode), + }; + } + + /** + * Throw legacy server exceptions based on status code. + * + * @throws \OpenSearch\Common\Exceptions\OpenSearchException + */ + private function throwLegacyServerException($response): void + { + $statusCode = $response['status_code']; + $error = $response['body']['error'] ?? []; + $reason = $error['reason'] ?? 'undefined reason'; + $type = $error['type'] ?? 'undefined type'; + $errorMessage = "$type: $reason"; + $responseBody = $this->convertBodyToString($response['body'], $statusCode); + + $exception = new ServerErrorResponseException($responseBody, $statusCode); + if ($statusCode === 500) { + if (str_contains($responseBody, "RoutingMissingException")) { + $exception = new RoutingMissingException($errorMessage, $statusCode); + } elseif (preg_match('/ActionRequestValidationException.+ no documents to get/', $responseBody) === 1) { + $exception = new NoDocumentsToGetException($errorMessage, $statusCode); + } elseif (str_contains($responseBody, 'NoShardAvailableActionException')) { + $exception = new NoShardAvailableException($errorMessage, $statusCode); + } + } + throw $exception; + } + + private function convertBodyToString(mixed $body, int $statusCode): string + { + return empty($body) + ? "Unknown $statusCode error from OpenSearch" + : (is_string($body) ? $body : json_encode($body)); } } diff --git a/util/template/required-part b/util/template/required-part index 2eac180d..69966d75 100644 --- a/util/template/required-part +++ b/util/template/required-part @@ -1,6 +1,4 @@ - if (isset($this->:part) !== true) { - throw new RuntimeException( - ':part is required for :endpoint' - ); + if (!isset($this->:part) || $this->:part === '') { + throw new RuntimeException(':part is required for :endpoint'); } - $:part = $this->:part; \ No newline at end of file + $:part = $this->:part;