Skip to content

Commit

Permalink
SQS Transport - Add support for AWS profiles.
Browse files Browse the repository at this point in the history
  • Loading branch information
Baptiste Gaillard committed Jan 8, 2020
1 parent 8f86cf9 commit 64a3b23
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/sqs/SqsConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
* ].
*
Expand Down Expand Up @@ -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'],
Expand Down Expand Up @@ -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; });
}
Expand All @@ -150,6 +156,7 @@ private function defaultConfig(): array
'version' => '2012-11-05',
'lazy' => true,
'endpoint' => null,
'profile' => null,
'queue_owner_aws_account_id' => null,
];
}
Expand Down
41 changes: 41 additions & 0 deletions pkg/sqs/Tests/SqsConnectionFactoryConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public static function provideConfigs()
'version' => '2012-11-05',
'lazy' => true,
'endpoint' => null,
'profile' => null,
'queue_owner_aws_account_id' => null,
],
];
Expand All @@ -78,6 +79,7 @@ public static function provideConfigs()
'version' => '2012-11-05',
'lazy' => true,
'endpoint' => null,
'profile' => null,
'queue_owner_aws_account_id' => null,
],
];
Expand All @@ -93,6 +95,7 @@ public static function provideConfigs()
'version' => '2012-11-05',
'lazy' => true,
'endpoint' => null,
'profile' => null,
'queue_owner_aws_account_id' => null,
],
];
Expand All @@ -108,6 +111,7 @@ public static function provideConfigs()
'version' => '2012-11-05',
'lazy' => false,
'endpoint' => null,
'profile' => null,
'queue_owner_aws_account_id' => null,
],
];
Expand All @@ -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,
],
];
Expand All @@ -138,6 +159,7 @@ public static function provideConfigs()
'version' => '2012-11-05',
'lazy' => false,
'endpoint' => null,
'profile' => null,
'queue_owner_aws_account_id' => null,
],
];
Expand All @@ -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,
],
];
Expand Down
2 changes: 2 additions & 0 deletions pkg/sqs/Tests/SqsConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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);
}
Expand Down

0 comments on commit 64a3b23

Please sign in to comment.