generated from spiral-packages/package-skeleton
-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83: multiple Temporal Client configuration
- Loading branch information
Showing
15 changed files
with
713 additions
and
285 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# These are supported funding model platforms | ||
|
||
github: spiral |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,13 +17,19 @@ | |
"chat": "https://discord.gg/V6EK4he" | ||
}, | ||
"license": "MIT", | ||
"funding": [ | ||
{ | ||
"type": "github", | ||
"url": "https://github.com/sponsors/spiral" | ||
} | ||
], | ||
"authors": [ | ||
{ | ||
"name": "Anton Titov (wolfy-j)", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "Pavel Butchnev (butschster)", | ||
"name": "Pavel Buchnev (butschster)", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
|
@@ -38,15 +44,15 @@ | |
"require": { | ||
"php": "^8.1", | ||
"spiral/boot": "^3.13", | ||
"spiral/attributes": "^2.8 || ^3.0", | ||
"spiral/attributes": "^2.8 || ^3.1.5", | ||
"spiral/tokenizer": "^3.13", | ||
"spiral/scaffolder": "^3.13", | ||
"spiral/roadrunner-bridge": "^2.0 || ^3.5", | ||
"temporal/sdk": "^2.7" | ||
"spiral/roadrunner-bridge": "^2.0 || ^3.6", | ||
"temporal/sdk": "^2.10" | ||
}, | ||
"require-dev": { | ||
"spiral/framework": "^3.13", | ||
"spiral/testing": "^2.7", | ||
"spiral/testing": "^2.8", | ||
"vimeo/psalm": "^5.23" | ||
}, | ||
"autoload": { | ||
|
@@ -60,12 +66,6 @@ | |
"Spiral\\TemporalBridge\\Tests\\": "tests/src" | ||
} | ||
}, | ||
"funding": [ | ||
{ | ||
"type": "github", | ||
"url": "https://github.com/sponsors/roadrunner-server" | ||
} | ||
], | ||
"scripts": { | ||
"test": "vendor/bin/phpunit", | ||
"psalm": "vendor/bin/psalm --no-cache --config=psalm.xml ./src" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\TemporalBridge\Config; | ||
|
||
use Temporal\Client\ClientOptions; | ||
use Temporal\Client\GRPC\Context; | ||
use Temporal\Client\GRPC\ContextInterface; | ||
|
||
/** | ||
* Temporal Client configuration. | ||
* | ||
* ClientConfig::new( | ||
* ConnectionConfig::new('localhost:7233') | ||
* ->withTls( | ||
* privateKey: '/my-project.key', | ||
* certChain: '/my-project.pem', | ||
* ), | ||
* (new ClientOptions()) | ||
* ->withNamespace('default'), | ||
* Context::default() | ||
* ->withTimeout(4.5) | ||
* ->withRetryOptions( | ||
* RpcRetryOptions::new() | ||
* ->withMaximumAttempts(5) | ||
* ->withInitialInterval(3) | ||
* ->withMaximumInterval(10) | ||
* ->withBackoffCoefficient(1.6) | ||
* ), | ||
* ), | ||
* ), | ||
*/ | ||
final class ClientConfig | ||
{ | ||
private function __construct( | ||
public readonly ConnectionConfig $connection, | ||
public readonly ClientOptions $options, | ||
public readonly ContextInterface $context, | ||
) {} | ||
|
||
/** | ||
* Create a new client configuration. | ||
* | ||
* @param ConnectionConfig $connection | ||
* @param ClientOptions|null $options | ||
* @param ContextInterface|null $context Default Service Client context. | ||
*/ | ||
public static function new( | ||
ConnectionConfig $connection, | ||
?ClientOptions $options = null, | ||
?ContextInterface $context = null, | ||
): self { | ||
return new self( | ||
$connection, | ||
$options ?? new ClientOptions(), | ||
$context ?? Context::default(), | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Spiral\TemporalBridge\Config; | ||
|
||
/** | ||
* Temporal connection and credentials configuration. | ||
* | ||
* How to connect to local Temporal server: | ||
* | ||
* ConnectionConfig::new('localhost:7233'), | ||
* | ||
* How to connect to Temporal Cloud: | ||
* | ||
* ConnectionConfig::new('foo-bar-default.baz.tmprl.cloud:7233') | ||
* ->withTls( | ||
* privateKey: '/my-project.key', | ||
* certChain: '/my-project.pem', | ||
* ), | ||
*/ | ||
final class ConnectionConfig | ||
{ | ||
/** | ||
* @param non-empty-string $address | ||
* @param non-empty-string|\Stringable|null $authToken | ||
*/ | ||
private function __construct( | ||
public readonly string $address, | ||
public readonly ?TlsConfig $tlsConfig = null, | ||
public readonly string|\Stringable|null $authToken = null, | ||
) {} | ||
|
||
/** | ||
* Check if the connection is secure. | ||
* | ||
* @psalm-assert-if-true TlsConfig $this->tlsConfig | ||
* @psalm-assert-if-false null $this->tlsConfig | ||
*/ | ||
public function isSecure(): bool | ||
{ | ||
return $this->tlsConfig !== null; | ||
} | ||
|
||
/** | ||
* @param non-empty-string $address | ||
*/ | ||
public static function new( | ||
string $address, | ||
): self { | ||
return new self($address); | ||
} | ||
|
||
/** | ||
* Set the TLS configuration for the connection. | ||
* | ||
* @param non-empty-string|null $rootCerts Root certificates string or file in PEM format. | ||
* If null provided, default gRPC root certificates are used. | ||
* @param non-empty-string|null $privateKey Client private key string or file in PEM format. | ||
* @param non-empty-string|null $certChain Client certificate chain string or file in PEM format. | ||
* @param non-empty-string|null $serverName Server name override for TLS verification. | ||
*/ | ||
public function withTls( | ||
?string $rootCerts = null, | ||
?string $privateKey = null, | ||
?string $certChain = null, | ||
?string $serverName = null, | ||
): self { | ||
return new self( | ||
$this->address, | ||
new TlsConfig($rootCerts, $privateKey, $certChain, $serverName), | ||
); | ||
} | ||
|
||
/** | ||
* Set the authentication token for the service client. | ||
* | ||
* This is the equivalent of providing an "Authorization" header with "Bearer " + the given key. | ||
* This will overwrite any "Authorization" header that may be on the context before each request to the | ||
* Temporal service. | ||
* You may pass your own {@see \Stringable} implementation to be able to change the key dynamically. | ||
* | ||
* @param non-empty-string|\Stringable|null $authToken | ||
*/ | ||
public function withAuthKey(string|\Stringable|null $authToken): self | ||
{ | ||
return new self( | ||
$this->address, | ||
$this->tlsConfig, | ||
$authToken, | ||
); | ||
} | ||
} |
Oops, something went wrong.