Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sns] added possibility to define already existing topics (prevent create topic call) #1022 #1147

Merged
merged 7 commits into from
Mar 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions pkg/sns/SnsConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,14 @@ class SnsConnectionFactory implements ConnectionFactory

/**
* $config = [
* 'key' => null AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment.
* 'key' => null, AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment.
* 'secret' => null, AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment.
* 'token' => null, AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment.
* 'region' => null, (string, required) Region to connect to. See http://docs.aws.amazon.com/general/latest/gr/rande.html for a list of available regions.
* '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
* 'topic_arns' => [], (array<string,string>) The list of existing topic arns: key - topic name; value - arn
* ].
*
* or
Expand Down Expand Up @@ -132,6 +133,7 @@ private function parseDsn(string $dsn): array
'version' => $dsn->getString('version'),
'lazy' => $dsn->getBool('lazy'),
'endpoint' => $dsn->getString('endpoint'),
'topic_arns' => $dsn->getArray('topic_arns', [])->toArray(),
]), function ($value) { return null !== $value; });
}

Expand All @@ -145,6 +147,7 @@ private function defaultConfig(): array
'version' => '2010-03-31',
'lazy' => true,
'endpoint' => null,
'topic_arns' => [],
];
}
}
3 changes: 1 addition & 2 deletions pkg/sns/SnsContext.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ public function __construct(SnsClient $client, array $config)
{
$this->client = $client;
$this->config = $config;

$this->topicArns = [];
$this->topicArns = $config['topic_arns'];
makasim marked this conversation as resolved.
Show resolved Hide resolved
}

/**
Expand Down
24 changes: 24 additions & 0 deletions pkg/sns/Tests/SnsConnectionFactoryConfigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ public static function provideConfigs()
'version' => '2010-03-31',
'lazy' => true,
'endpoint' => null,
'topic_arns' => [],
],
];

Expand All @@ -77,6 +78,7 @@ public static function provideConfigs()
'version' => '2010-03-31',
'lazy' => true,
'endpoint' => null,
'topic_arns' => [],
],
];

Expand All @@ -90,6 +92,7 @@ public static function provideConfigs()
'version' => '2010-03-31',
'lazy' => true,
'endpoint' => null,
'topic_arns' => [],
],
];

Expand All @@ -103,6 +106,7 @@ public static function provideConfigs()
'version' => '2010-03-31',
'lazy' => false,
'endpoint' => null,
'topic_arns' => [],
],
];

Expand All @@ -116,6 +120,7 @@ public static function provideConfigs()
'version' => '2010-03-31',
'lazy' => false,
'endpoint' => null,
'topic_arns' => [],
],
];

Expand All @@ -129,6 +134,7 @@ public static function provideConfigs()
'version' => '2010-03-31',
'lazy' => false,
'endpoint' => null,
'topic_arns' => [],
],
];

Expand All @@ -148,6 +154,24 @@ public static function provideConfigs()
'version' => '2010-03-31',
'lazy' => false,
'endpoint' => 'http://localstack:1111',
'topic_arns' => [],
],
];

yield [
['dsn' => 'sns:?topic_arns[topic1]=arn:aws:sns:us-east-1:123456789012:topic1&topic_arns[topic2]=arn:aws:sns:us-west-2:123456789012:topic2'],
[
'key' => null,
'secret' => null,
'token' => null,
'region' => null,
'version' => '2010-03-31',
'lazy' => true,
'endpoint' => null,
'topic_arns' => [
'topic1' => 'arn:aws:sns:us-east-1:123456789012:topic1',
'topic2' => 'arn:aws:sns:us-west-2:123456789012:topic2',
],
],
];
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/sns/Tests/SnsConnectionFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public function testCouldBeConstructedWithEmptyConfiguration()
'region' => null,
'version' => '2010-03-31',
'endpoint' => null,
'topic_arns' => [],
], 'config', $factory);
}

Expand All @@ -48,6 +49,7 @@ public function testCouldBeConstructedWithCustomConfiguration()
'region' => null,
'version' => '2010-03-31',
'endpoint' => null,
'topic_arns' => [],
], 'config', $factory);
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/sns/Tests/Spec/SnsContextTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ protected function createContext()
{
$client = $this->createMock(SnsClient::class);

return new SnsContext($client, []);
return new SnsContext($client, ['topic_arns' => []]);
}
}