diff --git a/pkg/sqs/SqsConnectionFactory.php b/pkg/sqs/SqsConnectionFactory.php index 1a8a967c7..54059ddae 100644 --- a/pkg/sqs/SqsConnectionFactory.php +++ b/pkg/sqs/SqsConnectionFactory.php @@ -31,7 +31,8 @@ class SqsConnectionFactory implements ConnectionFactory * 'retries' => 3, (int, default=int(3)) Configures the maximum number of allowed retries for a client (pass 0 to disable retries). * 'version' => '2012-11-05', (string, required) The version of the webservice to utilize * 'lazy' => true, Enable lazy connection (boolean) - * 'endpoint' => null (string, default=null) The full URI of the webservice. This is only required when connecting to a custom endpoint e.g. localstack + * 'endpoint' => null, (string, default=null) The full URI of the webservice. This is only required when connecting to a custom endpoint e.g. localstack + * '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. * 'queue_owner_aws_account_id' The AWS account ID of the account that created the queue. * ]. * @@ -92,6 +93,10 @@ private function establishConnection(): SqsClient $config['endpoint'] = $this->config['endpoint']; } + if (isset($this->config['profile'])) { + $config['profile'] = $this->config['profile']; + } + if ($this->config['key'] && $this->config['secret']) { $config['credentials'] = [ 'key' => $this->config['key'], @@ -135,6 +140,7 @@ private function parseDsn(string $dsn): array 'version' => $dsn->getString('version'), 'lazy' => $dsn->getBool('lazy'), 'endpoint' => $dsn->getString('endpoint'), + 'profile' => $dsn->getString('profile'), 'queue_owner_aws_account_id' => $dsn->getString('queue_owner_aws_account_id'), ]), function ($value) { return null !== $value; }); } @@ -150,6 +156,7 @@ private function defaultConfig(): array 'version' => '2012-11-05', 'lazy' => true, 'endpoint' => null, + 'profile' => null, 'queue_owner_aws_account_id' => null, ]; } diff --git a/pkg/sqs/Tests/SqsConnectionFactoryConfigTest.php b/pkg/sqs/Tests/SqsConnectionFactoryConfigTest.php index 375b0d03a..8225a4d34 100644 --- a/pkg/sqs/Tests/SqsConnectionFactoryConfigTest.php +++ b/pkg/sqs/Tests/SqsConnectionFactoryConfigTest.php @@ -63,6 +63,7 @@ public static function provideConfigs() 'version' => '2012-11-05', 'lazy' => true, 'endpoint' => null, + 'profile' => null, 'queue_owner_aws_account_id' => null, ], ]; @@ -78,6 +79,7 @@ public static function provideConfigs() 'version' => '2012-11-05', 'lazy' => true, 'endpoint' => null, + 'profile' => null, 'queue_owner_aws_account_id' => null, ], ]; @@ -93,6 +95,7 @@ public static function provideConfigs() 'version' => '2012-11-05', 'lazy' => true, 'endpoint' => null, + 'profile' => null, 'queue_owner_aws_account_id' => null, ], ]; @@ -108,6 +111,7 @@ public static function provideConfigs() 'version' => '2012-11-05', 'lazy' => false, 'endpoint' => null, + 'profile' => null, 'queue_owner_aws_account_id' => null, ], ]; @@ -123,6 +127,23 @@ public static function provideConfigs() 'version' => '2012-11-05', 'lazy' => false, 'endpoint' => null, + 'profile' => null, + 'queue_owner_aws_account_id' => null, + ], + ]; + + yield [ + ['dsn' => 'sqs:?profile=staging&lazy=0'], + [ + 'key' => null, + 'secret' => null, + 'token' => null, + 'region' => null, + 'retries' => 3, + 'version' => '2012-11-05', + 'lazy' => false, + 'endpoint' => null, + 'profile' => 'staging', 'queue_owner_aws_account_id' => null, ], ]; @@ -138,6 +159,7 @@ public static function provideConfigs() 'version' => '2012-11-05', 'lazy' => false, 'endpoint' => null, + 'profile' => null, 'queue_owner_aws_account_id' => null, ], ]; @@ -159,6 +181,25 @@ public static function provideConfigs() 'version' => '2012-11-05', 'lazy' => false, 'endpoint' => 'http://localstack:1111', + 'profile' => null, + 'queue_owner_aws_account_id' => null, + ], + ]; + + yield [ + [ + 'profile' => 'staging', + ], + [ + 'key' => null, + 'secret' => null, + 'token' => null, + 'region' => null, + 'retries' => 3, + 'version' => '2012-11-05', + 'lazy' => true, + 'endpoint' => null, + 'profile' => 'staging', 'queue_owner_aws_account_id' => null, ], ]; diff --git a/pkg/sqs/Tests/SqsConnectionFactoryTest.php b/pkg/sqs/Tests/SqsConnectionFactoryTest.php index 056ecc41b..189cfe7f8 100644 --- a/pkg/sqs/Tests/SqsConnectionFactoryTest.php +++ b/pkg/sqs/Tests/SqsConnectionFactoryTest.php @@ -32,6 +32,7 @@ public function testCouldBeConstructedWithEmptyConfiguration() 'retries' => 3, 'version' => '2012-11-05', 'endpoint' => null, + 'profile' => null, 'queue_owner_aws_account_id' => null, ], 'config', $factory); } @@ -49,6 +50,7 @@ public function testCouldBeConstructedWithCustomConfiguration() 'retries' => 3, 'version' => '2012-11-05', 'endpoint' => null, + 'profile' => null, 'queue_owner_aws_account_id' => null, ], 'config', $factory); }