diff --git a/README.md b/README.md index db3b901..66d0895 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 4f5a527..964b69c 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 93817fe..90600cb 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 87abf2d..35ad918 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 6fb5dd8..79293f6 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()); }