-
Notifications
You must be signed in to change notification settings - Fork 6
[SWP-5969] - Allow missing credentials to make use of injected IAM role credentials #65
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
Changes from all commits
fc08ee9
9a4c092
716ce80
0dcc672
a54a6ea
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,7 +47,7 @@ protected function registerSnsBroadcaster() | |
| * @param array $config | ||
| * @return \Illuminate\Contracts\Broadcasting\Broadcaster | ||
| */ | ||
| protected function createSnsDriver(array $config): \Illuminate\Contracts\Broadcasting\Broadcaster | ||
| public function createSnsDriver(array $config): \Illuminate\Contracts\Broadcasting\Broadcaster | ||
| { | ||
| $config = self::prepareConfigurationCredentials($config); | ||
|
|
||
|
|
@@ -81,9 +81,7 @@ protected function registerEventBridgeBroadcaster() | |
| { | ||
| $this->app->resolving(BroadcastManager::class, function (BroadcastManager $manager) { | ||
| $manager->extend('eventbridge', function (Container $app, array $config) { | ||
| return $this->createEventBridgeDriver(array_merge($config, [ | ||
| 'version' => '2015-10-07', | ||
| ])); | ||
| return $this->createEventBridgeDriver($config); | ||
| }); | ||
| }); | ||
| } | ||
|
|
@@ -94,12 +92,12 @@ protected function registerEventBridgeBroadcaster() | |
| * @param array $config | ||
| * @return \Illuminate\Contracts\Broadcasting\Broadcaster | ||
| */ | ||
| protected function createEventBridgeDriver(array $config): \Illuminate\Contracts\Broadcasting\Broadcaster | ||
| public function createEventBridgeDriver(array $config): \Illuminate\Contracts\Broadcasting\Broadcaster | ||
oaklees marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| $config = self::prepareConfigurationCredentials($config); | ||
|
|
||
| return new EventBridgeBroadcaster( | ||
| new EventBridgeClient($config), | ||
| new EventBridgeClient(array_merge($config, ['version' => '2015-10-07'])), | ||
| $config['source'] ?? '' | ||
| ); | ||
| } | ||
|
|
@@ -112,10 +110,23 @@ protected function createEventBridgeDriver(array $config): \Illuminate\Contracts | |
| */ | ||
| public static function prepareConfigurationCredentials(array $config): array | ||
| { | ||
| if (Arr::has($config, ['key', 'secret'])) { | ||
| if (static::configHasCredentials($config)) { | ||
| $config['credentials'] = Arr::only($config, ['key', 'secret', 'token']); | ||
| } | ||
|
|
||
| return $config; | ||
| } | ||
|
|
||
| /** | ||
| * Make sure some AWS credentials were provided to the configuration array. | ||
| * | ||
| * @param array $config | ||
| * @return bool | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In this JavaDoc string, can you type the input argument as well?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's PHPDoc, which I guess is pretty much the same. We could indeed add Could we also bring in over the EventBridgeBroadcasterTest and SnsBroadcasterTest? |
||
| */ | ||
| private static function configHasCredentials(array $config): bool | ||
| { | ||
| return Arr::has($config, ['key', 'secret']) | ||
| && is_string(Arr::get($config, 'key')) | ||
| && is_string(Arr::get($config, 'secret')); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?php | ||
|
|
||
| namespace PodPoint\AwsPubSub\Tests\Pub\Broadcasting\Broadcasters; | ||
|
|
||
| use PodPoint\AwsPubSub\EventServiceProvider; | ||
| use PodPoint\AwsPubSub\Pub\Broadcasting\Broadcasters\EventBridgeBroadcaster; | ||
| use PodPoint\AwsPubSub\Tests\TestCase; | ||
|
|
||
| class EventBridgeBroadcasterTest extends TestCase | ||
| { | ||
| /** @test */ | ||
| public function it_can_instantiate_the_broadcaster() | ||
| { | ||
| $broadcaster = (new EventServiceProvider($this->app))->createEventBridgeDriver([ | ||
| 'driver' => 'eventbridge', | ||
| 'key' => 'dummy-key', | ||
| 'secret' => 'dummy-secret', | ||
| 'region' => 'eu-west-1', | ||
| 'event_bus' => 'default', | ||
| 'source' => 'my-app', | ||
| ]); | ||
|
|
||
| $this->assertInstanceOf(EventBridgeBroadcaster::class, $broadcaster); | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function it_supports_optional_aws_credentials() | ||
| { | ||
| $broadcaster = (new EventServiceProvider($this->app))->createEventBridgeDriver([ | ||
| 'driver' => 'eventbridge', | ||
| 'region' => 'eu-west-1', | ||
| 'event_bus' => 'default', | ||
| 'source' => 'my-app', | ||
| ]); | ||
|
|
||
| $this->assertInstanceOf(EventBridgeBroadcaster::class, $broadcaster); | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function it_supports_null_aws_credentials() | ||
| { | ||
| $broadcaster = (new EventServiceProvider($this->app))->createEventBridgeDriver([ | ||
| 'driver' => 'eventbridge', | ||
| 'key' => null, | ||
| 'secret' => null, | ||
| 'region' => 'eu-west-1', | ||
| 'event_bus' => 'default', | ||
| 'source' => 'my-app', | ||
| ]); | ||
|
|
||
| $this->assertInstanceOf(EventBridgeBroadcaster::class, $broadcaster); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?php | ||
|
|
||
| namespace PodPoint\AwsPubSub\Tests\Pub\Broadcasting\Broadcasters; | ||
|
|
||
| use PodPoint\AwsPubSub\EventServiceProvider; | ||
| use PodPoint\AwsPubSub\Pub\Broadcasting\Broadcasters\SnsBroadcaster; | ||
| use PodPoint\AwsPubSub\Tests\Pub\Concerns\InteractsWithSns; | ||
| use PodPoint\AwsPubSub\Tests\TestCase; | ||
|
|
||
| class SnsBroadcasterTest extends TestCase | ||
| { | ||
| use InteractsWithSns; | ||
|
|
||
| /** @test */ | ||
| public function it_can_instantiate_the_broadcaster() | ||
| { | ||
| $broadcaster = (new EventServiceProvider($this->app))->createSnsDriver([ | ||
| 'driver' => 'sns', | ||
| 'key' => 'dummy-key', | ||
| 'secret' => 'dummy-secret', | ||
| 'arn-prefix' => 'aws:arn:12345:', | ||
| 'region' => 'eu-west-1', | ||
| ]); | ||
|
|
||
| $this->assertInstanceOf(SnsBroadcaster::class, $broadcaster); | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function it_supports_optional_aws_credentials() | ||
| { | ||
| $broadcaster = (new EventServiceProvider($this->app))->createSnsDriver([ | ||
| 'driver' => 'sns', | ||
| 'arn-prefix' => 'aws:arn:12345:', | ||
| 'region' => 'eu-west-1', | ||
| ]); | ||
|
|
||
| $this->assertInstanceOf(SnsBroadcaster::class, $broadcaster); | ||
| } | ||
|
|
||
| /** @test */ | ||
| public function it_supports_null_aws_credentials() | ||
| { | ||
| $broadcaster = (new EventServiceProvider($this->app))->createSnsDriver([ | ||
| 'driver' => 'sns', | ||
| 'key' => null, | ||
| 'secret' => null, | ||
| 'arn-prefix' => 'aws:arn:12345:', | ||
| 'region' => 'eu-west-1', | ||
| ]); | ||
|
|
||
| $this->assertInstanceOf(SnsBroadcaster::class, $broadcaster); | ||
| } | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.