Skip to content

Commit f4f9fa5

Browse files
committed
Added setCABundle in ClientBuilder
1 parent b9f9353 commit f4f9fa5

File tree

4 files changed

+39
-7
lines changed

4 files changed

+39
-7
lines changed

src/ClientBuilder.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ class ClientBuilder
106106
*/
107107
private bool $sslVerification = true;
108108

109+
/**
110+
* SSL CA bundle
111+
*/
112+
private string $sslCA;
113+
109114
/**
110115
* Elastic meta header
111116
*
@@ -261,7 +266,7 @@ public function setRetries(int $retries): ClientBuilder
261266
/**
262267
* Set SSL certificate
263268
*
264-
* @param string $cert The name of a file containing a PEM formatted certificate.
269+
* @param string $cert The name of a file containing a PEM formatted certificate
265270
* @param string $password if the certificate requires a password
266271
*/
267272
public function setSSLCert(string $cert, string $password = null): ClientBuilder
@@ -270,6 +275,17 @@ public function setSSLCert(string $cert, string $password = null): ClientBuilder
270275
return $this;
271276
}
272277

278+
/**
279+
* Set the Certificate Authority (CA) bundle
280+
*
281+
* @param string $cert The name of a file containing a PEM formatted certificate
282+
*/
283+
public function setCABundle(string $cert): ClientBuilder
284+
{
285+
$this->sslCA = $cert;
286+
return $this;
287+
}
288+
273289
/**
274290
* Set SSL key
275291
*
@@ -400,6 +416,9 @@ protected function getConfig(): array
400416
if (!$this->sslVerification) {
401417
$config[RequestOptions::SSL_VERIFY] = false;
402418
}
419+
if (!empty($this->sslCA)) {
420+
$config[RequestOptions::SSL_CA] = $this->sslCA;
421+
}
403422
return $config;
404423
}
405424

src/Transport/Adapter/Guzzle.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ public function setConfig(ClientInterface $client, array $config, array $clientO
3636
case Options::SSL_VERIFY:
3737
$guzzleConfig[RequestOptions::VERIFY] = $value;
3838
break;
39+
case Options::SSL_CA:
40+
$guzzleConfig[RequestOptions::VERIFY] = $value;
3941
}
4042
}
4143
$class = get_class($client);
42-
return new $class($clientOptions + $guzzleConfig);
44+
return new $class(array_merge($clientOptions, $guzzleConfig));
4345
}
4446
}

src/Transport/RequestOptions.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,9 @@ final class RequestOptions
3030
* SSL key
3131
*/
3232
public const SSL_KEY = 'ssl_key';
33+
34+
/**
35+
* SSL Certificate Authority (CA) bundle
36+
*/
37+
public const SSL_CA = 'ssl_ca';
3338
}

tests/ClientBuilderTest.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,36 +275,42 @@ public function testSetRetriesSetTheTransport()
275275
$this->assertEquals(10, $client->getTransport()->getRetries());
276276
}
277277

278-
public function testSetSSLCert()
278+
public function testSetSslCert()
279279
{
280280
$result = $this->builder->setSSLCert('/tmp/cert.pem');
281281
$this->assertEquals($this->builder, $result);
282282
}
283283

284-
public function testSetSSLCertWithPassword()
284+
public function testSetSslCertWithPassword()
285285
{
286286
$result = $this->builder->setSSLCert('/tmp/cert.pem', 'xxx');
287287
$this->assertEquals($this->builder, $result);
288288
}
289289

290-
public function testSetSSLKey()
290+
public function testSetSslKey()
291291
{
292292
$result = $this->builder->setSSLKey('xxx');
293293
$this->assertEquals($this->builder, $result);
294294
}
295295

296-
public function testSetSSLKeyWithPassword()
296+
public function testSetSslKeyWithPassword()
297297
{
298298
$result = $this->builder->setSSLKey('xxx', 'yyy');
299299
$this->assertEquals($this->builder, $result);
300300
}
301301

302-
public function testSetSSLVerification()
302+
public function testSetSslVerification()
303303
{
304304
$result = $this->builder->setSSLVerification(false);
305305
$this->assertEquals($this->builder, $result);
306306
}
307307

308+
public function testSetCaBundle()
309+
{
310+
$result = $this->builder->setCABundle('/tmp/ca.pem');
311+
$this->assertEquals($this->builder, $result);
312+
}
313+
308314
public function testSetElasticMetaHeader()
309315
{
310316
$result = $this->builder->setElasticMetaHeader(false);

0 commit comments

Comments
 (0)