Skip to content

Commit

Permalink
Merge pull request #283 from hulkur/master
Browse files Browse the repository at this point in the history
Add config option to disable SSL verification
  • Loading branch information
matchish authored Jul 2, 2024
2 parents 94365ad + caea6b9 commit 996e161
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 3 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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`

Expand Down
1 change: 1 addition & 0 deletions config/elasticsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'),
],
Expand Down
1 change: 1 addition & 0 deletions src/ElasticSearch/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* @method static password()
* @method static elasticCloudId()
* @method static apiKey()
* @method static sslVerification()
* @method static queueTimeout()
*/
class Config
Expand Down
8 changes: 8 additions & 0 deletions src/ElasticSearch/Config/Storage.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
4 changes: 3 additions & 1 deletion src/ElasticSearchServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down

0 comments on commit 996e161

Please sign in to comment.