Skip to content

Commit

Permalink
Extract HTTP BasicAuth from host details if present
Browse files Browse the repository at this point in the history
  • Loading branch information
polyfractal committed Jan 13, 2015
1 parent 49377f8 commit 0b80bcf
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
14 changes: 8 additions & 6 deletions docs/configuration.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@ The client accepts an array of hosts that you would like to connect to. Each va
----
$params = array();
$params['hosts'] = array (
'192.168.1.1:9200', // IP + Port
'192.168.1.2', // Just IP
'mydomain.server.com:9201', // Domain + Port
'mydomain2.server.com', // Just Domain
'https://localhost', // SSL to localhost
'https://192.168.1.3:9200' // SSL to IP + Port
'192.168.1.1:9200', // IP + Port
'192.168.1.2', // Just IP
'mydomain.server.com:9201', // Domain + Port
'mydomain2.server.com', // Just Domain
'https://localhost', // SSL to localhost
'https://192.168.1.3:9200', // SSL to IP + Port
'http://user:pass@localhost:9200', // HTTP Basic Auth
'https://user:pass@localhost:9200', // SSL + HTTP Basic Auth
);
$client = new Elasticsearch\Client($params);
Expand Down
12 changes: 12 additions & 0 deletions src/Elasticsearch/Connections/AbstractConnection.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,18 @@ public function __construct($hostDetails, $connectionParams, LoggerInterface $lo
$this->transportSchema = $hostDetails['scheme'];
}

if (isset($hostDetails['user']) && isset($hostDetails['pass'])) {
if (isset($connectionParams['auth'][0]) !== true) {
$connectionParams['auth'][0] = $hostDetails['user'];
}
if (isset($connectionParams['auth'][1]) !== true) {
$connectionParams['auth'][1] = $hostDetails['pass'];
}
if (isset($connectionParams['auth'][2]) !== true) {
$connectionParams['auth'][2] = 'Basic';
}
}

$host = $this->transportSchema.'://'.$hostDetails['host'].':'.$hostDetails['port'];
if (isset($hostDetails['path']) === true) {
$host .= $hostDetails['path'];
Expand Down

0 comments on commit 0b80bcf

Please sign in to comment.