Skip to content

Commit

Permalink
Merge pull request #3127 from gabrielLumao/feat/add-ssl-verify-config…
Browse files Browse the repository at this point in the history
…-LU-140

Added configuration for ssl verification
  • Loading branch information
romainruaud authored Dec 6, 2023
2 parents 81120f1 + 701ec55 commit d300dc2
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/module-elasticsuite-core/Client/ClientBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class ClientBuilder
'is_debug_mode_enabled' => false,
'max_parallel_handles' => 100, // As per default Elasticsearch Handler configuration.
'max_retries' => 2,
'verify' => true,
];

/**
Expand Down Expand Up @@ -113,6 +114,10 @@ public function build($options = [])
$clientBuilder->setRetries((int) $options['max_retries']);
}

if (array_key_exists('verify', $options)) {
$clientBuilder->setSSLVerification($options['verify']);
}

if (null !== $this->selector) {
$selector = (count($hosts) > 1) ? $this->selector : StickyRoundRobinSelector::class;
$clientBuilder->setSelector($selector);
Expand Down
9 changes: 9 additions & 0 deletions src/module-elasticsuite-core/Client/ClientConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ public function getMaxRetries()
return (int) $this->getElasticsearchClientConfigParam('max_retries');
}

/**
* @return bool
*/
public function isVerifyEnabled()
{
return (bool) $this->getElasticsearchClientConfigParam('enable_certificate_validation');
}

/**
* {@inheritDoc}
*/
Expand All @@ -145,6 +153,7 @@ public function getOptions()
'is_debug_mode_enabled' => $this->isDebugModeEnabled(),
'max_parallel_handles' => $this->getMaxParallelHandles(),
'max_retries' => $this->getMaxRetries(),
'verify' => $this->isVerifyEnabled(),
];

return $options;
Expand Down
5 changes: 5 additions & 0 deletions src/module-elasticsuite-core/etc/adminhtml/system.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,11 @@
<comment>Select yes if you want to connect to your Elasticsearch server over HTTPS.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="enable_certificate_validation" translate="label comment" type="select" sortOrder="52" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Use SSL certificate Validation</label>
<comment>Select no if you are using opensearch.</comment>
<source_model>Magento\Config\Model\Config\Source\Yesno</source_model>
</field>
<field id="enable_http_auth" translate="label comment" type="select" sortOrder="52" showInDefault="1" showInWebsite="0" showInStore="0" canRestore="1">
<label>Enable basic HTTP authentication</label>
<comment>Enable this option when your Elasticsearch server use basic HTTP authentication.</comment>
Expand Down
1 change: 1 addition & 0 deletions src/module-elasticsuite-core/etc/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
<timeout>30</timeout>
<max_parallel_handles>10</max_parallel_handles>
<max_retries>2</max_retries>
<enable_certificate_validation>1</enable_certificate_validation>
</es_client>
<indices_settings>
<alias>magento2</alias>
Expand Down

0 comments on commit d300dc2

Please sign in to comment.