Skip to content

Commit 586fbdb

Browse files
committed
[BWC] Add getUserPass() method to ConnectionInterface
1 parent 445fdea commit 586fbdb

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

src/Elasticsearch/Connections/Connection.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,17 @@ public function getHost()
493493
return $this->host;
494494
}
495495

496+
/**
497+
* @return null|string
498+
*/
499+
public function getUserPass()
500+
{
501+
if (isset($this->connectionParams['client']['curl'][CURLOPT_USERPWD]) === true) {
502+
return $this->connectionParams['client']['curl'][CURLOPT_USERPWD];
503+
}
504+
return null;
505+
}
506+
496507
/**
497508
* @param $request
498509
* @param $response

src/Elasticsearch/Connections/ConnectionInterface.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,13 @@ public function getTransportSchema();
4444
*/
4545
public function getHost();
4646

47+
/**
48+
* Get the username:password string for this connection, null if not set
49+
*
50+
* @return null|string
51+
*/
52+
public function getUserPass();
53+
4754
/**
4855
* Check to see if this instance is marked as 'alive'
4956
*

tests/Elasticsearch/Tests/ClientTest.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -300,15 +300,13 @@ public function testInlineHosts()
300300
$this->assertEquals("https", $host->getTransportSchema());
301301

302302

303-
// Note: we can't test user/pass themselves yet, need to introduce
304-
// breaking change to interface in master to do that
305-
// But we can confirm it doesn't break anything
306303
$client = Elasticsearch\ClientBuilder::create()->setHosts([
307304
'https://user:pass@foo.com:9200'
308305
])->build();
309306
$host = $client->transport->getConnection();
310307
$this->assertEquals("foo.com:9200", $host->getHost());
311308
$this->assertEquals("https", $host->getTransportSchema());
309+
$this->assertEquals("user:pass", $host->getUserPass());
312310
}
313311

314312
public function testExtendedHosts()
@@ -410,12 +408,12 @@ public function testExtendedHosts()
410408
[
411409
'host' => 'foo.com',
412410
'user' => 'user',
413-
'pass' => 'abc#$%!abc'
411+
'pass' => 'abc#$@?%!abc'
414412
]
415413
])->build();
416414
$host = $client->transport->getConnection();
417415
$this->assertEquals("foo.com:9200", $host->getHost());
418416
$this->assertEquals("http", $host->getTransportSchema());
419-
417+
$this->assertEquals("user:abc#$@?%!abc", $host->getUserPass());
420418
}
421419
}

0 commit comments

Comments
 (0)