From d269eaede68ba8c59b4975bfb8ada8f7ff53b5e7 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Wed, 3 Aug 2022 10:40:47 +0200 Subject: [PATCH 1/8] Added 8.4 job + updated tests --- ...ch-php+6.8.x.yml => elastic+elasticsearch-php+8.4.yml} | 8 ++++---- .ci/test-matrix.yml | 2 +- .github/workflows/test.yml | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) rename .ci/jobs/{elastic+elasticsearch-php+6.8.x.yml => elastic+elasticsearch-php+8.4.yml} (56%) diff --git a/.ci/jobs/elastic+elasticsearch-php+6.8.x.yml b/.ci/jobs/elastic+elasticsearch-php+8.4.yml similarity index 56% rename from .ci/jobs/elastic+elasticsearch-php+6.8.x.yml rename to .ci/jobs/elastic+elasticsearch-php+8.4.yml index 50455c049..27f516b81 100644 --- a/.ci/jobs/elastic+elasticsearch-php+6.8.x.yml +++ b/.ci/jobs/elastic+elasticsearch-php+8.4.yml @@ -1,12 +1,12 @@ --- - job: - name: elastic+elasticsearch-php+6.8.x - display-name: 'elastic / elasticsearch-php # 6.8.x' - description: Testing the elasticsearch-php 6.8.x branch. + name: elastic+elasticsearch-php+8.4 + display-name: 'elastic / elasticsearch-php # 8.4' + description: Testing the elasticsearch-php 8.4 branch. parameters: - string: name: branch_specifier - default: refs/heads/6.8.x + default: refs/heads/8.4 description: the Git branch specifier to build (<branchName>, <tagName>, <commitId>, etc.) triggers: diff --git a/.ci/test-matrix.yml b/.ci/test-matrix.yml index edb113223..e0da51323 100644 --- a/.ci/test-matrix.yml +++ b/.ci/test-matrix.yml @@ -1,6 +1,6 @@ --- STACK_VERSION: - - 8.3.0-SNAPSHOT + - 8.4.0-SNAPSHOT PHP_VERSION: - 8.1-cli diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 272350078..80c34b56e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: matrix: php-version: [7.4, 8.0, 8.1] os: [ubuntu-latest] - es-version: [8.3.0-SNAPSHOT] + es-version: [8.4.0-SNAPSHOT] steps: - name: Checkout From 849e8bd95e3d8b80dafa58cf23cb5477fc547cb2 Mon Sep 17 00:00:00 2001 From: Sam Reed Date: Tue, 9 Aug 2022 13:31:31 +0100 Subject: [PATCH 2/8] README.md: Fix "Backward Incompatible Changes" link (#1245) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6494965d2..a98ffe474 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ This is the official PHP client for - [Search a document](#search-a-document) - [Delete a document](#delete-a-document) - [Versioning](#versioning) -- [Backward Incompatible Changes](#backward-incompatible-changes-) +- [Backward Incompatible Changes](#backward-incompatible-changes-boom) - [Mock the Elasticsearch client](#mock-the-elasticsearch-client) - [FAQ](#faq-) - [Contribute](#contribute-) From c0bc0fac9304a78536f46abf63823ed643fc1c05 Mon Sep 17 00:00:00 2001 From: Emanuele Panzeri Date: Tue, 9 Aug 2022 14:32:20 +0200 Subject: [PATCH 3/8] doc(readme) Fix typo in docker instructions (#1240) --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a98ffe474..b6efb69e4 100644 --- a/README.md +++ b/README.md @@ -118,7 +118,7 @@ docker run --name es01 --net elastic -p 9200:9200 -p 9300:9300 -it docker.elasti This command creates an `elastic` Docker network and start Elasticsearch using the port `9200` (default). -When you run the docker imnage a password is generated for the `elastic` user +When you run the docker image a password is generated for the `elastic` user and it's printed to the terminal (you might need to scroll back a bit in the terminal to view it). You have to copy it since we will need to connect to Elasticsearch. From c334f0459966ff6a1c445856d36a874886d4544b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=9D=A6=E7=B1=B3?= Date: Tue, 9 Aug 2022 20:34:09 +0800 Subject: [PATCH 4/8] Update installation.asciidoc (#1234) The namespace changes since 8.x --- docs/installation.asciidoc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/installation.asciidoc b/docs/installation.asciidoc index 371c76304..0b3b35f3c 100644 --- a/docs/installation.asciidoc +++ b/docs/installation.asciidoc @@ -29,7 +29,7 @@ create this object, as follows: -------------------------- require 'vendor/autoload.php'; -$client = Elasticsearch\ClientBuilder::create()->build(); +$client = Elastic\Elasticsearch\ClientBuilder::create()->build(); -------------------------- + Client instantiation is performed with a static helper function `create()`. This From 6c6124ecb71d68737e66c312f7498847f7b7486a Mon Sep 17 00:00:00 2001 From: Felix Date: Tue, 9 Aug 2022 14:34:59 +0200 Subject: [PATCH 5/8] Update README.md (#1230) fix link to github issues --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index b6efb69e4..f85f86be1 100644 --- a/README.md +++ b/README.md @@ -384,7 +384,7 @@ section of PHP-HTTP documentation. ### Where do I report issues with the client? If something is not working as expected, please open an -[issue](https://github.com/elastic/elasticsearh-php/issues/new). +[issue](https://github.com/elastic/elasticsearch-php/issues/new). ### Where else can I go to get help? From ba64c54c3379c6b40066feb531c21cf4107b9c33 Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Mon, 8 Aug 2022 09:15:24 +0200 Subject: [PATCH 6/8] Add Symfony HTTP client adapter and remove Accept-Encoding header (gzip) for Symfony (#1243) * Remove the gzip Accept-Encoding header for Symfony HTTP client * Add the support of symfony http-client v5 * Added Symfony options adapter + use Guzzle as default HTTP client * Reverted default HTTP client + fixed setOptions --- composer.json | 6 +- phpunit-integration-cloud-tests.xml | 26 +++++++ phpunit.xml.dist | 1 + src/ClientBuilder.php | 34 +++++++--- src/Transport/Adapter/AdapterOptions.php | 4 +- src/Transport/Adapter/Guzzle.php | 22 +++--- src/Transport/Adapter/Symfony.php | 46 +++++++++++++ tests/ClientBuilderTest.php | 35 ++++++++++ tests/Integration/BasicTest.php | 2 - tests/Integration/ElasticCloudTest.php | 77 +++++++++++++++++++++ tests/Transport/Adapter/GuzzleTest.php | 67 ++++++++++++++++++ tests/Transport/Adapter/SymfonyTest.php | 86 ++++++++++++++++++++++++ 12 files changed, 381 insertions(+), 25 deletions(-) create mode 100644 phpunit-integration-cloud-tests.xml create mode 100644 src/Transport/Adapter/Symfony.php create mode 100644 tests/Integration/ElasticCloudTest.php create mode 100644 tests/Transport/Adapter/GuzzleTest.php create mode 100644 tests/Transport/Adapter/SymfonyTest.php diff --git a/composer.json b/composer.json index 9c40e5e40..53d8cd99e 100644 --- a/composer.json +++ b/composer.json @@ -25,7 +25,8 @@ "phpunit/phpunit": "^9.5", "symfony/finder": "~4.0", "nyholm/psr7": "^1.5", - "php-http/mock-client": "^1.5" + "php-http/mock-client": "^1.5", + "symfony/http-client": "^5.0|^6.0" }, "autoload": { "psr-4": { @@ -45,6 +46,9 @@ "integration-test" : [ "vendor/bin/phpunit --testdox -c phpunit-integration-tests.xml" ], + "cloud-test" : [ + "vendor/bin/phpunit --testdox -c phpunit-integration-cloud-tests.xml" + ], "phpstan": [ "phpstan analyse src --level 2 --no-progress" ] diff --git a/phpunit-integration-cloud-tests.xml b/phpunit-integration-cloud-tests.xml new file mode 100644 index 000000000..dbee7d789 --- /dev/null +++ b/phpunit-integration-cloud-tests.xml @@ -0,0 +1,26 @@ + + + + + src + + + + + + + + + + tests/Integration + + + + + cloud + + + + + + diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 7a4a32997..1172040f9 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -15,6 +15,7 @@ integration free platinum + cloud diff --git a/src/ClientBuilder.php b/src/ClientBuilder.php index 245d35eb3..41ae53ef2 100644 --- a/src/ClientBuilder.php +++ b/src/ClientBuilder.php @@ -22,7 +22,9 @@ use Elastic\Elasticsearch\Transport\Adapter\AdapterOptions; use Elastic\Elasticsearch\Transport\RequestOptions; use Elastic\Transport\NodePool\NodePoolInterface; +use Elastic\Transport\Transport; use Elastic\Transport\TransportBuilder; +use GuzzleHttp\Client as GuzzleHttpClient; use Http\Client\HttpAsyncClient; use Psr\Http\Client\ClientInterface; use Psr\Log\LoggerInterface; @@ -344,14 +346,11 @@ public function build(): Client // Http client if (!empty($this->httpClient)) { $builder->setClient($this->httpClient); - } else { - // Set HTTP client options - if (!empty($this->getConfig()) || !empty($this->httpClientOptions)) { - $builder->setClient( - $this->setOptions($builder->getClient(), $this->getConfig(), $this->httpClientOptions) - ); - } } + // Set HTTP client options + $builder->setClient( + $this->setOptions($builder->getClient(), $this->getConfig(), $this->httpClientOptions) + ); // Cloud id if (!empty($this->cloudId)) { @@ -389,8 +388,11 @@ public function build(): Client $transport->setHeader('Authorization', sprintf("ApiKey %s", $this->apiKey)); } - // Elastic cloud optimized with gzip - if (!empty($this->cloudId)) { + /** + * Elastic cloud optimized with gzip + * @see https://github.com/elastic/elasticsearch-php/issues/1241 omit for Symfony HTTP Client + */ + if (!empty($this->cloudId) && !$this->isSymfonyHttpClient($transport)) { $transport->setHeader('Accept-Encoding', 'gzip'); } @@ -401,6 +403,20 @@ public function build(): Client return $client; } + /** + * Returns true if the transport HTTP client is Symfony + */ + protected function isSymfonyHttpClient(Transport $transport): bool + { + if (false !== strpos(get_class($transport->getClient()), 'Symfony\Component\HttpClient')) { + return true; + } + if (false !== strpos(get_class($transport->getAsyncClient()), 'Symfony\Component\HttpClient')) { + return true; + } + return false; + } + /** * Returns the configuration to be used in the HTTP client */ diff --git a/src/Transport/Adapter/AdapterOptions.php b/src/Transport/Adapter/AdapterOptions.php index 501d65027..c3d2da0dd 100644 --- a/src/Transport/Adapter/AdapterOptions.php +++ b/src/Transport/Adapter/AdapterOptions.php @@ -20,6 +20,8 @@ final class AdapterOptions { const HTTP_ADAPTERS = [ - "GuzzleHttp\\Client" => "Elastic\\Elasticsearch\\Transport\\Adapter\\Guzzle" + "GuzzleHttp\\Client" => "Elastic\\Elasticsearch\\Transport\\Adapter\\Guzzle", + "Symfony\\Component\\HttpClient\\HttplugClient" => "Elastic\\Elasticsearch\\Transport\\Adapter\\Symfony", + "Symfony\\Component\\HttpClient\\Psr18Client" => "Elastic\\Elasticsearch\\Transport\\Adapter\\Symfony" ]; } \ No newline at end of file diff --git a/src/Transport/Adapter/Guzzle.php b/src/Transport/Adapter/Guzzle.php index ce750acfd..dfacc97fe 100644 --- a/src/Transport/Adapter/Guzzle.php +++ b/src/Transport/Adapter/Guzzle.php @@ -14,10 +14,8 @@ namespace Elastic\Elasticsearch\Transport\Adapter; -use Elastic\Elasticsearch\Exception\HttpClientException; -use Elastic\Elasticsearch\Transport\RequestOptions as Options; -use GuzzleHttp\Client; -use GuzzleHttp\RequestOptions; +use Elastic\Elasticsearch\Transport\RequestOptions; +use GuzzleHttp\RequestOptions As GuzzleOptions; use Psr\Http\Client\ClientInterface; class Guzzle implements AdapterInterface @@ -27,17 +25,17 @@ public function setConfig(ClientInterface $client, array $config, array $clientO $guzzleConfig = []; foreach ($config as $key => $value) { switch ($key) { - case Options::SSL_CERT: - $guzzleConfig[RequestOptions::CERT] = $value; + case RequestOptions::SSL_CERT: + $guzzleConfig[GuzzleOptions::CERT] = $value; break; - case Options::SSL_KEY: - $guzzleConfig[RequestOptions::SSL_KEY] = $value; + case RequestOptions::SSL_KEY: + $guzzleConfig[GuzzleOptions::SSL_KEY] = $value; break; - case Options::SSL_VERIFY: - $guzzleConfig[RequestOptions::VERIFY] = $value; + case RequestOptions::SSL_VERIFY: + $guzzleConfig[GuzzleOptions::VERIFY] = $value; break; - case Options::SSL_CA: - $guzzleConfig[RequestOptions::VERIFY] = $value; + case RequestOptions::SSL_CA: + $guzzleConfig[GuzzleOptions::VERIFY] = $value; } } $class = get_class($client); diff --git a/src/Transport/Adapter/Symfony.php b/src/Transport/Adapter/Symfony.php new file mode 100644 index 000000000..892ed4b91 --- /dev/null +++ b/src/Transport/Adapter/Symfony.php @@ -0,0 +1,46 @@ + $value) { + switch ($key) { + case RequestOptions::SSL_CERT: + $symfonyConfig['local_cert'] = $value; + break; + case RequestOptions::SSL_KEY: + $symfonyConfig['local_pk'] = $value; + break; + case RequestOptions::SSL_VERIFY: + $symfonyConfig['verify_host'] = $value; + $symfonyConfig['verify_peer'] = $value; + break; + case RequestOptions::SSL_CA: + $symfonyConfig['cafile'] = $value; + } + } + $class = get_class($client); + $httpClient = HttpClient::create(array_merge($clientOptions, $symfonyConfig)); + return new $class($httpClient); + } +} \ No newline at end of file diff --git a/tests/ClientBuilderTest.php b/tests/ClientBuilderTest.php index 45a2795c6..bd32f0d7d 100644 --- a/tests/ClientBuilderTest.php +++ b/tests/ClientBuilderTest.php @@ -25,6 +25,8 @@ use PHPUnit\Framework\TestCase; use Psr\Http\Client\ClientInterface; use Psr\Log\LoggerInterface; +use Symfony\Component\HttpClient\Psr18Client; +use Symfony\Component\HttpClient\HttplugClient; class ClientBuilderTest extends TestCase { @@ -331,4 +333,37 @@ public function testSetHttpClientOptions() $result = $this->builder->setHttpClientOptions([]); $this->assertEquals($this->builder, $result); } + + public function testClientWithSymfonyPsr18Client() + { + $symfonyClient = new Psr18Client(); + $client = ClientBuilder::create() + ->setHttpClient($symfonyClient) + ->build(); + + $this->assertInstanceOf(Client::class, $client); + $this->assertEquals($symfonyClient, $client->getTransport()->getClient()); + } + + public function testClientWithSymfonyHttplugClient() + { + $symfonyClient = new HttplugClient(); + $client = ClientBuilder::create() + ->setHttpClient($symfonyClient) + ->build(); + + $this->assertInstanceOf(Client::class, $client); + $this->assertEquals($symfonyClient, $client->getTransport()->getClient()); + } + + public function testAsyncClientWithSymfonyHttplugClient() + { + $symfonyClient = new HttplugClient(); + $client = ClientBuilder::create() + ->setAsyncHttpClient($symfonyClient) + ->build(); + + $this->assertInstanceOf(Client::class, $client); + $this->assertEquals($symfonyClient, $client->getTransport()->getAsyncClient()); + } } \ No newline at end of file diff --git a/tests/Integration/BasicTest.php b/tests/Integration/BasicTest.php index 9a77a615b..df080dee0 100644 --- a/tests/Integration/BasicTest.php +++ b/tests/Integration/BasicTest.php @@ -14,9 +14,7 @@ namespace Elastic\Elasticsearch\Tests\Integration; -use Elastic\Elasticsearch\Exception\ClientResponseException; use Elastic\Elasticsearch\Tests\Utility; -use Elastic\Transport\Exception\NoNodeAvailableException; use PHPUnit\Framework\TestCase; /** diff --git a/tests/Integration/ElasticCloudTest.php b/tests/Integration/ElasticCloudTest.php new file mode 100644 index 000000000..0b037d6d7 --- /dev/null +++ b/tests/Integration/ElasticCloudTest.php @@ -0,0 +1,77 @@ +markTestSkipped(sprintf( + "I cannot execute the Elastic Cloud test without the env variables %s and %s", + self::CLOUD_ID, + self::API_KEY + )); + } + $this->clientBuilder = ClientBuilder::create() + ->setElasticCloudId(getenv(self::CLOUD_ID)) + ->setApiKey(getenv(self::API_KEY)); + } + + public function testInfoWithAsyncSymfonyHttplugClient() + { + $symfonyClient = new HttplugClient(); + + $client = $this->clientBuilder->setAsyncHttpClient($symfonyClient) + ->build(); + + $client->setAsync(true); + + $promise = $client->info(); + $this->assertInstanceOf(Promise::class, $promise); + $response = $promise->wait(); + + $this->assertEquals(200, $response->getStatusCode()); + $this->assertNotEmpty($response['name']); + $this->assertNotEmpty($response['version']['number']); + } + + public function testInfoWithSymfonyHttpPsr18Client() + { + $symfonyClient = new Psr18Client(); + + $client = $this->clientBuilder->setHttpClient($symfonyClient) + ->build(); + + $response = $client->info(); + $this->assertEquals(200, $response->getStatusCode()); + $this->assertNotEmpty($response['name']); + $this->assertNotEmpty($response['version']['number']); + } +} \ No newline at end of file diff --git a/tests/Transport/Adapter/GuzzleTest.php b/tests/Transport/Adapter/GuzzleTest.php new file mode 100644 index 000000000..ecd6e0aac --- /dev/null +++ b/tests/Transport/Adapter/GuzzleTest.php @@ -0,0 +1,67 @@ +guzzleAdapter = new Guzzle; + $this->client = $this->createStub(ClientInterface::class); + } + + public function testSetConfigWithEmptyArray() + { + $result = $this->guzzleAdapter->setConfig($this->client, [], []); + $this->assertInstanceOf(ClientInterface::class, $result); + } + + public function testSetConfigWithSslCert() + { + $result = $this->guzzleAdapter->setConfig(new Client(), [ RequestOptions::SSL_CERT => 'test'], []); + $this->assertInstanceOf(Client::class, $result); + $this->assertEquals('test', $result->getConfig(GuzzleOptions::CERT)); + } + + public function testSetConfigWithSslKey() + { + $result = $this->guzzleAdapter->setConfig(new Client(), [ RequestOptions::SSL_KEY => 'test'], []); + $this->assertInstanceOf(Client::class, $result); + $this->assertEquals('test', $result->getConfig(GuzzleOptions::SSL_KEY)); + } + + public function testSetConfigWithSslVerify() + { + $result = $this->guzzleAdapter->setConfig(new Client(), [ RequestOptions::SSL_VERIFY => false], []); + $this->assertInstanceOf(Client::class, $result); + $this->assertEquals(false, $result->getConfig(GuzzleOptions::VERIFY)); + } + + public function testSetConfigWithSslCa() + { + $result = $this->guzzleAdapter->setConfig(new Client(), [ RequestOptions::SSL_CA => 'test'], []); + $this->assertInstanceOf(Client::class, $result); + $this->assertEquals('test', $result->getConfig(GuzzleOptions::VERIFY)); + } +} \ No newline at end of file diff --git a/tests/Transport/Adapter/SymfonyTest.php b/tests/Transport/Adapter/SymfonyTest.php new file mode 100644 index 000000000..3b62e63f9 --- /dev/null +++ b/tests/Transport/Adapter/SymfonyTest.php @@ -0,0 +1,86 @@ +symfonyAdapter = new Symfony; + $this->client = $this->createStub(ClientInterface::class); + } + + /** Httplug tests */ + + public function testHttplugSetConfigWithSslCert() + { + $result = $this->symfonyAdapter->setConfig(new HttplugClient(), [ RequestOptions::SSL_CERT => 'test'], []); + $this->assertInstanceOf(HttplugClient::class, $result); + } + + public function testHttplugSetConfigWithSslKey() + { + $result = $this->symfonyAdapter->setConfig(new HttplugClient(), [ RequestOptions::SSL_KEY => 'test'], []); + $this->assertInstanceOf(HttplugClient::class, $result); + } + + public function testHttplugSetConfigWithSslVerify() + { + $result = $this->symfonyAdapter->setConfig(new HttplugClient(), [ RequestOptions::SSL_VERIFY => false], []); + $this->assertInstanceOf(HttplugClient::class, $result); + } + + public function testHttplugSetConfigWithSslCa() + { + $result = $this->symfonyAdapter->setConfig(new HttplugClient(), [ RequestOptions::SSL_CA => 'test'], []); + $this->assertInstanceOf(HttplugClient::class, $result); + } + + /** Psr18Client tests */ + + public function testPsr18ClientSetConfigWithSslCert() + { + $result = $this->symfonyAdapter->setConfig(new Psr18Client(), [ RequestOptions::SSL_CERT => 'test'], []); + $this->assertInstanceOf(Psr18Client::class, $result); + } + + public function testPsr18ClientSetConfigWithSslKey() + { + $result = $this->symfonyAdapter->setConfig(new Psr18Client(), [ RequestOptions::SSL_KEY => 'test'], []); + $this->assertInstanceOf(Psr18Client::class, $result); + } + + public function testPsr18ClientSetConfigWithSslVerify() + { + $result = $this->symfonyAdapter->setConfig(new Psr18Client(), [ RequestOptions::SSL_VERIFY => false], []); + $this->assertInstanceOf(Psr18Client::class, $result); + } + + public function testPsr18ClientSetConfigWithSslCa() + { + $result = $this->symfonyAdapter->setConfig(new Psr18Client(), [ RequestOptions::SSL_CA => 'test'], []); + $this->assertInstanceOf(Psr18Client::class, $result); + } +} \ No newline at end of file From 02347775971d05eb96d2231cb5f5473628fd6f3f Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Tue, 9 Aug 2022 18:37:55 +0200 Subject: [PATCH 7/8] Updated endpoints to 8.4 --- .ci/test-matrix.yml | 2 +- .github/workflows/test.yml | 2 +- src/Endpoints/Ml.php | 3 ++- src/Endpoints/Security.php | 37 +++++++++++++++++++++++++++++ src/Endpoints/Snapshot.php | 9 ++++++- src/Traits/ClientEndpointsTrait.php | 9 ++++--- 6 files changed, 55 insertions(+), 7 deletions(-) diff --git a/.ci/test-matrix.yml b/.ci/test-matrix.yml index e0da51323..2dd495a1f 100644 --- a/.ci/test-matrix.yml +++ b/.ci/test-matrix.yml @@ -1,6 +1,6 @@ --- STACK_VERSION: - - 8.4.0-SNAPSHOT + - 8.4-SNAPSHOT PHP_VERSION: - 8.1-cli diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 80c34b56e..800c5bd11 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -11,7 +11,7 @@ jobs: matrix: php-version: [7.4, 8.0, 8.1] os: [ubuntu-latest] - es-version: [8.4.0-SNAPSHOT] + es-version: [8.4-SNAPSHOT] steps: - name: Checkout diff --git a/src/Endpoints/Ml.php b/src/Endpoints/Ml.php index a8fdceac4..a8d7e408a 100644 --- a/src/Endpoints/Ml.php +++ b/src/Endpoints/Ml.php @@ -2340,6 +2340,7 @@ public function startDatafeed(array $params = []) * * @param array{ * model_id: string, // (REQUIRED) The unique identifier of the trained model. + * cache_size: string, // A byte-size value for configuring the inference cache size. For example, 20mb. * number_of_allocations: int, // The number of model allocations on each node where the model is deployed. * threads_per_allocation: int, // The number of threads used by each model allocation during inference. * queue_capacity: int, // Controls how many inference requests are allowed in the queue at a time. @@ -2365,7 +2366,7 @@ public function startTrainedModelDeployment(array $params = []) $url = '/_ml/trained_models/' . $this->encode($params['model_id']) . '/deployment/_start'; $method = 'POST'; - $url = $this->addQueryString($url, $params, ['number_of_allocations','threads_per_allocation','queue_capacity','timeout','wait_for','pretty','human','error_trace','source','filter_path']); + $url = $this->addQueryString($url, $params, ['cache_size','number_of_allocations','threads_per_allocation','queue_capacity','timeout','wait_for','pretty','human','error_trace','source','filter_path']); $headers = [ 'Accept' => 'application/json', 'Content-Type' => 'application/json', diff --git a/src/Endpoints/Security.php b/src/Endpoints/Security.php index 6eabb624a..83349b0b2 100644 --- a/src/Endpoints/Security.php +++ b/src/Endpoints/Security.php @@ -1908,6 +1908,43 @@ public function suggestUserProfiles(array $params = []) } + /** + * Updates attributes of an existing API key. + * + * @see https://www.elastic.co/guide/en/elasticsearch/reference/current/security-api-update-api-key.html + * + * @param array{ + * id: string, // (REQUIRED) The ID of the API key to update + * pretty: boolean, // Pretty format the returned JSON response. (DEFAULT: false) + * human: boolean, // Return human readable values for statistics. (DEFAULT: true) + * error_trace: boolean, // Include the stack trace of returned errors. (DEFAULT: false) + * source: string, // The URL-encoded request definition. Useful for libraries that do not accept a request body for non-POST requests. + * filter_path: list, // A comma-separated list of filters used to reduce the response. + * body: array, // The API key request to update attributes of an API key. + * } $params + * + * @throws MissingParameterException if a required parameter is missing + * @throws NoNodeAvailableException if all the hosts are offline + * @throws ClientResponseException if the status code of response is 4xx + * @throws ServerResponseException if the status code of response is 5xx + * + * @return Elasticsearch|Promise + */ + public function updateApiKey(array $params = []) + { + $this->checkRequiredParameters(['id'], $params); + $url = '/_security/api_key/' . $this->encode($params['id']); + $method = 'PUT'; + + $url = $this->addQueryString($url, $params, ['pretty','human','error_trace','source','filter_path']); + $headers = [ + 'Accept' => 'application/json', + 'Content-Type' => 'application/json', + ]; + return $this->client->sendRequest($this->createRequest($method, $url, $headers, $params['body'] ?? null)); + } + + /** * Update application specific data for the user profile of the given unique ID. * diff --git a/src/Endpoints/Snapshot.php b/src/Endpoints/Snapshot.php index 6f9b13b49..f2732da66 100644 --- a/src/Endpoints/Snapshot.php +++ b/src/Endpoints/Snapshot.php @@ -272,6 +272,13 @@ public function deleteRepository(array $params = []) * index_names: boolean, // Whether to include the name of each index in the snapshot. Defaults to true. * index_details: boolean, // Whether to include details of each index in the snapshot, if those details are available. Defaults to false. * include_repository: boolean, // Whether to include the repository name in the snapshot info. Defaults to true. + * sort: enum, // Allows setting a sort order for the result. Defaults to start_time + * size: integer, // Maximum number of snapshots to return. Defaults to 0 which means return all that match without limit. + * order: enum, // Sort order + * from_sort_value: string, // Value of the current sort column at which to start retrieval. + * after: string, // Offset identifier to start pagination from as returned by the 'next' field in the response body. + * offset: integer, // Numeric offset to start pagination based on the snapshots matching the request. Defaults to 0 + * slm_policy_filter: string, // Filter snapshots by a comma-separated list of SLM policy names that snapshots belong to. Accepts wildcards. Use the special pattern '_none' to match snapshots without an SLM policy * verbose: boolean, // Whether to show verbose snapshot info or only show the basic info found in the repository index blob * pretty: boolean, // Pretty format the returned JSON response. (DEFAULT: false) * human: boolean, // Return human readable values for statistics. (DEFAULT: true) @@ -293,7 +300,7 @@ public function get(array $params = []) $url = '/_snapshot/' . $this->encode($params['repository']) . '/' . $this->encode($params['snapshot']); $method = 'GET'; - $url = $this->addQueryString($url, $params, ['master_timeout','ignore_unavailable','index_names','index_details','include_repository','verbose','pretty','human','error_trace','source','filter_path']); + $url = $this->addQueryString($url, $params, ['master_timeout','ignore_unavailable','index_names','index_details','include_repository','sort','size','order','from_sort_value','after','offset','slm_policy_filter','verbose','pretty','human','error_trace','source','filter_path']); $headers = [ 'Accept' => 'application/json', ]; diff --git a/src/Traits/ClientEndpointsTrait.php b/src/Traits/ClientEndpointsTrait.php index 7e434d6ac..ac2ed6123 100644 --- a/src/Traits/ClientEndpointsTrait.php +++ b/src/Traits/ClientEndpointsTrait.php @@ -629,6 +629,7 @@ public function fieldCaps(array $params = []) * @param array{ * id: string, // (REQUIRED) The document ID * index: string, // (REQUIRED) The name of the index + * force_synthetic_source: boolean, // Should this request force synthetic _source? Use this to test if the mapping supports synthetic _source and to get a sense of the worst case performance. Fetches with this enabled will be slower the enabling synthetic source natively in the index. * stored_fields: list, // A comma-separated list of stored fields to return in the response * preference: string, // Specify the node or shard the operation should be performed on (default: random) * realtime: boolean, // Specify whether to perform the operation in realtime or search mode @@ -659,7 +660,7 @@ public function get(array $params = []) $url = '/' . $this->encode($params['index']) . '/_doc/' . $this->encode($params['id']); $method = 'GET'; - $url = $this->addQueryString($url, $params, ['stored_fields','preference','realtime','refresh','routing','_source','_source_excludes','_source_includes','version','version_type','pretty','human','error_trace','source','filter_path']); + $url = $this->addQueryString($url, $params, ['force_synthetic_source','stored_fields','preference','realtime','refresh','routing','_source','_source_excludes','_source_includes','version','version_type','pretty','human','error_trace','source','filter_path']); $headers = [ 'Accept' => 'application/json', ]; @@ -943,6 +944,7 @@ public function knnSearch(array $params = []) * * @param array{ * index: string, // The name of the index + * force_synthetic_source: boolean, // Should this request force synthetic _source? Use this to test if the mapping supports synthetic _source and to get a sense of the worst case performance. Fetches with this enabled will be slower the enabling synthetic source natively in the index. * stored_fields: list, // A comma-separated list of stored fields to return in the response * preference: string, // Specify the node or shard the operation should be performed on (default: random) * realtime: boolean, // Specify whether to perform the operation in realtime or search mode @@ -975,7 +977,7 @@ public function mget(array $params = []) $url = '/_mget'; $method = empty($params['body']) ? 'GET' : 'POST'; } - $url = $this->addQueryString($url, $params, ['stored_fields','preference','realtime','refresh','routing','_source','_source_excludes','_source_includes','pretty','human','error_trace','source','filter_path']); + $url = $this->addQueryString($url, $params, ['force_synthetic_source','stored_fields','preference','realtime','refresh','routing','_source','_source_excludes','_source_includes','pretty','human','error_trace','source','filter_path']); $headers = [ 'Accept' => 'application/json', 'Content-Type' => 'application/json', @@ -1499,6 +1501,7 @@ public function scroll(array $params = []) * stored_fields: list, // A comma-separated list of stored fields to return as part of a hit * docvalue_fields: list, // A comma-separated list of fields to return as the docvalue representation of a field for each hit * from: number, // Starting offset (default: 0) + * force_synthetic_source: boolean, // Should this request force synthetic _source? Use this to test if the mapping supports synthetic _source and to get a sense of the worst case performance. Fetches with this enabled will be slower the enabling synthetic source natively in the index. * ignore_unavailable: boolean, // Whether specified concrete indices should be ignored when unavailable (missing or closed) * ignore_throttled: boolean, // Whether specified concrete, expanded or aliased indices should be ignored when throttled * allow_no_indices: boolean, // Whether to ignore if a wildcard indices expression resolves into no concrete indices. (This includes `_all` string or when no indices have been specified) @@ -1556,7 +1559,7 @@ public function search(array $params = []) $url = '/_search'; $method = empty($params['body']) ? 'GET' : 'POST'; } - $url = $this->addQueryString($url, $params, ['analyzer','analyze_wildcard','ccs_minimize_roundtrips','default_operator','df','explain','stored_fields','docvalue_fields','from','ignore_unavailable','ignore_throttled','allow_no_indices','expand_wildcards','lenient','preference','q','routing','scroll','search_type','size','sort','_source','_source_excludes','_source_includes','terminate_after','stats','suggest_field','suggest_mode','suggest_size','suggest_text','timeout','track_scores','track_total_hits','allow_partial_search_results','typed_keys','version','seq_no_primary_term','request_cache','batched_reduce_size','max_concurrent_shard_requests','pre_filter_shard_size','rest_total_hits_as_int','min_compatible_shard_node','pretty','human','error_trace','source','filter_path']); + $url = $this->addQueryString($url, $params, ['analyzer','analyze_wildcard','ccs_minimize_roundtrips','default_operator','df','explain','stored_fields','docvalue_fields','from','force_synthetic_source','ignore_unavailable','ignore_throttled','allow_no_indices','expand_wildcards','lenient','preference','q','routing','scroll','search_type','size','sort','_source','_source_excludes','_source_includes','terminate_after','stats','suggest_field','suggest_mode','suggest_size','suggest_text','timeout','track_scores','track_total_hits','allow_partial_search_results','typed_keys','version','seq_no_primary_term','request_cache','batched_reduce_size','max_concurrent_shard_requests','pre_filter_shard_size','rest_total_hits_as_int','min_compatible_shard_node','pretty','human','error_trace','source','filter_path']); $headers = [ 'Accept' => 'application/json', 'Content-Type' => 'application/json', From e98c4d34390a32e95f3805194127aacf6a78244b Mon Sep 17 00:00:00 2001 From: Enrico Zimuel Date: Tue, 9 Aug 2022 19:02:56 +0200 Subject: [PATCH 8/8] Skip test cluster.desired_nodes/20_dry_run using _internal API --- util/YamlTests.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/YamlTests.php b/util/YamlTests.php index 42e0d67cf..655bc3ef7 100644 --- a/util/YamlTests.php +++ b/util/YamlTests.php @@ -35,7 +35,8 @@ class YamlTests const YAML_FILES_TO_OMIT = [ 'platinum/eql/10_basic.yml', // use of _internal APIs - 'free/cluster.desired_nodes/10_basic.yml', + 'free/cluster.desired_nodes/10_basic.yml', + 'free/cluster.desired_nodes/20_dry_run.yml', 'free/health/' ];