Skip to content

Commit da0237f

Browse files
authored
Merge pull request #1008 from bgaillard/master
SQS Transport - Add support for AWS profiles.
2 parents 8f86cf9 + c9fe07c commit da0237f

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

Diff for: pkg/snsqs/Tests/SnsQsProducerTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ public function testCouldBeConstructedWithRequiredArguments()
3636
public function testShouldThrowIfMessageIsInvalidType()
3737
{
3838
$this->expectException(InvalidMessageException::class);
39-
$this->expectExceptionMessage('The message must be an instance of Enqueue\SnsQs\SnsQsMessage but it is Double\Message\P1');
39+
$this->expectExceptionMessage('The message must be an instance of Enqueue\SnsQs\SnsQsMessage but it is Double\Message\P4');
4040

4141
$producer = new SnsQsProducer($this->createSnsContextMock(), $this->createSqsContextMock());
4242

Diff for: pkg/sqs/SqsConnectionFactory.php

+9-5
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ class SqsConnectionFactory implements ConnectionFactory
3131
* 'retries' => 3, (int, default=int(3)) Configures the maximum number of allowed retries for a client (pass 0 to disable retries).
3232
* 'version' => '2012-11-05', (string, required) The version of the webservice to utilize
3333
* 'lazy' => true, Enable lazy connection (boolean)
34-
* 'endpoint' => null (string, default=null) The full URI of the webservice. This is only required when connecting to a custom endpoint e.g. localstack
34+
* 'endpoint' => null, (string, default=null) The full URI of the webservice. This is only required when connecting to a custom endpoint e.g. localstack
35+
* 'profile' => null, (string, default=null) The name of an AWS profile to used, if provided the SDK will attempt to read associated credentials from the ~/.aws/credentials file.
3536
* 'queue_owner_aws_account_id' The AWS account ID of the account that created the queue.
3637
* ].
3738
*
@@ -92,6 +93,10 @@ private function establishConnection(): SqsClient
9293
$config['endpoint'] = $this->config['endpoint'];
9394
}
9495

96+
if (isset($this->config['profile'])) {
97+
$config['profile'] = $this->config['profile'];
98+
}
99+
95100
if ($this->config['key'] && $this->config['secret']) {
96101
$config['credentials'] = [
97102
'key' => $this->config['key'],
@@ -120,10 +125,7 @@ private function parseDsn(string $dsn): array
120125
$dsn = Dsn::parseFirst($dsn);
121126

122127
if ('sqs' !== $dsn->getSchemeProtocol()) {
123-
throw new \LogicException(sprintf(
124-
'The given scheme protocol "%s" is not supported. It must be "sqs"',
125-
$dsn->getSchemeProtocol()
126-
));
128+
throw new \LogicException(sprintf('The given scheme protocol "%s" is not supported. It must be "sqs"', $dsn->getSchemeProtocol()));
127129
}
128130

129131
return array_filter(array_replace($dsn->getQuery(), [
@@ -135,6 +137,7 @@ private function parseDsn(string $dsn): array
135137
'version' => $dsn->getString('version'),
136138
'lazy' => $dsn->getBool('lazy'),
137139
'endpoint' => $dsn->getString('endpoint'),
140+
'profile' => $dsn->getString('profile'),
138141
'queue_owner_aws_account_id' => $dsn->getString('queue_owner_aws_account_id'),
139142
]), function ($value) { return null !== $value; });
140143
}
@@ -150,6 +153,7 @@ private function defaultConfig(): array
150153
'version' => '2012-11-05',
151154
'lazy' => true,
152155
'endpoint' => null,
156+
'profile' => null,
153157
'queue_owner_aws_account_id' => null,
154158
];
155159
}

Diff for: pkg/sqs/Tests/SqsConnectionFactoryConfigTest.php

+41
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public static function provideConfigs()
6363
'version' => '2012-11-05',
6464
'lazy' => true,
6565
'endpoint' => null,
66+
'profile' => null,
6667
'queue_owner_aws_account_id' => null,
6768
],
6869
];
@@ -78,6 +79,7 @@ public static function provideConfigs()
7879
'version' => '2012-11-05',
7980
'lazy' => true,
8081
'endpoint' => null,
82+
'profile' => null,
8183
'queue_owner_aws_account_id' => null,
8284
],
8385
];
@@ -93,6 +95,7 @@ public static function provideConfigs()
9395
'version' => '2012-11-05',
9496
'lazy' => true,
9597
'endpoint' => null,
98+
'profile' => null,
9699
'queue_owner_aws_account_id' => null,
97100
],
98101
];
@@ -108,6 +111,7 @@ public static function provideConfigs()
108111
'version' => '2012-11-05',
109112
'lazy' => false,
110113
'endpoint' => null,
114+
'profile' => null,
111115
'queue_owner_aws_account_id' => null,
112116
],
113117
];
@@ -123,6 +127,23 @@ public static function provideConfigs()
123127
'version' => '2012-11-05',
124128
'lazy' => false,
125129
'endpoint' => null,
130+
'profile' => null,
131+
'queue_owner_aws_account_id' => null,
132+
],
133+
];
134+
135+
yield [
136+
['dsn' => 'sqs:?profile=staging&lazy=0'],
137+
[
138+
'key' => null,
139+
'secret' => null,
140+
'token' => null,
141+
'region' => null,
142+
'retries' => 3,
143+
'version' => '2012-11-05',
144+
'lazy' => false,
145+
'endpoint' => null,
146+
'profile' => 'staging',
126147
'queue_owner_aws_account_id' => null,
127148
],
128149
];
@@ -138,6 +159,7 @@ public static function provideConfigs()
138159
'version' => '2012-11-05',
139160
'lazy' => false,
140161
'endpoint' => null,
162+
'profile' => null,
141163
'queue_owner_aws_account_id' => null,
142164
],
143165
];
@@ -159,6 +181,25 @@ public static function provideConfigs()
159181
'version' => '2012-11-05',
160182
'lazy' => false,
161183
'endpoint' => 'http://localstack:1111',
184+
'profile' => null,
185+
'queue_owner_aws_account_id' => null,
186+
],
187+
];
188+
189+
yield [
190+
[
191+
'profile' => 'staging',
192+
],
193+
[
194+
'key' => null,
195+
'secret' => null,
196+
'token' => null,
197+
'region' => null,
198+
'retries' => 3,
199+
'version' => '2012-11-05',
200+
'lazy' => true,
201+
'endpoint' => null,
202+
'profile' => 'staging',
162203
'queue_owner_aws_account_id' => null,
163204
],
164205
];

Diff for: pkg/sqs/Tests/SqsConnectionFactoryTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function testCouldBeConstructedWithEmptyConfiguration()
3232
'retries' => 3,
3333
'version' => '2012-11-05',
3434
'endpoint' => null,
35+
'profile' => null,
3536
'queue_owner_aws_account_id' => null,
3637
], 'config', $factory);
3738
}
@@ -49,6 +50,7 @@ public function testCouldBeConstructedWithCustomConfiguration()
4950
'retries' => 3,
5051
'version' => '2012-11-05',
5152
'endpoint' => null,
53+
'profile' => null,
5254
'queue_owner_aws_account_id' => null,
5355
], 'config', $factory);
5456
}

0 commit comments

Comments
 (0)