Skip to content

Commit 7f361b3

Browse files
committed
ssl connection fix for systems where ca bundle is incomplete #3
1 parent 65a9e02 commit 7f361b3

File tree

6 files changed

+3950
-7
lines changed

6 files changed

+3950
-7
lines changed

src/Understand/UnderstandLaravel/Handlers/BaseHandler.php

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ abstract class BaseHandler
2828
*/
2929
protected $silent = true;
3030

31+
/**
32+
* SSL CA bundle path
33+
*
34+
* @var string
35+
*/
36+
protected $sslBundlePath;
37+
3138
/**
3239
* Send data to storage
3340
*
@@ -37,15 +44,17 @@ abstract class BaseHandler
3744
abstract protected function send($data);
3845

3946
/**
40-
* @param string $inputKey
47+
* @param string $inputToken
4148
* @param string $apiUrl
42-
* @param bool $silent
49+
* @param boolean $silent
50+
* @param string $sslBundlePath
4351
*/
44-
public function __construct($inputToken, $apiUrl, $silent = true)
52+
public function __construct($inputToken, $apiUrl, $silent = true, $sslBundlePath = null)
4553
{
4654
$this->setInputKey($inputToken);
4755
$this->setApiUrl($apiUrl);
4856

57+
$this->sslBundlePath = $sslBundlePath;
4958
$this->silent = $silent;
5059
}
5160

src/Understand/UnderstandLaravel/Handlers/LaravelQueueListener.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ public function listen($job, $data)
1717
$inputToken = \Config::get('understand-laravel::config.token');
1818
$apiUrl = \Config::get('understand-laravel::config.url', 'https://api.understand.io');
1919
$silent = \Config::get('understand-laravel::config.silent');
20+
$sslBundlePath = \Config::get('understand-laravel::config.ssl_ca_bundle');
2021

21-
$syncHandler = new SyncHandler($inputToken, $apiUrl, $silent);
22+
$syncHandler = new SyncHandler($inputToken, $apiUrl, $silent, $sslBundlePath);
2223
$syncHandler->handle($requestData);
2324

2425
$job->delete();

src/Understand/UnderstandLaravel/Handlers/SyncHandler.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,13 @@ protected function send($requestData)
2323
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 5);
2424
curl_setopt($ch, CURLOPT_TIMEOUT, 5);
2525

26+
if ($this->sslBundlePath)
27+
{
28+
curl_setopt($ch, CURLOPT_TIMEOUT, $this->sslBundlePath);
29+
}
30+
31+
curl_setopt($ch, CURLOPT_USERAGENT, 'Laravel service provider.');
32+
2633
$response = curl_exec($ch);
2734
curl_close($ch);
2835

src/Understand/UnderstandLaravel/UnderstandLaravelServiceProvider.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,15 +142,16 @@ protected function resolveHandler($app)
142142
$apiUrl = $app['config']->get('understand-laravel::config.url', 'https://api.understand.io');
143143
$silent = $app['config']->get('understand-laravel::config.silent');
144144
$handlerType = $app['config']->get('understand-laravel::config.handler');
145+
$sslBundlePath = $app['config']->get('understand-laravel::config.ssl_ca_bundle');
145146

146147
if ($handlerType == 'sync')
147148
{
148-
return new Handlers\SyncHandler($inputToken, $apiUrl, $silent);
149+
return new Handlers\SyncHandler($inputToken, $apiUrl, $silent, $sslBundlePath);
149150
}
150151

151152
if ($handlerType == 'queue')
152153
{
153-
return new Handlers\LaravelQueueHandler($inputToken, $apiUrl, $silent);
154+
return new Handlers\LaravelQueueHandler($inputToken, $apiUrl, $silent, $sslBundlePath);
154155
}
155156

156157
throw new \ErrorException('understand-laravel handler misconfiguration:' . $handlerType);

0 commit comments

Comments
 (0)