Skip to content

Commit

Permalink
feat: extend base client for ssl (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
seregazhuk authored Sep 8, 2022
1 parent d347de3 commit 6bc84c0
Showing 1 changed file with 22 additions and 7 deletions.
29 changes: 22 additions & 7 deletions src/Client/GRPC/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,21 +63,36 @@ public static function create(string $address): ServiceClientInterface
/**
* @param string $address
* @param string $crt Certificate or cert file in x509 format.
* @param string|null $clientKey
* @param string|null $clientPem
* @param string|null $overrideServerName
* @return ServiceClientInterface
*
* @psalm-suppress UndefinedClass
* @psalm-suppress UnusedVariable
*/
public static function createSSL(string $address, string $crt): ServiceClientInterface
public static function createSSL(
string $address,
string $crt,
string $clientKey = null,
string $clientPem = null,
string $overrideServerName = null
): ServiceClientInterface
{
if (\is_file($crt)) {
$crt = \file_get_contents($crt);
$options = [
'credentials' => \Grpc\ChannelCredentials::createSsl(
\is_file($crt) ? \file_get_contents($crt) : null,
\is_file($clientKey) ? \file_get_contents($clientKey) : null,
\is_file($clientPem) ? \file_get_contents($clientPem) : null
)
];

if ($overrideServerName !== null) {
$options['grpc.default_authority'] = $overrideServerName;
$options['grpc.ssl_target_name_override'] = $overrideServerName;
}

$client = new WorkflowServiceClient(
$address,
['credentials' => \Grpc\ChannelCredentials::createSsl($crt)]
);
$client = new WorkflowServiceClient($address, $options);

return new static($client);
}
Expand Down

0 comments on commit 6bc84c0

Please sign in to comment.