Skip to content

Commit

Permalink
Add ServiceClient::createDefaultConnection() method
Browse files Browse the repository at this point in the history
  • Loading branch information
roxblnfk committed May 10, 2024
1 parent 6e710e3 commit 93920bd
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Client/GRPC/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,30 @@ public static function createSSL(
return new static(static fn(): WorkflowServiceClient => new WorkflowServiceClient($address, $options));
}

/**
* Create a new connection with settings from environment variables.
* It automatically detects if SSL connection is required.
*
* @psalm-suppress RiskyTruthyFalsyComparison
*/
public static function createDefaultConnection(): static
{
$address = \getenv('TEMPORAL_ADDRESS') ?: '127.0.0.1:7233';
$authKey = \getenv('TEMPORAL_AUTH_KEY') ?: '';
$sslPrivateKey = \getenv('TEMPORAL_SSL_PRIVATE_KEY') ?: null;
$sslCertChain = \getenv('TEMPORAL_SSL_CERTIFICATE_CHAIN') ?: null;

// Check SSL connection is required
$useSsl = $authKey !== '' || $sslPrivateKey !== null || $sslCertChain !== null;

if (!$useSsl) {
return static::create($address);
}

return static::createSSL($address, clientKey: $sslPrivateKey, clientPem: $sslCertChain)
->withAuthKey($authKey);
}

/**
* @param null|Pipeline<GrpcClientInterceptor, object> $pipeline
*
Expand Down

0 comments on commit 93920bd

Please sign in to comment.