Skip to content

Commit 7d3da26

Browse files
authored
Merge pull request #1147 from paramonov/master
[sns] added possibility to define already existing topics (prevent create topic call) #1022
2 parents b57d068 + ef7b5c7 commit 7d3da26

5 files changed

+33
-5
lines changed

Diff for: pkg/sns/SnsConnectionFactory.php

+5-2
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ class SnsConnectionFactory implements ConnectionFactory
2424

2525
/**
2626
* $config = [
27-
* 'key' => null AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment.
27+
* 'key' => null, AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment.
2828
* 'secret' => null, AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment.
2929
* 'token' => null, AWS credentials. If no credentials are provided, the SDK will attempt to load them from the environment.
3030
* '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.
3131
* 'version' => '2012-11-05', (string, required) The version of the webservice to utilize
3232
* 'lazy' => true, Enable lazy connection (boolean)
33-
* 'endpoint' => null (string, default=null) The full URI of the webservice. This is only required when connecting to a custom endpoint e.g. localstack
33+
* '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+
* 'topic_arns' => [], (array<string,string>) The list of existing topic arns: key - topic name; value - arn
3435
* ].
3536
*
3637
* or
@@ -132,6 +133,7 @@ private function parseDsn(string $dsn): array
132133
'version' => $dsn->getString('version'),
133134
'lazy' => $dsn->getBool('lazy'),
134135
'endpoint' => $dsn->getString('endpoint'),
136+
'topic_arns' => $dsn->getArray('topic_arns', [])->toArray(),
135137
]), function ($value) { return null !== $value; });
136138
}
137139

@@ -145,6 +147,7 @@ private function defaultConfig(): array
145147
'version' => '2010-03-31',
146148
'lazy' => true,
147149
'endpoint' => null,
150+
'topic_arns' => [],
148151
];
149152
}
150153
}

Diff for: pkg/sns/SnsContext.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ public function __construct(SnsClient $client, array $config)
3535
{
3636
$this->client = $client;
3737
$this->config = $config;
38-
39-
$this->topicArns = [];
38+
$this->topicArns = $config['topic_arns'];
4039
}
4140

4241
/**

Diff for: pkg/sns/Tests/SnsConnectionFactoryConfigTest.php

+24
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public static function provideConfigs()
6464
'version' => '2010-03-31',
6565
'lazy' => true,
6666
'endpoint' => null,
67+
'topic_arns' => [],
6768
],
6869
];
6970

@@ -77,6 +78,7 @@ public static function provideConfigs()
7778
'version' => '2010-03-31',
7879
'lazy' => true,
7980
'endpoint' => null,
81+
'topic_arns' => [],
8082
],
8183
];
8284

@@ -90,6 +92,7 @@ public static function provideConfigs()
9092
'version' => '2010-03-31',
9193
'lazy' => true,
9294
'endpoint' => null,
95+
'topic_arns' => [],
9396
],
9497
];
9598

@@ -103,6 +106,7 @@ public static function provideConfigs()
103106
'version' => '2010-03-31',
104107
'lazy' => false,
105108
'endpoint' => null,
109+
'topic_arns' => [],
106110
],
107111
];
108112

@@ -116,6 +120,7 @@ public static function provideConfigs()
116120
'version' => '2010-03-31',
117121
'lazy' => false,
118122
'endpoint' => null,
123+
'topic_arns' => [],
119124
],
120125
];
121126

@@ -129,6 +134,7 @@ public static function provideConfigs()
129134
'version' => '2010-03-31',
130135
'lazy' => false,
131136
'endpoint' => null,
137+
'topic_arns' => [],
132138
],
133139
];
134140

@@ -148,6 +154,24 @@ public static function provideConfigs()
148154
'version' => '2010-03-31',
149155
'lazy' => false,
150156
'endpoint' => 'http://localstack:1111',
157+
'topic_arns' => [],
158+
],
159+
];
160+
161+
yield [
162+
['dsn' => 'sns:?topic_arns[topic1]=arn:aws:sns:us-east-1:123456789012:topic1&topic_arns[topic2]=arn:aws:sns:us-west-2:123456789012:topic2'],
163+
[
164+
'key' => null,
165+
'secret' => null,
166+
'token' => null,
167+
'region' => null,
168+
'version' => '2010-03-31',
169+
'lazy' => true,
170+
'endpoint' => null,
171+
'topic_arns' => [
172+
'topic1' => 'arn:aws:sns:us-east-1:123456789012:topic1',
173+
'topic2' => 'arn:aws:sns:us-west-2:123456789012:topic2',
174+
],
151175
],
152176
];
153177
}

Diff for: pkg/sns/Tests/SnsConnectionFactoryTest.php

+2
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ public function testCouldBeConstructedWithEmptyConfiguration()
3333
'region' => null,
3434
'version' => '2010-03-31',
3535
'endpoint' => null,
36+
'topic_arns' => [],
3637
], 'config', $factory);
3738
}
3839

@@ -48,6 +49,7 @@ public function testCouldBeConstructedWithCustomConfiguration()
4849
'region' => null,
4950
'version' => '2010-03-31',
5051
'endpoint' => null,
52+
'topic_arns' => [],
5153
], 'config', $factory);
5254
}
5355

Diff for: pkg/sns/Tests/Spec/SnsContextTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,6 @@ protected function createContext()
2020
{
2121
$client = $this->createMock(SnsClient::class);
2222

23-
return new SnsContext($client, []);
23+
return new SnsContext($client, ['topic_arns' => []]);
2424
}
2525
}

0 commit comments

Comments
 (0)