Skip to content

Commit 3281853

Browse files
Stephen HoogendijkStephen Hoogendijk
authored andcommitted
Added auth support to legacy version
1 parent fd80291 commit 3281853

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/InfluxDB/Client.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,9 @@ public function __construct(
115115
$this->baseURI = sprintf('%s://%s:%d', $this->scheme, $this->host, $this->port);
116116
$this->httpClient = new \Guzzle\Http\Client($this->getBaseURI());
117117

118+
if ($this->username && $this->password) {
119+
$this->httpClient->setDefaultOption('auth', array($this->username, $this->password));
120+
}
118121
}
119122

120123
/**
@@ -310,4 +313,12 @@ protected function pointsToArray(array $points)
310313

311314
return $names;
312315
}
316+
317+
/**
318+
* @return \Guzzle\Http\Client
319+
*/
320+
public function getHttpClient()
321+
{
322+
return $this->httpClient;
323+
}
313324
}

tests/unit/ClientTest.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class ClientTest extends \PHPUnit_Framework_TestCase
1010

1111
/** @var Client $client */
1212
protected $client = null;
13-
13+
1414
public function testBaseURl()
1515
{
1616
$client = new Client('localhost', 8086);
@@ -32,6 +32,12 @@ public function testSelectDbShouldReturnDatabaseInstance()
3232
$this->assertEquals($dbName, $db->getName());
3333
}
3434

35+
public function testAuth()
36+
{
37+
$client = new Client('localhost', 8086, 'test', 'test');
38+
39+
$this->assertEquals(array('test', 'test'), $client->getHttpClient()->getDefaultOption('auth'));
40+
}
3541

3642
/**
3743
*/

0 commit comments

Comments
 (0)