Skip to content

Commit dcdf364

Browse files
committed
#22297 Fix elasticsearch issue over secure connection
Apply changes for ES5 client
1 parent b5bc848 commit dcdf364

File tree

1 file changed

+12
-5
lines changed

1 file changed

+12
-5
lines changed

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -108,21 +108,28 @@ public function testConnection()
108108
*/
109109
private function buildConfig($options = [])
110110
{
111-
$host = preg_replace('/http[s]?:\/\//i', '', $options['hostname']);
111+
$hostname = preg_replace('/http[s]?:\/\//i', '', $options['hostname']);
112112
// @codingStandardsIgnoreStart
113113
$protocol = parse_url($options['hostname'], PHP_URL_SCHEME);
114114
// @codingStandardsIgnoreEnd
115115
if (!$protocol) {
116116
$protocol = 'http';
117117
}
118-
if (!empty($options['port'])) {
119-
$host .= ':' . $options['port'];
118+
119+
$authString = '';
120+
if (!empty($options['enableAuth']) && (int)$options['enableAuth'] === 1) {
121+
$authString = "{$options['username']}:{$options['password']}@";
120122
}
121-
if (!empty($options['enableAuth']) && ($options['enableAuth'] == 1)) {
122-
$host = sprintf('%s://%s:%s@%s', $protocol, $options['username'], $options['password'], $host);
123+
124+
$portString = '';
125+
if (!empty($options['port'])) {
126+
$portString = ':' . $options['port'];
123127
}
124128

129+
$host = $protocol . '://' . $authString . $hostname . $portString;
130+
125131
$options['hosts'] = [$host];
132+
126133
return $options;
127134
}
128135

0 commit comments

Comments
 (0)