-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Send ApiKey to RoadRunner with WorkerInfo (#539)
- Loading branch information
Showing
9 changed files
with
107 additions
and
40 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
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
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,47 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Worker; | ||
|
||
use Temporal\Internal\Traits\CloneWith; | ||
|
||
/** | ||
* DTO with credential configuration for connecting RoadRunner to the Temporal service. | ||
*/ | ||
final class ServiceCredentials | ||
{ | ||
use CloneWith; | ||
|
||
public readonly string $apiKey; | ||
|
||
private function __construct() | ||
{ | ||
$this->apiKey = ''; | ||
} | ||
|
||
public static function create(): self | ||
{ | ||
return new self(); | ||
} | ||
|
||
/** | ||
* Set the authentication token for API calls. | ||
* | ||
* To update the API key in runtime, call the `UpdateAPIKey` RPC method with the new key: | ||
* | ||
* $result = \Temporal\Worker\Transport\Goridge::create()->call( | ||
* 'temporal.UpdateAPIKey', | ||
* $newApiKey, | ||
* ); | ||
* | ||
* @link https://docs.temporal.io/cloud/api-keys | ||
* @since SDK 2.12.0 | ||
* @since RoadRunner 2024.3.0 | ||
*/ | ||
public function withApiKey(string $key): static | ||
{ | ||
/** @see self::$apiKey */ | ||
return $this->with('apiKey', $key); | ||
} | ||
} |
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
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Temporal\Tests\Unit\Worker; | ||
|
||
use PHPUnit\Framework\TestCase; | ||
use Temporal\Worker\ServiceCredentials; | ||
|
||
class ServiceCredentialsTestCase extends TestCase | ||
{ | ||
public function testWithApiKeyImmutability() | ||
{ | ||
$dto = ServiceCredentials::create(); | ||
|
||
$new = $dto->withApiKey('test'); | ||
|
||
$this->assertNotSame($dto, $new); | ||
$this->assertSame('test', $new->apiKey); | ||
$this->assertSame('', $dto->apiKey); | ||
} | ||
} |