Skip to content

Commit 82bcc80

Browse files
committed
Extract HTTP BasicAuth from host details if present
1 parent 9f0f9c9 commit 82bcc80

File tree

2 files changed

+20
-6
lines changed

2 files changed

+20
-6
lines changed

docs/configuration.asciidoc

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ The client accepts an array of hosts that you would like to connect to. Each va
1717
----
1818
$params = array();
1919
$params['hosts'] = array (
20-
'192.168.1.1:9200', // IP + Port
21-
'192.168.1.2', // Just IP
22-
'mydomain.server.com:9201', // Domain + Port
23-
'mydomain2.server.com', // Just Domain
24-
'https://localhost', // SSL to localhost
25-
'https://192.168.1.3:9200' // SSL to IP + Port
20+
'192.168.1.1:9200', // IP + Port
21+
'192.168.1.2', // Just IP
22+
'mydomain.server.com:9201', // Domain + Port
23+
'mydomain2.server.com', // Just Domain
24+
'https://localhost', // SSL to localhost
25+
'https://192.168.1.3:9200', // SSL to IP + Port
26+
'http://user:pass@localhost:9200', // HTTP Basic Auth
27+
'https://user:pass@localhost:9200', // SSL + HTTP Basic Auth
2628
);
2729
2830
$client = new Elasticsearch\Client($params);

src/Elasticsearch/Connections/AbstractConnection.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,18 @@ public function __construct($hostDetails, $connectionParams, LoggerInterface $lo
9393
$this->transportSchema = $hostDetails['scheme'];
9494
}
9595

96+
if (isset($hostDetails['user']) && isset($hostDetails['pass'])) {
97+
if (isset($connectionParams['auth'][0]) !== true) {
98+
$connectionParams['auth'][0] = $hostDetails['user'];
99+
}
100+
if (isset($connectionParams['auth'][1]) !== true) {
101+
$connectionParams['auth'][1] = $hostDetails['pass'];
102+
}
103+
if (isset($connectionParams['auth'][2]) !== true) {
104+
$connectionParams['auth'][2] = 'Basic';
105+
}
106+
}
107+
96108
$host = $this->transportSchema.'://'.$hostDetails['host'].':'.$hostDetails['port'];
97109
if (isset($hostDetails['path']) === true) {
98110
$host .= $hostDetails['path'];

0 commit comments

Comments
 (0)