From 29541fc2ec9255f0fbecfe85b7dd6df4837b5d6b Mon Sep 17 00:00:00 2001 From: Jakub Winkler Date: Tue, 8 Jul 2025 17:47:12 +0200 Subject: [PATCH] adding 'schema' param to Elasticsearch / OpenSearch configuration to support SSL connection --- .../Elasticsearch8/Model/Client/Elasticsearch.php | 11 ++++------- app/code/Magento/OpenSearch/Model/SearchClient.php | 11 ++++------- .../Validator/ElasticsearchConnectionValidator.php | 11 ++++------- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/app/code/Magento/Elasticsearch8/Model/Client/Elasticsearch.php b/app/code/Magento/Elasticsearch8/Model/Client/Elasticsearch.php index fe6af19c6dd53..c2127c4bb0bd1 100644 --- a/app/code/Magento/Elasticsearch8/Model/Client/Elasticsearch.php +++ b/app/code/Magento/Elasticsearch8/Model/Client/Elasticsearch.php @@ -196,12 +196,9 @@ public function indexExists(string $index): bool private function buildESConfig(array $options = []): array { $hostname = preg_replace('/http[s]?:\/\//i', '', $options['hostname']); - // @codingStandardsIgnoreStart - $protocol = parse_url($options['hostname'], PHP_URL_SCHEME); - // @codingStandardsIgnoreEnd - if (!$protocol) { - $protocol = 'http'; - } + $url = parse_url($options['hostname']); + + $options['scheme'] = $url['scheme'] ?? 'http'; $authString = ''; if (!empty($options['enableAuth']) && (int)$options['enableAuth'] === 1) { @@ -213,7 +210,7 @@ private function buildESConfig(array $options = []): array $portString = ':' . $options['port']; } - $host = $protocol . '://' . $authString . $hostname . $portString; + $host = ($options['scheme'] ?? 'http') . '://' . $authString . $hostname . $portString; $options['hosts'] = [$host]; diff --git a/app/code/Magento/OpenSearch/Model/SearchClient.php b/app/code/Magento/OpenSearch/Model/SearchClient.php index 200d277441df4..d0b28690586fb 100644 --- a/app/code/Magento/OpenSearch/Model/SearchClient.php +++ b/app/code/Magento/OpenSearch/Model/SearchClient.php @@ -137,12 +137,9 @@ public function testConnection(): bool private function buildOSConfig(array $options = []): array { $hostname = preg_replace('/http[s]?:\/\//i', '', $options['hostname']); - // @codingStandardsIgnoreStart - $protocol = parse_url($options['hostname'], PHP_URL_SCHEME); - // @codingStandardsIgnoreEnd - if (!$protocol) { - $protocol = 'http'; - } + $url = parse_url($options['hostname']); + + $options['scheme'] = $url['scheme'] ?? 'http'; $authString = ''; if (!empty($options['enableAuth']) && (int)$options['enableAuth'] === 1) { @@ -154,7 +151,7 @@ private function buildOSConfig(array $options = []): array $portString = ':' . $options['port']; } - $host = $protocol . '://' . $authString . $hostname . $portString; + $host = ($options['scheme'] ?? 'http') . '://' . $authString . $hostname . $portString; $options['hosts'] = [$host]; diff --git a/setup/src/Magento/Setup/Validator/ElasticsearchConnectionValidator.php b/setup/src/Magento/Setup/Validator/ElasticsearchConnectionValidator.php index 7ec3251a58135..7b9b39c8b0ccd 100644 --- a/setup/src/Magento/Setup/Validator/ElasticsearchConnectionValidator.php +++ b/setup/src/Magento/Setup/Validator/ElasticsearchConnectionValidator.php @@ -42,12 +42,9 @@ public function isValidConnection(array $options) private function buildConfig(array $options) { $hostname = preg_replace('/http[s]?:\/\//i', '', $options['hostname']); - // @codingStandardsIgnoreStart - $protocol = parse_url($options['hostname'], PHP_URL_SCHEME); - // @codingStandardsIgnoreEnd - if (!$protocol) { - $protocol = 'http'; - } + $url = parse_url($options['hostname']); + + $options['scheme'] = $url['scheme'] ?? 'http'; $authString = ''; if (isset($options['enableAuth']) && true === $options['enableAuth']) { @@ -59,7 +56,7 @@ private function buildConfig(array $options) $authString = "{$options['username']}:{$options['password']}@"; } $portString = empty($options['port']) ? '' : ':' . $options['port']; - $host = $protocol . '://' . $authString . $hostname . $portString; + $host = ($options['scheme'] ?? 'http') . '://' . $authString . $hostname . $portString; $options['hosts'] = [$host]; return $options;