From caea6b95117f6b7ed3b2729578562559a8824b47 Mon Sep 17 00:00:00 2001 From: Jaanus Vapper Date: Tue, 2 Jul 2024 20:21:27 +0300 Subject: [PATCH] Add config option to disable SSL verification --- README.md | 10 ++++++++-- config/elasticsearch.php | 1 + src/ElasticSearch/Config/Config.php | 1 + src/ElasticSearch/Config/Storage.php | 8 ++++++++ src/ElasticSearchServiceProvider.php | 4 +++- 5 files changed, 21 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index db3b901b..66d08955 100644 --- a/README.md +++ b/README.md @@ -67,8 +67,8 @@ Set env variables SCOUT_DRIVER=Matchish\ScoutElasticSearch\Engines\ElasticSearchEngine ``` -The package uses `\ElasticSearch\Client` from official package, but does not try to configure it, -so feel free do it in your app service provider. +The package uses `\ElasticSearch\Client` from official package, but does not try to configure it +beyond connection configuration, so feel free do it in your app service provider. But if you don't want to do it right now, you can use `Matchish\ElasticSearchServiceProvider` from the package. Register the provider, adding to `config/app.php` @@ -87,6 +87,12 @@ or use commas as separator for additional nodes ``` ELASTICSEARCH_HOST=host:port,host:port ``` + +You can disable SSL verification by setting the following in your env +``` +ELASTICSEARCH_SSL_VERIFICATION=false +``` + And publish config example for elasticsearch `php artisan vendor:publish --tag config` diff --git a/config/elasticsearch.php b/config/elasticsearch.php index 4f5a5273..964b69cb 100644 --- a/config/elasticsearch.php +++ b/config/elasticsearch.php @@ -6,6 +6,7 @@ 'password' => env('ELASTICSEARCH_PASSWORD'), 'cloud_id' => env('ELASTICSEARCH_CLOUD_ID'), 'api_key' => env('ELASTICSEARCH_API_KEY'), + 'ssl_verification' => env('ELASTICSEARCH_SSL_VERIFICATION', true), 'queue' => [ 'timeout' => env('SCOUT_QUEUE_TIMEOUT'), ], diff --git a/src/ElasticSearch/Config/Config.php b/src/ElasticSearch/Config/Config.php index 93817fed..90600cbe 100644 --- a/src/ElasticSearch/Config/Config.php +++ b/src/ElasticSearch/Config/Config.php @@ -8,6 +8,7 @@ * @method static password() * @method static elasticCloudId() * @method static apiKey() + * @method static sslVerification() * @method static queueTimeout() */ class Config diff --git a/src/ElasticSearch/Config/Storage.php b/src/ElasticSearch/Config/Storage.php index 87abf2d4..35ad918a 100644 --- a/src/ElasticSearch/Config/Storage.php +++ b/src/ElasticSearch/Config/Storage.php @@ -63,6 +63,14 @@ public function apiKey(): ?string return $this->loadConfig('api_key'); } + /** + * @return bool + */ + public function sslVerification(): bool + { + return (bool) ($this->loadConfig('ssl_verification') ?? true); + } + /** * @return ?int */ diff --git a/src/ElasticSearchServiceProvider.php b/src/ElasticSearchServiceProvider.php index 6fb5dd87..79293f6f 100644 --- a/src/ElasticSearchServiceProvider.php +++ b/src/ElasticSearchServiceProvider.php @@ -21,7 +21,9 @@ public function register(): void $this->mergeConfigFrom(__DIR__.'/../config/elasticsearch.php', 'elasticsearch'); $this->app->bind(Client::class, function () { - $clientBuilder = ClientBuilder::create()->setHosts(Config::hosts()); + $clientBuilder = ClientBuilder::create() + ->setHosts(Config::hosts()) + ->setSSLVerification(Config::sslVerification()); if ($user = Config::user()) { $clientBuilder->setBasicAuthentication($user, Config::password()); }