Skip to content

Commit dd23603

Browse files
authored
Merge pull request #59 from ppavlovic/master
Added Curl options to ignore unsigned SSL, support for http basic auth on URL (g4/value-object >= 3.6.0)
2 parents 012580e + 7b14bda commit dd23603

File tree

4 files changed

+20
-8
lines changed

4 files changed

+20
-8
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
"ext-json" : "*",
4545
"g4/factory" : "1.*",
4646
"g4/profiler" : ">=1.11.0",
47-
"g4/value-object" : "*",
47+
"g4/value-object" : ">=3.6.0",
4848
"zf1/zend-db" : "1.12.*"
4949
},
5050
"scripts": {

src/Engine/Elasticsearch/ElasticsearchClient.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ private function submitCurlRequest()
254254
CURLOPT_URL => (string) $this->url,
255255
CURLOPT_HTTPHEADER => ['Content-Type: application/json'],
256256
CURLOPT_CUSTOMREQUEST => $this->method,
257+
CURLOPT_SSL_VERIFYPEER => false,
258+
CURLOPT_SSL_VERIFYHOST => false,
257259
]);
258260

259261
$response = curl_exec($handle);
@@ -308,7 +310,7 @@ private function throwCurlException($code, $message, $url, $body, $response)
308310
"Unexpected response code:%s from ES has been returned on submit. More info: %s. Url: %s. Body: %s. Response: %s",
309311
$code,
310312
json_encode($message),
311-
json_encode($url),
313+
(string) $url,
312314
json_encode($body),
313315
is_array($response) ? json_encode($response) : $response
314316
)

src/Engine/Elasticsearch/ElasticsearchClientFactory.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,26 @@ public function __construct(array $params)
3636
*/
3737
public function create()
3838
{
39+
$host = parse_url($this->params['host'], PHP_URL_HOST) ?: $this->params['host'];
40+
$protocol = parse_url($this->params['host'], PHP_URL_SCHEME) ?: self::PROTOCOL;
41+
$port = parse_url($this->params['host'], PHP_URL_PORT) ?: $this->params['port'];
42+
$username = parse_url($this->params['host'], PHP_URL_USER);
43+
$password = parse_url($this->params['host'], PHP_URL_PASS);
44+
3945
$url = new Url(
40-
self::PROTOCOL .
46+
$protocol .
4147
self::COLON .
4248
self::FORWARD_SLASH .
4349
self::FORWARD_SLASH .
44-
$this->params['host']
50+
$host
4551
);
4652

53+
if ($username && $password) {
54+
$url = $url->credentials($username, $password);
55+
}
56+
4757
return new ElasticsearchClient(
48-
$url->port(new PortNumber($this->params['port'])),
58+
$url->port(new PortNumber($port)),
4959
$this->params['index_type'],
5060
$this->params['timeout'],
5161
$this->params['version']

tests/unit/src/Engine/Elasticsearch/ElasticsearchClientTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,9 @@ public function testGetUrl()
4646
public function testCurlError()
4747
{
4848
$this->expectException(ClientException::class);
49-
$this->expectExceptionMessage('Unexpected response code:Curl error number - 6 from ES has been returned on submit. More info: "Could not resolve host: nothing". Url: {}. Body: null. Response: ');
50-
$elasticsearchClient = new ElasticsearchClient(new Url('http://nothing'), null, 5);
51-
$elasticsearchClient->execute();
49+
$this->expectExceptionMessage('Unexpected response code:Curl error number - 6 from ES has been returned on submit. More info: "Could not resolve host: nothing". Url: http://nothing//doc/. Body: null. Response: ');
50+
$elasticsearchClient = new ElasticsearchClient(new Url('http://nothing/'), null, 5);
51+
$elasticsearchClient->execute(); // todo - misleading because execute is only called internally
5252
}
5353

5454
protected function setUp()

0 commit comments

Comments
 (0)