Skip to content

Commit 2c46bd5

Browse files
committed
#22297 Fix elasticsearch issue over secure connection
Apply changes for default ES client
1 parent dcdf364 commit 2c46bd5

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

app/code/Magento/Elasticsearch/Model/Client/Elasticsearch.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,21 +103,28 @@ public function testConnection()
103103
*/
104104
private function buildConfig($options = [])
105105
{
106-
$host = preg_replace('/http[s]?:\/\//i', '', $options['hostname']);
106+
$hostname = preg_replace('/http[s]?:\/\//i', '', $options['hostname']);
107107
// @codingStandardsIgnoreStart
108108
$protocol = parse_url($options['hostname'], PHP_URL_SCHEME);
109109
// @codingStandardsIgnoreEnd
110110
if (!$protocol) {
111111
$protocol = 'http';
112112
}
113-
if (!empty($options['port'])) {
114-
$host .= ':' . $options['port'];
113+
114+
$authString = '';
115+
if (!empty($options['enableAuth']) && (int)$options['enableAuth'] === 1) {
116+
$authString = "{$options['username']}:{$options['password']}@";
115117
}
116-
if (!empty($options['enableAuth']) && ($options['enableAuth'] == 1)) {
117-
$host = sprintf('%s://%s:%s@%s', $protocol, $options['username'], $options['password'], $host);
118+
119+
$portString = '';
120+
if (!empty($options['port'])) {
121+
$portString = ':' . $options['port'];
118122
}
119123

124+
$host = $protocol . '://' . $authString . $hostname . $portString;
125+
120126
$options['hosts'] = [$host];
127+
121128
return $options;
122129
}
123130

0 commit comments

Comments
 (0)