Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit d3bce0e

Browse files
filkarisfabpot
authored andcommitted
[Messenger] Add sessionToken option to SQS transport
1 parent 1317e39 commit d3bce0e

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/Symfony/Component/Messenger/Bridge/AmazonSqs/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
6.1
5+
---
6+
7+
* Added `session_token` option to support short-lived AWS credentials
8+
49
5.3
510
---
611

src/Symfony/Component/Messenger/Bridge/AmazonSqs/Tests/Transport/ConnectionTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,24 @@ public function testConfigureWithCredentials()
5656
);
5757
}
5858

59+
public function testConfigureWithTemporaryCredentials()
60+
{
61+
$awsKey = 'some_aws_access_key_value';
62+
$awsSecret = 'some_aws_secret_value';
63+
$sessionToken = 'some_aws_sessionToken';
64+
$region = 'eu-west-1';
65+
$httpClient = $this->createMock(HttpClientInterface::class);
66+
$this->assertEquals(
67+
new Connection(['queue_name' => 'queue'], new SqsClient(['region' => $region, 'accessKeyId' => $awsKey, 'accessKeySecret' => $awsSecret, 'sessionToken' => $sessionToken], null, $httpClient)),
68+
Connection::fromDsn('sqs://default/queue', [
69+
'access_key' => $awsKey,
70+
'secret_key' => $awsSecret,
71+
'session_token' => $sessionToken,
72+
'region' => $region,
73+
], $httpClient)
74+
);
75+
}
76+
5977
public function testFromInvalidDsn()
6078
{
6179
$this->expectException(\InvalidArgumentException::class);

src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ class Connection
4141
'auto_setup' => true,
4242
'access_key' => null,
4343
'secret_key' => null,
44+
'session_token' => null,
4445
'endpoint' => 'https://sqs.eu-west-1.amazonaws.com',
4546
'region' => 'eu-west-1',
4647
'queue_name' => 'messages',
@@ -89,6 +90,7 @@ public function __destruct()
8990
* * account: identifier of the AWS account
9091
* * access_key: AWS access key
9192
* * secret_key: AWS secret key
93+
* * session_token: AWS session token (required only when using temporary credentials)
9294
* * buffer_size: number of messages to prefetch (Default: 9)
9395
* * wait_time: long polling duration in seconds (Default: 20)
9496
* * poll_timeout: amount of seconds the transport should wait for new message
@@ -135,6 +137,9 @@ public static function fromDsn(string $dsn, array $options = [], HttpClientInter
135137
'accessKeyId' => urldecode($parsedUrl['user'] ?? '') ?: $options['access_key'] ?? self::DEFAULT_OPTIONS['access_key'],
136138
'accessKeySecret' => urldecode($parsedUrl['pass'] ?? '') ?: $options['secret_key'] ?? self::DEFAULT_OPTIONS['secret_key'],
137139
];
140+
if (null !== $options['session_token']) {
141+
$clientConfiguration['sessionToken'] = $options['session_token'];
142+
}
138143
if (isset($options['debug'])) {
139144
$clientConfiguration['debug'] = $options['debug'];
140145
}

0 commit comments

Comments
 (0)